| 1 | import { DurableObject } from "cloudflare:workers"; |
| 2 | import type { Env } from "./env.js"; |
| 3 | import { finalKey, runComposeStep, stagingPrefix, stepKeys, type BlobBucket, type ComposeStep } from "./lib/blob-store.js"; |
| 4 | import type { BlobRef } from "./lib/runtime-auth.js"; |
| 5 | |
| 6 | /** |
| 7 | * Runs one step of joining an upload's blocks (lib/blob-store.ts `compose`): each step in an object |
| 8 | * of its own (a fresh id), so the steps of a large artifact or cache really run at once and the |
| 9 | * copying doesn't load the repository's object, which serves the rest of its traffic. Ran in RepoDO |
| 10 | * before: eight steps at once made its other calls up to ten times slower while a 200 MiB upload |
| 11 | * was joined. Only the Worker calls it, after checking the upload may still be written. |
| 12 | */ |
| 13 | export class ComposeDO extends DurableObject<Env> { |
| 14 | async step(b: BlobRef, step: ComposeStep, contentType?: string): Promise<Array<{ partNumber: number; etag: string }>> { |
| 15 | if (!stepKeys(step).every((k) => k === finalKey(b) || k.startsWith(stagingPrefix(b)))) throw new Error("the step names objects outside this upload"); |
| 16 | return runComposeStep(this.env.BUCKET as unknown as BlobBucket, step, contentType); |
| 17 | } |
| 18 | } |