Skip to content

Commit

Permalink
feat: introduce chunk_size in PermissionMixin
Browse files Browse the repository at this point in the history
Signed-off-by: Guilhem Barthes <[email protected]>
  • Loading branch information
guilhem-barthes committed Aug 24, 2023
1 parent 16f3635 commit 090a3bb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions backend/api/views/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def image(self, request, *args, **kwargs):
status=status.HTTP_404_NOT_FOUND,
)

# TODO we love hard-coded size, see also api.views.utils.PermissionMixin._download_remote_file
response = CustomFileResponse(streaming_content=(chunk for chunk in function_image.file.chunks(512 * 1024)))
response = CustomFileResponse(
streaming_content=(chunk for chunk in function_image.file.chunks(self.chunk_size))
)
return response
3 changes: 2 additions & 1 deletion backend/api/views/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def set_headers(self, filelike):
class PermissionMixin(object):
authentication_classes = api_settings.DEFAULT_AUTHENTICATION_CLASSES + [BasicAuthentication]
permission_classes = [IsAuthorized]
chunk_size = 512 * 1024

def check_access(self, channel_name: str, user, asset, is_proxied_request: bool) -> None:
"""Returns true if API consumer is allowed to access data.
Expand Down Expand Up @@ -142,7 +143,7 @@ def _download_remote_file(self, channel_name: str, owner: str, url: str) -> djan
headers={HTTP_HEADER_PROXY_ASSET: "True"},
)
response = CustomFileResponse(
streaming_content=(chunk for chunk in proxy_response.iter_content(512 * 1024)),
streaming_content=(chunk for chunk in proxy_response.iter_content(self.chunk_size)),
status=proxy_response.status_code,
)

Expand Down

0 comments on commit 090a3bb

Please sign in to comment.