From 6fc37cb5b36b56b1c08d6e6b27cee2aa9f76e356 Mon Sep 17 00:00:00 2001 From: 1yam Date: Fri, 25 Aug 2023 17:58:03 +0200 Subject: [PATCH] Fix: mypy error --- src/aleph/web/controllers/storage.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/aleph/web/controllers/storage.py b/src/aleph/web/controllers/storage.py index 2e6009998..ab83637cc 100644 --- a/src/aleph/web/controllers/storage.py +++ b/src/aleph/web/controllers/storage.py @@ -118,7 +118,9 @@ async def _verify_user_balance( async def _verify_user_file(message: PendingStoreMessage, size: int, file_io) -> None: file_io.seek(0) content = file_io.read(size) - item_content = json.loads(message.item_content) + item_content = {} + if message.item_content: + item_content = json.loads(message.item_content) actual_item_hash = sha256(content).hexdigest() client_item_hash = item_content["item_hash"] if len(content) > (1000 * MiB): @@ -194,7 +196,11 @@ async def storage_add_file(request: web.Request): metadata = post.get("metadata", b"") storage_metadata = None try: - storage_metadata = StorageMetadata.parse_raw(metadata) + if isinstance(metadata, FileField): + metadata_content = metadata.file.read() + storage_metadata = StorageMetadata.parse_raw(metadata_content) + else: + storage_metadata = StorageMetadata.parse_raw(metadata) except Exception as e: if metadata: raise web.HTTPUnprocessableEntity()