Skip to content
44 linesCodeBlameRaw

Pick any line to see why it is the way it is: the commit, the pull request and issue it came from, and what the agent was thinking.

Artifacts is a mode in the rail, the shell and the phone's tab bar in place of Docs: its home lists everything you can open by day or as cards under All, Yours and Shared with you, with search, filters and tiles to start a doc (slides, designs and dashboards say they are coming soon), and its sidebar holds favorites, spaces, Private, Shared, projects' docs and the trash.1import { env } from "cloudflare:workers";
2import { data } from "react-router";
3
4import { DOCS_VIEWER_HEADER, DOC_MAX_FILE_BYTES } from "@g1t/contracts";
5
6import type { Route } from "./+types/upload";
7import { assertSameOrigin, requireUser, roleIn } from "../../../lib/session.server";
8
9/**
10 * A file put in an artifact (an image, a PDF, an attachment):
11 * `POST <site>/<workspace>/-/artifacts/upload?folio=<id>&name=<file name>`
The artifacts service is services/artifacts, the Worker g1t-artifacts, bound as ARTIFACTS by the API, the site and the agents; its live rooms move to it with a Durable Object transfer from g1t-docs-service, and its database, bucket, indexes and queue keep their names. The git store's binding and settings are GITSTORE, its ops scripts gitstore-*, and workflow run artifacts keep their compatible API under run_artifacts modules. The deploy tool puts a Worker that has never deployed before the Workers in its stage that bind to it, and the deploy guide gives the cutover runbook.12 * with the file as the body. The artifacts service checks the viewer can edit
Artifacts is a mode in the rail, the shell and the phone's tab bar in place of Docs: its home lists everything you can open by day or as cards under All, Yours and Shared with you, with search, filters and tiles to start a doc (slides, designs and dashboards say they are coming soon), and its sidebar holds favorites, spaces, Private, Shared, projects' docs and the trash.13 * the folio, keeps the file, and answers with its address on the usercontent
14 * origin, where it is served, never on the site.
15 */
16export async function action({ params, context, request }: Route.ActionArgs) {
17 assertSameOrigin(request);
18 const viewer = requireUser(context, request);
19 if (!roleIn(viewer, params.owner)) throw data(null, { status: 404 });
20 const url = new URL(request.url);
21 const length = Number(request.headers.get("content-length") ?? "0");
22 if (!length || length > DOC_MAX_FILE_BYTES) {
23 return Response.json({ ok: false, error: { code: "invalid", message: `Files can be up to ${DOC_MAX_FILE_BYTES / 1024 / 1024} MB.` } });
24 }
25 const target = new URL("https://docs/files");
26 target.searchParams.set("workspace", params.owner.toLowerCase());
27 target.searchParams.set("folio", url.searchParams.get("folio") ?? "");
28 target.searchParams.set("name", url.searchParams.get("name") ?? "file");
29 try {
The artifacts service is services/artifacts, the Worker g1t-artifacts, bound as ARTIFACTS by the API, the site and the agents; its live rooms move to it with a Durable Object transfer from g1t-docs-service, and its database, bucket, indexes and queue keep their names. The git store's binding and settings are GITSTORE, its ops scripts gitstore-*, and workflow run artifacts keep their compatible API under run_artifacts modules. The deploy tool puts a Worker that has never deployed before the Workers in its stage that bind to it, and the deploy guide gives the cutover runbook.30 const answer = await env.ARTIFACTS.fetch(target.toString(), {
Artifacts is a mode in the rail, the shell and the phone's tab bar in place of Docs: its home lists everything you can open by day or as cards under All, Yours and Shared with you, with search, filters and tiles to start a doc (slides, designs and dashboards say they are coming soon), and its sidebar holds favorites, spaces, Private, Shared, projects' docs and the trash.31 method: "PUT",
32 headers: {
33 "content-type": request.headers.get("content-type") ?? "application/octet-stream",
34 "content-length": String(length),
35 [DOCS_VIEWER_HEADER]: JSON.stringify(viewer),
36 },
37 body: request.body,
38 });
39 return new Response(answer.body, { headers: { "content-type": "application/json", "cache-control": "no-store" } });
40 } catch (error) {
41 console.error("artifacts: upload", error);
42 return Response.json({ ok: false, error: { code: "conflict", message: "Artifacts didn't answer. Try again." } });
43 }
44}