Skip to content

Commit

Permalink
[SDL-5682][SDL-5608][Server] Fixed generation pre-signed URL and reso…
Browse files Browse the repository at this point in the history
…urce validation (#28)
  • Loading branch information
mkaliberda authored Sep 22, 2024
1 parent 1f2fce6 commit 36d2256
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/server/datamanager/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ def delete_path(self, path):
except:
pass

def create_url(self, *_args, **_kwargs):
raise NotImplementedError(
"Current datastore provider doesn't support direct cloud uploading"
)


class LocalDataStoreBuilder(object):
def __call__(self, bucket: str = "", folder: str = "", **_ignored):
Expand Down
31 changes: 22 additions & 9 deletions src/server/datamanager/serializers/capture_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from rest_framework.fields import CreateOnlyDefault
from django.conf import settings
from datamanager.datastore import get_datastore
from rest_framework.exceptions import ValidationError
from rest_framework.exceptions import NotAcceptable, ValidationError
from datamanager.fields import CurrentCaptureDefault
from datamanager.models import CaptureVideo
from rest_framework.reverse import reverse
Expand Down Expand Up @@ -129,15 +129,28 @@ def create(self, validated_data):
folder=f"{settings.CAPTURE_VIDEO_S3_ROOT}/{project_uuid}"
)

# TODO: DATASTORE fix this so its in the same call
if datastore.is_remote:
datastore.save(file_key_name, uploaded_file.file.name, delete=True)
if not uploaded_file:
try:
upload_url = datastore.create_url(
key=file_key_name,
content_type=f"video/{ext}",
content_length=capture_video.file_size,
)
capture_video.save()
capture_video.upload_url = upload_url
return capture_video
except NotImplementedError as error:
raise NotAcceptable(error)
else:
utils.ensure_path_exists(settings.SERVER_CAPTURE_VIDEO_ROOT)
folder = capture_video.get_folder(project_uuid)
if not os.path.isdir(folder):
os.mkdir(folder)
move(uploaded_file.file.name, os.path.join(folder, file_key_name))
# TODO: DATASTORE fix this so its in the same call
if datastore.is_remote:
datastore.save(file_key_name, uploaded_file.file.name, delete=True)
else:
utils.ensure_path_exists(settings.SERVER_CAPTURE_VIDEO_ROOT)
folder = capture_video.get_folder(project_uuid)
if not os.path.isdir(folder):
os.mkdir(folder)
move(uploaded_file.file.name, os.path.join(folder, file_key_name))

capture_video.save()
return capture_video
Expand Down

0 comments on commit 36d2256

Please sign in to comment.