Skip to content

Commit 1151319

Browse files
committed
Update response codes
1 parent f83bd45 commit 1151319

4 files changed

Lines changed: 24 additions & 25 deletions

File tree

server/mergin/sync/private_api.yaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,10 @@ paths:
424424
description: Prepare project zip archive to download
425425
operationId: prepare_archive
426426
responses:
427-
"200":
428-
description: Archive is already prepared
429-
"202":
430-
description: Accepted
427+
"201":
428+
description: Project archive creation started
429+
"204":
430+
$ref: "#/components/responses/NoContent"
431431
"400":
432432
$ref: "#/components/responses/BadStatusResp"
433433
"422":
@@ -456,7 +456,9 @@ components:
456456
UnsupportedMediaType:
457457
description: Payload format is in an unsupported format.
458458
ConflictResp:
459-
description: Request could not be processed becuase of conflict in resources
459+
description: Request could not be processed because of conflict in resources
460+
NoContent:
461+
description: Success. No content returned.
460462
parameters:
461463
Page:
462464
name: page

server/mergin/sync/private_api_controller.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,6 @@ def download_project(id: str, version=None): # noqa: E501 # pylint: disable=W06
331331
project_id=project.id, name=lookup_version
332332
).first_or_404("Project version does not exist")
333333

334-
if project_version.project_size > current_app.config["MAX_DOWNLOAD_ARCHIVE_SIZE"]:
335-
abort(400)
336-
337334
# check zip is already created
338335
if os.path.exists(project_version.zip_path):
339336
if current_app.config["USE_X_ACCEL"]:
@@ -370,7 +367,7 @@ def prepare_archive(id: str, version=None):
370367
abort(400)
371368

372369
if os.path.exists(pv.zip_path):
373-
return "Project archive already ready", 200
370+
return NoContent, 204
374371

375372
# trigger job if no recent partial
376373
temp_zip_path = pv.zip_path + ".partial"
@@ -380,7 +377,8 @@ def prepare_archive(id: str, version=None):
380377
) < datetime.now(timezone.utc) - timedelta(
381378
seconds=current_app.config["PARTIAL_ZIP_EXPIRATION"]
382379
)
383-
if not partial_exists or is_expired:
384-
create_project_version_zip.delay(pv.id)
380+
if partial_exists and not is_expired:
381+
return NoContent, 204
385382

386-
return "Project zip being prepared", 202
383+
create_project_version_zip.delay(pv.id)
384+
return "Project zip creation started", 201

server/mergin/tests/test_private_project_api.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -456,21 +456,21 @@ def test_download_project(
456456
assert resp.status_code == 200
457457

458458

459-
def test_large_project_download_fail(client, diff_project):
460-
"""Test downloading too large project is refused"""
461-
resp = client.get(
459+
def test_prepare_large_project_fail(client, diff_project):
460+
"""Test asking for too large project is refused"""
461+
resp = client.post(
462462
url_for(
463-
"/app.mergin_sync_private_api_controller_download_project",
463+
"/app.mergin_sync_private_api_controller_prepare_archive",
464464
id=diff_project.id,
465465
version="v1",
466466
)
467467
)
468-
assert resp.status_code == 202
468+
assert resp.status_code == 201
469469
# pretend testing project to be too large by lowering limit
470470
client.application.config["MAX_DOWNLOAD_ARCHIVE_SIZE"] = 10
471-
resp = client.get(
471+
resp = client.post(
472472
url_for(
473-
"/app.mergin_sync_private_api_controller_download_project",
473+
"/app.mergin_sync_private_api_controller_prepare_archive",
474474
id=diff_project.id,
475475
version="v1",
476476
)
@@ -480,17 +480,17 @@ def test_large_project_download_fail(client, diff_project):
480480

481481
test_prepare_proj_data = [
482482
# zips do not exist, version not specified -> trigger celery to create zip with latest version
483-
(0, 0, 0, None, 202, 1),
483+
(0, 0, 0, None, 201, 1),
484484
# expired partial zip exists -> call celery task
485-
(0, 1, 1, None, 202, 1),
485+
(0, 1, 1, None, 201, 1),
486486
# valid partial zip exists -> do not call celery
487-
(0, 1, 0, None, 202, 0),
487+
(0, 1, 0, None, 204, 0),
488488
# zips do not exist, version specified -> call celery task with specified version
489-
(0, 0, 0, "v1", 202, 1),
489+
(0, 0, 0, "v1", 201, 1),
490490
# specified version does not exist -> 404
491491
(0, 0, 0, "v100", 404, 0),
492492
# zip is already prepared to download -> do not call celery
493-
(1, 0, 0, None, 200, 0),
493+
(1, 0, 0, None, 204, 0),
494494
]
495495

496496

web-app/packages/lib/src/modules/project/store.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,6 @@ export const useProjectStore = defineStore('projectModule', {
707707
},
708708

709709
async downloadArchive(payload: DownloadPayload) {
710-
console.log("You are here")
711710
const notificationStore = useNotificationStore()
712711
await this.cancelDownloadArchive()
713712
this.projectDownloadingVersion = payload.versionId

0 commit comments

Comments
 (0)