From bb959865e7e20bec2b53e8f8a56e293d0efb2d89 Mon Sep 17 00:00:00 2001 From: user Date: Mon, 4 Mar 2024 19:46:15 +0300 Subject: [PATCH] dev@locazia: api storage upload normally work at duplicate file --- app/api/routes/node_storage.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/api/routes/node_storage.py b/app/api/routes/node_storage.py index c38737d..d9c452d 100644 --- a/app/api/routes/node_storage.py +++ b/app/api/routes/node_storage.py @@ -35,6 +35,15 @@ async def s_api_v1_storage_post(request): try: file_hash = b58encode(hashlib.sha256(file_content).digest()).decode() + stored_content = db_session.query(StoredContent).filter(StoredContent.hash == file_hash).first() + if stored_content: + stored_cid = stored_content.cid.serialize_v1() + return { + "content_sha256": file_hash, + "content_id_v1": stored_cid, + "content_url": f"dmy://storage?cid={stored_cid}", + } + new_content = StoredContent( type="local/content_bin", user_id=request.ctx.user.id,