dev@locazia: edit file delivery method to response.raw
This commit is contained in:
parent
a8b2cbf8a4
commit
480f54dbde
|
|
@ -7,6 +7,7 @@ import aiofiles
|
|||
import traceback
|
||||
from base58 import b58encode
|
||||
from sanic import response
|
||||
import json
|
||||
|
||||
from app.core._config import UPLOADS_DIR
|
||||
from app.core._utils.resolve_content import resolve_content
|
||||
|
|
@ -104,7 +105,18 @@ async def s_api_v1_storage_get(request, file_hash=None):
|
|||
make_log("Storage", f"File {content_sha256} not found locally", level="error")
|
||||
return response.json({"error": "File not found"}, status=404)
|
||||
|
||||
return await response.file(file_path)
|
||||
async with aiofiles.open(file_path, "rb") as file:
|
||||
content_file_bin = await file.read()
|
||||
|
||||
accept_type = cid.accept_type or request.headers.get("Accept")
|
||||
accept_type = accept_type or "application/octet-stream"
|
||||
if accept_type:
|
||||
if accept_type == "application/json":
|
||||
return response.json(
|
||||
json.loads(content_file_bin.decode())
|
||||
)
|
||||
|
||||
return response.raw(body=content_file_bin, content_type=accept_type)
|
||||
|
||||
|
||||
async def s_api_v1_storage_decode_cid(request, content_id=None):
|
||||
|
|
|
|||
Loading…
Reference in New Issue