Diffinery

codician/diffinerypublic

Open-source, agent-first GitHub and GitHub Actions alternative that runs on your own Cloudflare account: git hosting, pull requests, code review and drop-in GitHub Actions YAML on Workers, Durable Objects, R2 and Containers.

18 lines · 1.2 KBRaw History
1import { DurableObject } from "cloudflare:workers";
2import type { Env } from "./env.js";
3import { finalKey, runComposeStep, stagingPrefix, stepKeys, type BlobBucket, type ComposeStep } from "./lib/blob-store.js";
4import 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 */
13export 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}