refactor(media): upload pieces are PUT, not PATCH

A piece at an offset is idempotent, which is what PUT means. Java's
HttpURLConnection, which the Kotlin port uses, refuses PATCH outright. nginx
also retries PUT on the next upstream by default but never PATCH, so the docs
now only ask for non_idempotent on the start/status POST. The protocol is
unreleased, so nothing else depends on the old method.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-10-19 00:09:09 +02:00
parent 441f26f814
commit f42a9bbe5e
6 changed files with 14 additions and 13 deletions

View File

@@ -194,7 +194,7 @@ export class MediaClient {
const length = Math.min(chunk, size - offset);
const piece = await cut(offset, offset + length);
const res = await send({
method: 'PATCH',
method: 'PUT',
headers: {
'content-type': 'application/octet-stream',
'content-length': String(length),
@@ -256,7 +256,7 @@ export class MediaClient {
// that failed and was retried): an empty piece at the end finishes it.
await retrying(async () => {
const res = await send({
method: 'PATCH',
method: 'PUT',
headers: { 'content-length': '0', [OFFSET_HEADER]: String(size), ...this.owner.headers({ op: 'piece', id, offset: size, length: 0 }) },
});
if (res.status !== 201) return fail(res, 'finish');

View File

@@ -3,7 +3,7 @@
*
* PUT /v1/media/:id signed by the owner; body = a sealed SMF1 file of at most one piece
* POST /v1/media/:id/upload signed; start a resumable upload, or ask how far it got
* PATCH /v1/media/:id/upload signed; one piece of it (see `upload.ts`)
* PUT /v1/media/:id/upload signed; one piece of it (see `upload.ts`)
* DELETE /v1/media/:id/upload signed; give up on it
* HEAD /v1/media/:id size (read token if the upload set one)
* GET /v1/media/:id Range-capable read of the sealed bytes
@@ -210,7 +210,7 @@ export function createMediaRoutes(store: MediaStore, opts: MediaRoutesOptions =
}
});
app.patch('/v1/media/:id/upload', async (c) => {
app.put('/v1/media/:id/upload', async (c) => {
const id = c.req.param('id');
if (!ID_RE.test(id)) return c.json({ error: 'BAD_ID' }, 400);
const length = Number(c.req.header('content-length') ?? '0');

View File

@@ -11,7 +11,7 @@
* POST /v1/media/:id/upload start, or ask how far an upload got
* → `{ size, chunk, window, received, landed }`, plus
* `complete: true` if it was stored (its last answer was lost)
* PATCH /v1/media/:id/upload one piece at `x-shade-offset`
* PUT /v1/media/:id/upload one piece at `x-shade-offset`
* → 200 `{ received }`, or 201 once the file is stored
* DELETE /v1/media/:id/upload give up
*