dev@locazia: remove accept type whitelist
This commit is contained in:
parent
a75dc3f31a
commit
88583ddc4e
|
|
@ -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._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.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.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.account import s_api_v1_account_get
|
||||||
from app.api.routes._blockchain import s_api_v1_blockchain_send_new_content_message, \
|
from app.api.routes._blockchain import s_api_v1_blockchain_send_new_content_message, \
|
||||||
s_api_v1_blockchain_send_purchase_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_post, "/api/v1/storage", methods=["POST", "OPTIONS"])
|
||||||
app.add_route(s_api_v1_storage_get, "/api/v1/storage/<file_hash>", methods=["GET", "OPTIONS"])
|
app.add_route(s_api_v1_storage_get, "/api/v1/storage/<file_hash>", methods=["GET", "OPTIONS"])
|
||||||
|
app.add_route(s_api_v1_storage_decode_cid, "/api/v1/storage.decodeContentId/<content_id>", methods=["GET", "OPTIONS"])
|
||||||
|
|
||||||
app.add_route(s_api_v1_account_get, "/api/v1/account", methods=["GET", "OPTIONS"])
|
app.add_route(s_api_v1_account_get, "/api/v1/account", methods=["GET", "OPTIONS"])
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 response.json({"error": "File not found"}, status=404)
|
||||||
|
|
||||||
return await response.file(file_path)
|
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,
|
||||||
|
})
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ class ContentId:
|
||||||
)
|
)
|
||||||
assert cid_version == 1, "Invalid version"
|
assert cid_version == 1, "Invalid version"
|
||||||
content_type = accept_type.split('/')
|
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"
|
assert len(content_sha256) == 32, "Invalid hash length"
|
||||||
return cls(
|
return cls(
|
||||||
content_hash=content_sha256,
|
content_hash=content_sha256,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue