Skip to content

Commit

Permalink
add artifacts download view
Browse files Browse the repository at this point in the history
  • Loading branch information
axellorreyne committed May 23, 2024
1 parent 6570721 commit 50180c8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
4 changes: 4 additions & 0 deletions backend/pigeonhole/apps/submissions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def submission_folder_path(group_id, submission_id):
return f"{str(settings.STATIC_ROOT)}/submissions/group_{group_id}/{submission_id}"


def artifacts_folder_path(group_id, submission_id):
return f"{str(settings.STATIC_ROOT)}/artifacts/group_{group_id}/{submission_id}"


def submission_folder_path_hostside(group_id, submission_id):
return f"{SUBMISSIONS_PATH}/group_{group_id}/{submission_id}"

Expand Down
27 changes: 26 additions & 1 deletion backend/pigeonhole/apps/submissions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from backend.pigeonhole.apps.projects.models import Project
from backend.pigeonhole.apps.submissions.models import (
Submissions,
SubmissionsSerializer,
SubmissionsSerializer, artifacts_folder_path,
)
from backend.pigeonhole.apps.submissions.permissions import CanAccessSubmission
from backend.pigeonhole.filters import CustomPageNumberPagination
Expand Down Expand Up @@ -164,6 +164,31 @@ def download(self, request, *args, **kwargs):

return response

@action(detail=True, methods=["get"])
def download_artifacts(self, request, *args, **kwargs):
submission = self.get_object()
if submission is None:
return Response(
{"message": f"Submission with id {id} not found", "errorcode":
"ERROR_SUBMISSION_NOT_FOUND"},
status=status.HTTP_404_NOT_FOUND
)

archivename = f"submission_{submission.submission_id}_artifacts"
downloadspath = 'backend/downloads/'
artifacts_path = artifacts_folder_path(submission.group_id.group_id, submission.submission_id)

shutil.make_archive(downloadspath + archivename, 'zip', artifacts_path)

path = realpath(downloadspath + archivename + '.zip')
response = FileResponse(
open(path, 'rb'),
content_type="application/force-download"
)
response['Content-Disposition'] = f'inline; filename={basename(path)}'

return response

@action(detail=False, methods=["get"])
def download_selection(self, request, *args, **kwargs):
ids = request.query_params.getlist("id", None)
Expand Down
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ services:
#- submissions:/usr/src/app/backend/uploads/submissions/
- /var/run/docker.sock:/var/run/docker.sock
- ${SUBMISSIONS_PATH}:/usr/src/app/backend/static/submissions/
- ${ARTIFACTS_PATH}:/usr/src/app/backend/static/artifacts/
ports:
- 8000:8000
env_file:
Expand Down

0 comments on commit 50180c8

Please sign in to comment.