add converter v1

This commit is contained in:
user committed 2025-02-26 17:01:26 +03:00
1 parent 080f000fd2
commit 5c8d9aa864
9 files changed
+259 -14

No files matched your search

+5 -6
View File
@@ -52,17 +52,17 @@ async def s_api_v1_blockchain_send_new_content_message(request):
assert field_key in request.json, f"No {field_key} provided"
assert field_value(request.json[field_key]), f"Invalid {field_key} provided"
wallet_connection = request.ctx.user.wallet_connection(request.ctx.db_session)
assert wallet_connection, "No wallet connection found"
decrypted_content_cid, err = resolve_content(request.json['content'])
assert not err, f"Invalid content CID"
# Поиск исходного файла загруженного
decrypted_content = request.ctx.db_session.query(StoredContent).filter(
StoredContent.hash == decrypted_content_cid.content_hash_b58
).first()
assert decrypted_content, "No content locally found"
assert decrypted_content.type == "local/content_bin", "Invalid content type"
# Создание фиктивного encrypted_content. Не шифруем для производительности, тк зашифрованная нигде дальше не используется
encrypted_content = await create_encrypted_content(request.ctx.db_session, decrypted_content)
encrypted_content_cid = encrypted_content.cid
@@ -83,7 +83,7 @@ async def s_api_v1_blockchain_send_new_content_message(request):
metadata_content = await create_metadata_for_item(
request.ctx.db_session,
title=content_title,
cover_url=f"{PROJECT_HOST}/api/v1/storage/{image_content_cid.serialize_v2()}" if image_content_cid else None,
cover_url=f"{PROJECT_HOST}/api/v1.5/storage/{image_content_cid.serialize_v2()}" if image_content_cid else None,
authors=request.json['authors'],
hashtags=request.json['hashtags']
)
@@ -107,7 +107,6 @@ async def s_api_v1_blockchain_send_new_content_message(request):
'hint_type': 'uploadContentTxRequested'
}
)
return response.json({
'address': platform.address.to_string(1, 1, 1),
@@ -133,7 +132,7 @@ async def s_api_v1_blockchain_send_new_content_message(request):
begin_cell()
.store_ref(
begin_cell()
.store_bytes(f"{PROJECT_HOST}/api/v1/storage/{metadata_content.cid.serialize_v2(include_accept_type=True)}".encode())
.store_bytes(f"{PROJECT_HOST}/api/v1.5/storage/{metadata_content.cid.serialize_v2(include_accept_type=True)}".encode())
.end_cell()
)
.store_ref(
+8 -3
View File
@@ -133,7 +133,7 @@ async def s_api_v1_5_storage_post(request):
# If computed hash matches the provided one, the final chunk has been received
if computed_hash_b58 == provided_hash_b58:
final_path = os.path.join(UPLOADS_DIR, f"v1.5_{computed_hash_b58}")
final_path = os.path.join(UPLOADS_DIR, f"{computed_hash_b58}")
try:
os.rename(temp_path, final_path)
make_log("uploader_v1.5", f"Final chunk received. File renamed to: {final_path}", level="INFO")
@@ -192,11 +192,16 @@ async def s_api_v1_5_storage_post(request):
async def s_api_v1_5_storage_get(request, file_hash):
make_log("uploader_v1.5", f"Received file retrieval request for hash: {file_hash}", level="INFO")
final_path = os.path.join(UPLOADS_DIR, f"v1.5_{file_hash}")
try:
file_hash = resolve_content(file_hash)[0].content_hash
except:
pass
final_path = os.path.join(UPLOADS_DIR, f"{file_hash}")
if not os.path.exists(final_path):
make_log("uploader_v1.5", f"File not found: {final_path}", level="ERROR")
return response.json({"error": "File not found"}, status=404)
db_session = request.ctx.db_session
stored = db_session.query(StoredContent).filter_by(hash=file_hash).first()
if stored and stored.filename: