Open source CapCut alternative.
TypeScript
docs: describe share streaming and the phone viewer
David Le55715abfc42b
diff --git a/docs/guides/cut/README.md b/docs/guides/cut/README.mdindex af8feb64..a4451e84 100644--- a/docs/guides/cut/README.md+++ b/docs/guides/cut/README.md@@ -30,7 +30,7 @@ The client probes the engine's health endpoint (dedicated port first, dev serverCloud projects make Cut usable in any browser on any OS with nothing installed, and they run alongside local ones: every account has both halves, and which one a project uses is decided per project.-Every client call goes through a backend seam (`site/src/cut/lib/backend/`): the local driver is the engine transport unchanged, and the cloud driver rewrites the same paths to `/api/cut-cloud/*` with the session cookie. Residency is per project — the home screen lists "On this Mac" and "Cloud" sections, each served by its own driver, and opening a project binds the editor to that project's backend. Capability flags on the driver hide what a backend can't do, so components never feature-detect.+Every client call goes through a backend seam (`site/src/cut/lib/backend/`): the local driver is the engine transport unchanged, and the cloud driver rewrites the same paths to `/api/cut-cloud/*` with the session cookie. Residency is per project and fixed when the project is created, so creating one is where the user chooses: New project carries a picker — this Mac or the cloud — whenever both are reachable, and the choice sticks on that browser until they change it. With no Donkey app running there is nothing to choose and every new project is a cloud project; inside a folder the folder decides, since a project files only into a folder beside it. The home lists both shelves as one listing, each project badged with where it lives, and opening one binds the editor to that project's backend. Capability flags on the driver hide what a backend can't do, so components never feature-detect.The library is the exception, because it is a shelf rather than a place: it lists every residency the browser can reach at once — the Mac's when an engine has answered, the cloud's always — as one listing, newest first, with a badge saying which shelf each item is on. So a cloud project can pull a clip off this Mac, and a local project can pull one out of the cloud. Each item's own shelf answers for it: previews, renames, and deletes go to the backend it came from, and folders belong to one shelf, so items file only into folders beside them. Adding to a project is the one crossing: on the project's own shelf the server copies the file without the bytes leaving it, and off it the browser carries them down and back up.@@ -42,6 +42,18 @@ Storage a subscription paid for outlives the subscription for a while: when ProA cloud project can be shared read-only, Google-Docs style: the editor's Share dialog invites specific emails (viewers sign in) or opens the link to anyone (no sign-in), and switches opt extra surfaces in — chat, media, AI generations, subtitles, details — on top of the always-shared preview and timeline. The share row's id is the link token, so revoking deletes the link. Viewers ride a third backend driver against `/api/cut-shared/<token>/*`, a deliberately public API surface (the one exception to session auth on the cloud side): the server resolves access per request, filters the doc to the shared surfaces before it leaves, and refuses media outside that filter, so hiding is enforced by the backend rather than the client. A public share's reads are cached at the edge for a lifetime that tracks how long the owner has been idle — a doc saved seconds ago is served near-live, one untouched for an hour is served from cache for minutes — and the same number is handed back as the viewer's poll interval, so a link a crowd opens costs a handful of origin requests rather than one per viewer per tick. A restricted share's reads depend on the viewer's session, so they are never cached. A shared project's media is served from Cloudflare's edge rather than presigned against R2's S3 endpoint, which nothing caches: a Worker holding a private bucket binding checks a short token the hosted API mints, then answers from cache keyed on the object alone. Dropping the token from the cache key is what makes the token affordable to keep short — every viewer and every re-mint share one cached copy — and a short token is what makes unsharing mean something, since a presigned URL is a bearer credential nothing can withdraw before it expires. Owner-side editing still presigns R2 directly, where the URLs are minted on fixed windows so a browser can reuse bytes across reloads. A shared link unfurls with the project's own card: the render worker derives a first-frame still and a five-second animation from the opening of the cut, the page's metadata points at them through a URL carrying the doc version, and a project with no card yet gets a drawn one. Viewers poll the doc version on an interval the server picks — shared views trail live edits, they don't stream them — and a "Copy project" action duplicates everything the share exposes — the filtered doc, its media, and the chat threads when chat is shared — server-side into the viewer's own account and quota. Copies queue rather than run in the request: each request writes a job row and publishes it to a Cloudflare Queue whose serial consumer executes one copy at a time, so a burst of copy requests can't stampede storage; the client polls the job for the outcome. An owner duplicating their own cloud project from the dashboard rides the same queue. Exports, hover-preview proxies, share cards, and URL imports run on the render worker — a pool of containers (`site/src/cut/worker/`) that claim job rows from Postgres, reuse the engine's exact ffmpeg pipeline against R2, and report progress back through the rows the client polls. Each replica takes one job at a time, so a render has the whole machine to itself, and the queue is claimed by what someone is watching first: an export or a URL import goes ahead of the background artwork. The artwork waits for a lull too — a project's hover proxy and share card rebuild when the editor closes or the tab goes to the background, so a session of editing spends the pool on the renders the user asked for. Transcription and mic dictation prefer this Mac: with the app running they use on-device speech even for a cloud project, and fall back to a hosted, credit-metered route — Gemini producing cue-level timestamps from browser-rendered audio, word timings interpolated inside each cue — when it isn't. That split between where a project's data lives and where its work runs is its own guide: [Local compute for cloud projects](local-compute.md). The assistant offers its Gemini models (which already run entirely in the page); the Claude/Codex CLI providers stay app-only because they are the user's local logins.+A share link opened on a phone plays rather than edits. The editor composites a project live — a video decoder per clip, painted onto a canvas — which is the right design on a desktop and an impossible one on a phone, where the decoders alone exhaust what a tab is given. So below the width the editor needs, the share serves a player instead: the cut as a single adaptive stream with the platform's own controls, and whichever surfaces the share opted in — chat, media, subtitles, details — as sheets that rise over it. The desktop share is untouched. The choice is made in code rather than in styling, because hiding the editor with a class would still have mounted it and started every decode.++That stream is an adaptive ladder the render worker builds and stores in R2 beside the project's media. A single flattened file is the wrong answer once a cut can run long or land in 4K, for two reasons. The edge declines to cache any object past half a gigabyte, so the file that most needs caching is exactly the one that never gets it, while segments of a few megabytes always do. And one bitrate cannot serve both a phone on a weak cellular link and a desktop on a 4K panel; a ladder lets the player choose, and change its mind mid-watch. Rungs are capped at the source so nothing is upscaled, and the low ones publish first, which is what makes a share watchable well before the slowest rung finishes. Each render writes a new version of the tree, so a viewer already watching keeps playing off the old one while the next is built, and the superseded version is swept a day later. Access is the same short-token scheme as the rest of a share's media, with one difference: the token covers the whole tree and rides in the path, because a player reaches segments by following relative links out of a playlist and a query string does not survive that hop.++A ladder is the one thing in the bucket that is neither the user's media nor charged to them. It is a delivery format the product picked, rebuilt whenever a shared project settles, and the footage it was built from is already paid for — so it carries no media rows and never counts against a storage quota. That is also why it needs an index of its own: with no rows, a tree nothing points at is a leak nothing can find. So a Workers KV record, not the database, tracks every version a project has ever *started* — claimed before the first byte uploads, so a render that dies partway still leaves a trail — along with the one it serves and the ones it has replaced, each stamped with when it was replaced. The sweep runs off those stamps: a replaced ladder gets a day before its segments go, counted from the moment it stopped being current rather than from whenever its bytes were written, and a claim whose render never finished is collected once it is too old to still be running. Work scales with the garbage rather than the project count, so no project waits behind a fixed number of others.++Rebuilding waits for the same lull the hover proxy does — the editor closing, or the tab going to the background — because unlike the five-second card it re-encodes the whole cut once per rung, and an interaction like opening a dialog is the wrong thing to hang that on. At most one ladder renders while one waits, and the waiting one is replaced rather than kept, so an edit made mid-render is never the thing that gets dropped.++What a viewer sees is answered in their favour: until a ladder exists, and while one is still rendering, the phone plays the project's flattened proxy and swaps in the real stream when it appears — though never mid-playback, since replacing a video someone is watching would restart the cut at zero. So a link shared before any of this existed still plays.++Both renders are subject to the same content boundary as the doc. Captions are burned into pixels, which no later filter can undo, so a share that hides Subtitles is rendered without them and the record remembers what each ladder actually burned in; if the owner turns Subtitles off afterwards, the existing ladder is withheld rather than served, and the next render replaces it.+## One API surface, one routerEvery Cut API route is a framework-free handler (web-standard request in, response out) registered once in a route table (`matchCutRoute`), namespaced under `/api/cut/*` to keep it clear of Donkey's own APIs. Both surfaces dispatch through that one table: the packaged engine mounts it directly, and the Next dev server reaches it through a single optional-catch-all route (`/api/cut/[[...slug]]`). They are the same router — static-over-dynamic precedence, HEAD, and 405s behave identically, and there is nowhere for the two to drift. The hosted 404 is applied once, in that shared dispatch.