Skip to content

Commit

Permalink
Fix: support byte ranges on filerespones
Browse files Browse the repository at this point in the history
  • Loading branch information
sverben committed Jan 22, 2024
1 parent e1a8a6a commit 211e19e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion api/app/db/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from Crypto.PublicKey import RSA
from Crypto.Signature import PKCS1_v1_5
from fastapi import UploadFile
from fastapi.responses import FileResponse
from app.fileresponse import FastApiBaizeFileResponse as FileResponse
from sqlalchemy.orm import Session

from app.conf import settings
Expand Down
19 changes: 19 additions & 0 deletions api/app/fileresponse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from baize.asgi.responses import FileResponse as BaizeFileResponse
from fastapi.responses import Response as FastApiResponse


class FastApiBaizeFileResponse(FastApiResponse):
_baize_response: BaizeFileResponse

def __init__(self, path, **kwargs) -> None:
filepath = str(kwargs.get("filepath", kwargs.get("path", path)))
kwargs.pop("filepath", None)
kwargs.pop("path", None)
self._baize_response = BaizeFileResponse(filepath, **kwargs)
super().__init__(None)

def __call__(self, *args, **kwargs):
return self._baize_response(*args, **kwargs)

def __getattr__(self, name):
return getattr(self._baize_response, name)

0 comments on commit 211e19e

Please sign in to comment.