From 88583ddc4ef21650c945e7b3df2a0d06f2efbb13 Mon Sep 17 00:00:00 2001 From: user Date: Fri, 8 Mar 2024 02:34:48 +0300 Subject: [PATCH] dev@locazia: remove accept type whitelist --- app/api/__init__.py | 4 +++- app/api/routes/node_storage.py | 12 ++++++++++++ app/core/content/content_id.py | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/api/__init__.py b/app/api/__init__.py index 28921d3..bc3a0be 100644 --- a/app/api/__init__.py +++ b/app/api/__init__.py @@ -15,7 +15,8 @@ from app.api.routes._index import s_index, s_favicon from app.api.routes._system import s_api_v1_node, s_api_system_version, s_api_system_send_status from app.api.routes.auth import s_api_v1_auth_twa from app.api.routes.statics import s_api_tonconnect_manifest, s_api_platform_metadata -from app.api.routes.node_storage import s_api_v1_storage_post, s_api_v1_storage_get +from app.api.routes.node_storage import s_api_v1_storage_post, s_api_v1_storage_get, \ + s_api_v1_storage_decode_cid from app.api.routes.account import s_api_v1_account_get from app.api.routes._blockchain import s_api_v1_blockchain_send_new_content_message, \ s_api_v1_blockchain_send_purchase_content_message @@ -35,6 +36,7 @@ app.add_route(s_api_v1_auth_twa, "/api/v1/auth.twa", methods=["POST", "OPTIONS"] app.add_route(s_api_v1_storage_post, "/api/v1/storage", methods=["POST", "OPTIONS"]) app.add_route(s_api_v1_storage_get, "/api/v1/storage/", methods=["GET", "OPTIONS"]) +app.add_route(s_api_v1_storage_decode_cid, "/api/v1/storage.decodeContentId/", methods=["GET", "OPTIONS"]) app.add_route(s_api_v1_account_get, "/api/v1/account", methods=["GET", "OPTIONS"]) diff --git a/app/api/routes/node_storage.py b/app/api/routes/node_storage.py index 30cec84..ecc9dd1 100644 --- a/app/api/routes/node_storage.py +++ b/app/api/routes/node_storage.py @@ -98,3 +98,15 @@ async def s_api_v1_storage_get(request, file_hash=None): return response.json({"error": "File not found"}, status=404) return await response.file(file_path) + + +async def s_api_v1_storage_decode_cid(request, content_id=None): + cid, errmsg = resolve_content(content_id) + if errmsg: + return response.json({"error": errmsg}, status=400) + + return response.json({ + "content_hash": b58encode(cid.content_hash).decode(), + "onchain_index": cid.onchain_index, + "accept_type": cid.accept_type, + }) diff --git a/app/core/content/content_id.py b/app/core/content/content_id.py index b5160b4..b976b9f 100644 --- a/app/core/content/content_id.py +++ b/app/core/content/content_id.py @@ -55,7 +55,7 @@ class ContentId: ) assert cid_version == 1, "Invalid version" content_type = accept_type.split('/') - assert '/'.join(content_type[0:2]) in ALLOWED_CONTENT_TYPES, "Invalid accept type" + # assert '/'.join(content_type[0:2]) in ALLOWED_CONTENT_TYPES, "Invalid accept type" assert len(content_sha256) == 32, "Invalid hash length" return cls( content_hash=content_sha256,