fix(api): align upload API contract between docs, routing, and responses - #22
Open
usehoplite[bot] wants to merge 1 commit into
Open
fix(api): align upload API contract between docs, routing, and responses#22usehoplite[bot] wants to merge 1 commit into
usehoplite[bot] wants to merge 1 commit into
Conversation
- README: document the real routes (POST /api/v1/storage/presign,
POST /api/v1/assets/{assetId}/complete) and their actual response
envelopes instead of endpoints that do not exist
- router: register /assets/{assetID}/complete as POST; the handler
mutates state (transaction + job enqueue), so GET was unsound
- service: return the real object key and an absolute unix expiry in
UploadAssetResponse; both previously reported values clients could
not act on (fileName instead of object path, relative seconds
instead of a timestamp), and bound both to one presignExpiry const
- response: WriteErrorResponse now uses the status envelope used by
every other endpoint instead of a divergent success:false shape
Co-authored-by: Shantanu Mane <shantanu.mane.200@outlook.com>
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
Audited MPiper's main user flow — presign → direct upload → complete → processing — against actual code behavior and found the documented API contract diverges from what the server actually serves. This PR aligns docs, routing, and response payloads with verified behavior, and fixes three response fields that returned values clients could not act on.
Changes
README.md — API documentation corrected to the real routes
POST /api/v1/assets/upload→POST /api/v1/storage/presign(the router registers/storage/presign; the documented path never existed)POST /api/v1/assets/{assetId}/uploaded→POST /api/v1/assets/{assetId}/complete(actual route){"status": "success", "data": {...}}envelope; "Mark Asset as Uploaded" response corrected to the handler's actual{"status": "success", "message": ...}shape (no longer claims anassetIdfield that isn't returned)Authorization: Bearer <token>headerinternal/router/router.go —
GET /api/v1/assets/{assetID}/complete→ POSTMarkAssetUploadedmutates state (DB transaction, inserts job, enqueues to Redis); registering it as GET was unsound (caches/link prefetchers can fire it, and the README already documented POST).internal/service/asset.go — response fields clients could not use
ObjectPathreturned the client'sfileNameinstead of the actual object key (media/raw/<assetID>) the presigned URL and worker operate onExpiresAtreturned relative300seconds while the field's contract (and README example) is an absolute Unix timestamppresignExpiryconstant used for the presigned URL TTL as well, so they cannot driftpkg/utils/response.go — consistent error envelope
WriteErrorResponseemitted{"success": false, ...}while every other endpoint (handlers, rate limiter, root) uses thestatusenvelope; unified to{"status": "error", ...}.Verification
go build ./...— cleango vet ./...— cleango test ./internal/... ./pkg/...— all pass (TestPerformanceLatenciesintests/requires the externalPERF_TEST_URLand fails identically on the base branch; it is not affected by this change)gofmt(note:metrics.go,otel.go,queue.goare pre-existing gofmt violations on the base branch unrelated to this PR)Notes for maintainers
staging; this PR was created against the repository's configured base (master).workflow_dispatchor when the PR carries thelint/run-unit-testslabels; apply those labels to get checks on this PR.