feat(web): multi-file batch upload endpoint (POST /shrink-batch)#195
Open
seonghobae wants to merge 1 commit into
Open
feat(web): multi-file batch upload endpoint (POST /shrink-batch)#195seonghobae wants to merge 1 commit into
seonghobae wants to merge 1 commit into
Conversation
The web UI could only shrink one file per request while the CLI handles whole folders. This adds a batch endpoint plus a matching upload form: - POST /shrink-batch accepts up to MAX_BATCH_FILES (20) uploads via FastAPI list[UploadFile], converts each with media_shrinker.convert_file, and returns one ZIP_STORED archive containing every successful output plus a results.json manifest (per-file status, output name, output bytes, error message). - Per-file failures are recorded in the manifest and never abort the rest of the batch. - Validation: 400 for zero files, more than 20 files, or target_bytes <= 0; per-file audio/*|video/* content-type allowlist; per-file MAX_UPLOAD_BYTES cap with the same 1 MB chunked save pattern as /shrink; outputs are only served from inside the request's temp workspace. - Each upload gets isolated input_N/output_N dirs so duplicate filenames cannot collide; zip entries are prefixed with the upload index. - Temp workspace is cleaned up after the response via background task. - Existing /shrink endpoint and its tests are untouched. Gates: 126 tests (baseline 5 macOS os.listxattr errors only), coverage 100% on saas_web.py, interrogate 100%. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CJRVbDrp1vGYkJgNHMGPpG
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The web app's
/shrinkaccepts exactly one file, so users who batch-shrink folders with the CLI had no web equivalent. This PR addsPOST /shrink-batch: upload multiple media files, get back a single zip with every shrunk output plus aresults.jsonmanifest.What's included
POST /shrink-batch— acceptslist[UploadFile](up toMAX_BATCH_FILES = 20) andtarget_bytes, converts each file with the existingmedia_shrinker.convert_fileengine, and returns oneZIP_STOREDarchive.results.jsonmanifest inside the zip — per-fileindex,filename,status(ok/error),output_name,output_bytes, anderrormessage.multiplefile input) posting to the new endpoint; existing single-file form untouched./shrinkis untouched — handler code and all its existing tests are unmodified and passing.Validation & security
target_bytes <= 0.audio/*/video/*content-type allowlist (rejected files recorded in the manifest, not converted).MAX_UPLOAD_BYTEScap using the same 1 MB chunked save pattern as/shrink; whole request still bounded by the existing request-size middleware.input_N//output_N/dirs per upload — duplicate filenames cannot collide; zip entries are index-prefixed.BackgroundTasks.Tests (13 new, FastAPI TestClient with mocked
convert_file)target_bytes=0→ 400Gates
coverage report --include=saas_web.py→ 100% (182 stmts, 0 miss)interrogate -c pyproject.toml saas_web.py→ 100%unittest discover -s tests→ 126 tests, no new failures (baseline exactly 5 macOSos.listxattrerrors)🤖 Generated with Claude Code