Hono-based Cloudflare Worker for GKD snapshot detection, build asset lookup, and safe public GitHub attachment proxying.
GET /snapshot-detect/getSnapshotListreturns all stored snapshot/import mappings.GET /snapshot-detect/getImportId?id=<positive-safe-integer>returns the stored GitHub import ID ornull.GET /snapshot-detect/detectSnapshot?id=123&importId=456preserves the original query-string API.POST /snapshot-detect/detectSnapshotaccepts JSON{ "id": 123, "importId": 456 }as the write-oriented alternative. Both forms verifysnapshot.jsonfrom the public GitHub attachment before storing the mapping in D1.GET /build-asset/getBuildAsset?buildKey=<string>returns{ "assetId": 123 }ornull.GET /build-asset/getBuildAssetListreturns every stored{ "buildKey": "...", "assetId": 123 }mapping ordered bybuildKey.POST /build-asset/createBuildAssetaccepts JSON, URL-encoded form data, or multipart form data containingbuildKeyandassetId. It requiresAuthorization: Bearer <token>, creates or updates the D1 mapping, and returns both fields.GET /proxy?url=<encoded-github-attachment-url>streams a rate-limited, header-filtered public GitHub ZIP attachment. It accepts currenthttps://github.com/user-attachments/files/<id>/<filename>.ziplinks and legacyhttps://github.com/gkd-kit/inspect/files/<id>/<filename>.ziplinks.- Framework-generated
HEADandOPTIONSresponses do not carry business logic. Unsupported paths, methods, and business errors return HTTP 200 JSON containingerror: true; successful JSON APIs return their business data without a response envelope.
The proxy does not forward cookies, authorization headers, or other private request state. Initial targets must match one of the GitHub ZIP attachment formats above without a query string or fragment. Redirects are followed manually and may only remain on an allowed attachment URL or continue to GitHub's objects.githubusercontent.com repository-file storage path. Direct CDN URLs, GitHub Raw or Release URLs, image attachment URLs, non-GitHub hosts, credentials, IP literals, local hostnames, non-default ports, and non-HTTPS URLs are rejected.
Successful proxy responses are transparent transport responses and retain the upstream status, selected headers, and body. Proxy errors generated by this Worker use the JSON error contract above.
Configure the shared GKD_API_AUTH_TOKEN as a plaintext variable in the Worker's Cloudflare dashboard settings. Wrangler is configured with keep_vars so deployments preserve dashboard-managed variables. For local development, set the same variable in the ignored .dev.vars file:
GKD_API_AUTH_TOKEN=local-development-tokenSend the configured value to authenticated routes as a Bearer token. Missing, malformed, or incorrect credentials are rejected before the request body is parsed or D1 is modified.
Requirements are pinned through package.json devEngines. All dependency versions live in the strict pnpm catalog, and pnpm rejects releases newer than one day.
- Run
pnpm install. - Run
pnpm typesafter changingwrangler.jsoncto refresh editor types; validation commands regenerate them automatically. - Run
pnpm d1:migrate:local. - Run
pnpm dev.
Use pnpm check for type generation, TypeScript checks, Workers/D1 integration tests, and a Wrangler deployment dry-run. Run pnpm audit --audit-level high --registry=https://registry.npmjs.org/ before deployment.
The configuration binds directly to the existing gkd D1 database by its database ID. Before deploying the build asset routes, apply the checked-in migrations with pnpm d1:migrate:remote. The existing snapshot migration uses CREATE TABLE IF NOT EXISTS, so applying it records the baseline without replacing snapshot data; the next migration adds build_asset.
Deploy to the generated workers.dev hostname before changing any custom-domain routing or removing the old Workers.
Pushes to main and manual GitHub Actions runs targeting main run pnpm check, then use the project-local Wrangler to apply pending D1 migrations and deploy the Worker. Configure repository secrets CLOUDFLARE_API_TOKEN with Workers Scripts Edit and D1 Edit permissions and CLOUDFLARE_ACCOUNT_ID for the target Cloudflare account.
The workflow reads Node and pnpm versions from package.json: actions/setup-node@v6 uses devEngines.runtime, while pnpm/action-setup@v6 uses devEngines.packageManager.
The old snapshot-detect Worker remains the rollback target and is not modified by this package.