Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Kinetic: every account can save its clips, no GPU or key needed

Adarsh3594fc9b7dc0
diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md
index fc9fb97f..c70cd96d 100644
--- a/docs/ARCHITECTURE.md
+++ b/docs/ARCHITECTURE.md
@@ -145,7 +145,7 @@ Every adapter implements `isConfigured`, `prepareFile`, `submit` and `poll`, and
- **Round 5 part 1 (fixes-5): reachability shared with Ollama.** The busy-vs-down rules above moved to `src/server/providers/reach.ts` (`hostPort`, `takesConnection`, `ask`, `checkReach`, `sharedCheck`, `reachSync`), which Ollama's check now uses too (see LLM provider). `REACH` is exported from there, and one map of running checks (`globalThis.__fuobeReachChecks`) replaces `__fuobeComfyProbe`; `probeComfy` and `probeComfySync` keep their behaviour (`tests/comfy-reach.test.ts`).
- **Round 5 part 2: soundtrack splits and asked sizes.** On `separate-soundtrack-dbs`, `prepareWorkflow()` binds `separationModel` to the model asked for, else the host's pick (`dbsModelFor` in `src/lib/av/split.ts`: DBS-TIGER on a CUDA device, DBS-BSRNN on a CPU, the other one when the pick isn't on disk). The device comes from `/system_stats` (`comfyDevice`, kept a minute) and the models on disk from `GET /models/dbs`, which ComfyUI-DBS registers (`comfyDbsModels`, read fresh at submit; callers that arrive while either request is on its way share it); a model that isn't there is refused in words, never sent. `channels` is mono or each channel (`dbsChannelsFor`), and a source with more than 2 channels (the header's count, else `params.extra.sourceChannels`) is split in mono with a mono Music & effects (`dbsSurroundBed`), because ComfyUI saves at most 2 channels. A canvas the request names (`params.extra.width` / `height`: a layout's, Soul's exact sizes) is fitted to the graph's grid and maximum side with its shape kept (`fitCanvas` in `src/lib/comfy.ts`), as the cloud's `sizeValue` fits it, so both engines render one size. Upload headers carry the channel count (`MediaInfo.channels`: WAV, FLAC, MP3 and an MP4 / MOV's first sound track in `src/lib/media-probe.ts`; WebM / Matroska in `src/server/webm-probe.ts`). The manifest's outputs gain the stems `music` and `effects` and the role `report` (a node's own account of the run).
- **llm** — text steps in this process (below).
-- **local** — results made in the browser (Color grading's PNG / WebM, Ads Studio composites, Kinetic Motion clips; `/api/generations/local` records them, an account's Kinetic Motion clip as its own run).
+- **local** — results made in the browser (Color grading's PNG / WebM, Ads Studio composites, Kinetic Motion clips; `/api/generations/local` records them, an account's Kinetic Motion clip as its own run, with or without its own GPU or key).
- **mock** — demo outputs for every operation (SVG art, bundled sample clips, a tone, layers with meta, cue lists, two stems, a GLB with a turntable from `scripts/gen-demo-3d.mjs`), so the product works with zero setup. Round-4 operations answer too: a scene-3d job gets the GLB plus a grey depth PNG on the open engine and a Spectral-coloured depth PNG on the cloud, and an EXR job a sample clip with a zip that holds only a README. An extract-frames job returns as many frames as `max_frames` asks (4 without a count), so a per-frame Mixed Media demo fans out like the real one. Splat and rig jobs get the demo GLB too (`meta.format` `glb`), so a demo run never shows the splat card. Since round 4 part 5 a `video-swap` on Character Swap Studio's segment graph also returns a `master`, so a demo continuation runs like a real one. Since round 5 part 1 a `face-mosaic` job returns a demo picture with no masks. Since round 5 part 2 a `separate-audio` job on `separate-soundtrack-dbs` returns four stems (voice, music, effects and background, voice first). A request with `demo: true` (a skill's free dry run) goes to this provider whatever Settings → Demo mode says (see Pipelines).
## Structured outputs
@@ -404,7 +404,7 @@ Each studio keeps its data and pure planner in `src/lib/`, its server module in
## Kinetic Motion (`src/lib/motion/`, `src/components/motion/`)
-Motion graphics drawn by code, in the brand's own fonts and colours, with the words exactly as typed. A **scene** is a pure function of a **recipe** (JSON: scene, seed, size, fps, length, the typed fields, the brand, the person's own files, control values, export settings) and an absolute time: `scene.plan(input)` lays the text out once (`layout.ts`: balanced lines, never cut, never re-cased, never split mid-word; a field that doesn't fit is reported as `overflow` and blocks the render) and builds a timeline of cues (`tween.ts`, on the named curves in `ease.ts`: Bézier, closed-form springs), and `plan.evaluate(t)` gives a display list (`display.ts`: groups with transforms, clips, masks and blends; rects, ellipses, paths with stroke trim, text runs, images) in design units (1080 on the short side, `sizes.ts`). Randomness is a hash of the seed and a key (`random.ts`); there is no clock, DOM or `Math.random` in `src/lib/motion`, so any frame can be seeked in any order (`tests/motion-scenes.test.ts`). `camera2d.ts` is a 2.5D camera with parallax by depth. The browser half: `draw.ts` (`drawDisplayList`, the only code that draws a list, and SVG logo outlines read with the browser's SVG engine), `fonts.ts` (an export waits for the brand font or stops), `player.tsx` (the live preview: absolute time on animation frames, pauses off screen or in a hidden tab, rest frame for reduced motion, a smaller backing store on slow devices), `render.ts` (`renderClip`: frame i at i / fps, motion blur from shutter samples never across a cut, as many per frame as its fastest edge needs (`listTravel` in `display.ts`: one for a frame that barely moves, up to 48), WebCodecs H.264 MP4 from the canvas itself, else VP8 WebM, else the recorder) and `save.ts` (`saveMotionResult`: `POST /api/uploads`, then `POST /api/generations/local` with model `local-motion`, op `motion` and the recipe in `params.extra.motion`; nothing is downloaded from the page). Phase 1 ships the end card's five styles (`scenes/end-card/`: Draw-on, Rise, Iris, Split, Glint), whose rest frame is the still card's own layout (`planEndCard` and `renderEndCard` use the same `endCardRest` and drawer). The rest layout sizes type from the frame's short side, keeps a tall card's bottom fifth clear, and sets the words and pill in the kit colour that reads best on the brand colour (`cardColours`). Each style opens a few frames into its motion (`lead`), is readable by about 0.9 s of a 2.5 s card (`settled`), then a slow push-in (`CAMERA_FROM`, the `drift` curve) comes home on the last frame (`rest`, the poster); `signature` is the frame the style chooser shows. A saved clip carries its poster in `output.meta.poster`. Click to Ad joins the rendered card after the ad: in the cloud with its silent track and `merge-videos`, on the open engine with `oss-join-sound1`, which re-encodes the ad at 25 fps (the still card's `oss-append-endcard` copies the ad's picture instead); the open path has not yet been run end to end on a GPU.
+Motion graphics drawn by code, in the brand's own fonts and colours, with the words exactly as typed. A **scene** is a pure function of a **recipe** (JSON: scene, seed, size, fps, length, the typed fields, the brand, the person's own files, control values, export settings) and an absolute time: `scene.plan(input)` lays the text out once (`layout.ts`: balanced lines, never cut, never re-cased, never split mid-word; a field that doesn't fit is reported as `overflow` and blocks the render) and builds a timeline of cues (`tween.ts`, on the named curves in `ease.ts`: Bézier, closed-form springs), and `plan.evaluate(t)` gives a display list (`display.ts`: groups with transforms, clips, masks and blends; rects, ellipses, paths with stroke trim, text runs, images) in design units (1080 on the short side, `sizes.ts`). Randomness is a hash of the seed and a key (`random.ts`); there is no clock, DOM or `Math.random` in `src/lib/motion`, so any frame can be seeked in any order (`tests/motion-scenes.test.ts`). `camera2d.ts` is a 2.5D camera with parallax by depth. The browser half: `draw.ts` (`drawDisplayList`, the only code that draws a list, and SVG logo outlines read with the browser's SVG engine), `fonts.ts` (an export waits for the brand font or stops), `player.tsx` (the live preview: absolute time on animation frames, pauses off screen or in a hidden tab, rest frame for reduced motion, a smaller backing store on slow devices), `render.ts` (`renderClip`: frame i at i / fps, motion blur from shutter samples never across a cut, as many per frame as its fastest edge needs (`listTravel` in `display.ts`: one for a frame that barely moves, up to 48), WebCodecs H.264 MP4 from the canvas itself, else VP8 WebM, else the recorder) and `save.ts` (`saveMotionResult`: `POST /api/uploads` sent with `x-fuobe-kinetic: 1`, which any account may send for an MP4 or WebM clip or a PNG poster, within its space and upload limits, since no model makes them; then `POST /api/generations/local` with model `local-motion`, op `motion` and the recipe in `params.extra.motion`; nothing is downloaded from the page). Phase 1 ships the end card's five styles (`scenes/end-card/`: Draw-on, Rise, Iris, Split, Glint), whose rest frame is the still card's own layout (`planEndCard` and `renderEndCard` use the same `endCardRest` and drawer). The rest layout sizes type from the frame's short side, keeps a tall card's bottom fifth clear, and sets the words and pill in the kit colour that reads best on the brand colour (`cardColours`). Each style opens a few frames into its motion (`lead`), is readable by about 0.9 s of a 2.5 s card (`settled`), then a slow push-in (`CAMERA_FROM`, the `drift` curve) comes home on the last frame (`rest`, the poster); `signature` is the frame the style chooser shows. A saved clip carries its poster in `output.meta.poster`. Click to Ad joins the rendered card after the ad: in the cloud with its silent track and `merge-videos`, on the open engine with `oss-join-sound1`, which re-encodes the ad at 25 fps (the still card's `oss-append-endcard` copies the ad's picture instead); the open path has not yet been run end to end on a GPU.
**Marketing templates drawn by code.** Ten Marketing Studio templates are Kinetic Motion scenes instead of model prompts (`render: "code"` in `catalog/marketing.ts`, with their `scene`, typed `fields` and `easy` choices): Kinetic Headline, Line-Art Reveal, Logo Sting, Feature Cards, Dashboard Zoom, Retro Starburst, and the new Offer Badge, Big Number, Five-Star Quote and Logo End Card (the five end-card styles as its Style choice). The scenes are in `src/lib/motion/scenes/marketing/` (`kit.ts`: the light, dark and brand-colour looks from the kit with every word at 4.5:1 or more, the safe area, the pace, the tabular rolling counter, `*stars*` that mark a highlighted word and are never drawn); `outline.ts` traces a cut-out picture's edge from its transparency (marching squares, then Ramer–Douglas–Peucker) for Line-Art Reveal, and a photo without one gets a traced frame. `template.ts` turns what the template's panel holds (words, choices, size, length 5–15 s, brand, picture) into the recipe; `showcase.ts` holds the fictional brands each template opens with. The panel (`components/marketing/kinetic-template.tsx` with `components/motion/{fields,easy-chips,brand-row,made-strip}.tsx`) replaces the composer for these templates: anyone can type and play, Save renders in the tab and records the clip as `feature: "marketing-kinetic"` through `save.ts` (the same upload rule as any file; a guest gets the sign-up card and an account with neither its own GPU nor a key the Connect card before anything renders), and "Made with this template" lists the saved clips, which open in the result viewer. Their covers are rendered by the engine itself: `scripts/kinetic/render-covers.mjs` plays each showcase on the development-only page `/dev/kinetic-covers` and writes cover masters (`meta.json` `rest`: `"end"`, or the seconds of the moment the words are all set), then `pnpm eval:covers --templates` versions them into `public/previews/templates/marketing/`.
diff --git a/docs/public-signup.md b/docs/public-signup.md
index 241278e0..1d6d8698 100644
--- a/docs/public-signup.md
+++ b/docs/public-signup.md
@@ -97,8 +97,9 @@ An account is signed in, but it sees the owner's studio as a guest does:
no other account can open it. See [Uploads](#uploads).
- **Results made in the browser (Kinetic Motion) are its own runs too.** A motion clip rendered in
the page (an animated end card, a text template) is saved with an upload and
- `POST /api/generations/local` (`op: "motion"`, model `local-motion`). It needs the same own GPU or
- own key as any upload, and counts as the account's own runs and files: the clip and every file it
+ `POST /api/generations/local` (`op: "motion"`, model `local-motion`). No model makes it, so any
+ account may save one, with or without its own GPU or key (the upload is sent with
+ `x-fuobe-kinetic: 1`; see [Uploads](#uploads)). It counts as the account's own runs and files: the clip and every file it
names (its pictures, and the recipe's logo, product and pictures) must be the account's own (403
otherwise), a clip is never made from a video (400), the stored file must be the MP4 or WebM it
claims to be (400), and it shares the account's hourly run budget (60 an hour with its other runs,
@@ -356,7 +357,10 @@ The code is `src/server/hosted.ts` (the switch, the place, the line), `src/serve
An account with its own ComfyUI connected, or its own key, can upload files (`POST /api/uploads`,
the file as the request body with its type in `Content-Type` and its name in `X-File-Name`; an
older page's multipart form works up to 26 MB). With neither it answers 403 with
-`code: "connect-gpu"`, and a guest gets 401 with the sign-up card.
+`code: "connect-gpu"`, and a guest gets 401 with the sign-up card. The one exception is a Kinetic
+Motion result rendered in the page (sent with `x-fuobe-kinetic: 1`): any account may upload its MP4
+or WebM clip and its PNG poster, within the same space, size and upload limits below. Any other type
+sent that way answers 403 `connect-gpu`, and a model run still needs the account's own GPU or key.
| What | Types | Largest |
|---|---|---|
diff --git a/src/app/api/uploads/route.ts b/src/app/api/uploads/route.ts
index dd3f1338..eaeee6a1 100644
--- a/src/app/api/uploads/route.ts
+++ b/src/app/api/uploads/route.ts
@@ -1,7 +1,7 @@
import fs from "node:fs";
import path from "node:path";
import { nanoid } from "nanoid";
-import { CONNECT_GPU_HEADER, CONNECT_GPU_UPLOAD_MESSAGE, CONNECT_GPU_UPLOAD_OPEN_MESSAGE } from "@/lib/guest-access";
+import { CONNECT_GPU_HEADER, CONNECT_GPU_UPLOAD_MESSAGE, CONNECT_GPU_UPLOAD_OPEN_MESSAGE, KINETIC_UPLOAD_HEADER } from "@/lib/guest-access";
import { accountProviders, paidAllowed } from "@/server/account-keys";
import { policy as billingPolicy } from "@/server/billing";
import { poolReady } from "@/server/hosted";
@@ -20,8 +20,10 @@ import { adoptFile, contentTypeFor, saveFile, scratchDir } from "@/server/storag
* proxy's checks here.
*
* - The owner: up to 200 MB, the types below.
- * - An account (public sign-up): only with its own ComfyUI connected or its own fal.ai or Replicate key (something to
- * run its files on); a picture up to 25 MB and 40 megapixels, a
+ * - An account (public sign-up): with its own ComfyUI connected or its own fal.ai or Replicate key (something to run
+ * its files on), any of the types below; without either, only a Kinetic Motion result rendered in its browser (sent
+ * with KINETIC_UPLOAD_HEADER: an MP4 or WebM clip, or its PNG poster), which no model makes. A picture up to 25 MB
+ * and 40 megapixels, a
* sound up to 50 MB, a clip up to 95 MB; its uploads up to 1 GB and all its files up to 3 GB; 60 uploads an hour,
* 300 a day, 2 at once. The stored type is read from the file's first bytes, never taken from the client.
*/
@@ -32,12 +34,20 @@ const UNSUPPORTED = "Fuobe can't open that file. Use a JPG, PNG, WebP, GIF, MP4,
/** Names browsers give AVI and Matroska files, to the one Fuobe stores them under. */
const VIDEO_ALIASES: Record<string, string> = { "video/avi": "video/x-msvideo", "video/msvideo": "video/x-msvideo", "video/vnd.avi": "video/x-msvideo", "video/mkv": "video/x-matroska" };
+/** A Kinetic Motion result rendered in the browser: its clip or its poster (the stored type, read from its bytes). */
+const KINETIC_TYPES = /^(video\/(mp4|webm)|image\/png)$/;
+
const KIND_CAP: Record<SniffKind, number> = { image: ACCOUNT_LIMITS.imageBytes, audio: ACCOUNT_LIMITS.audioBytes, video: ACCOUNT_LIMITS.videoBytes };
const KIND_MESSAGE: Record<SniffKind, string> = { image: ACCOUNT_MESSAGES.imageTooBig, audio: ACCOUNT_MESSAGES.audioTooBig, video: ACCOUNT_MESSAGES.videoTooBig };
const json = (status: number, body: Record<string, unknown>, headers: Record<string, string> = {}) =>
Response.json(body, { status, headers: { "Cache-Control": "no-store", ...headers } });
+/** An account with nothing that would let it add this file: "Connect your GPU" (with a key too, where paid models are on). */
+const connectFirst = () => json(403, { error: paidAllowed() ? CONNECT_GPU_UPLOAD_MESSAGE : CONNECT_GPU_UPLOAD_OPEN_MESSAGE, code: "connect-gpu" }, { [CONNECT_GPU_HEADER]: "1" });
+
+const isMultipart = (request: Request) => (request.headers.get("content-type") ?? "").toLowerCase().startsWith("multipart/form-data");
+
class TooBig extends Error {}
class Stalled extends Error {}
@@ -160,8 +170,16 @@ async function ownerUpload(request: Request): Promise<Response> {
// ---------------------------------------------------------------------------
// An account
+type Kinds = { image: boolean; video: boolean; audio: boolean };
+
+/**
+ * What an account with no GPU or key of its own may add: the kinds its runs on this install's GPUs may use (hosted runs
+ * on), and a Kinetic Motion result it rendered in its browser (no model makes one).
+ */
+type Without = { hosted: Kinds | null; kinetic: boolean };
+
/** The kinds of file an account with no GPU or key of its own may add for runs on this install's GPUs (hosted runs). */
-async function hostedUploads(accountId: string): Promise<{ image: boolean; video: boolean; audio: boolean } | null> {
+async function hostedUploads(accountId: string): Promise<Kinds | null> {
if (!poolReady()) return null;
const p = await billingPolicy(accountId);
if (!p?.hosted || !(p.uploads.image || p.uploads.video || p.uploads.audio)) return null;
@@ -170,10 +188,12 @@ async function hostedUploads(accountId: string): Promise<{ image: boolean; video
async function accountUpload(request: Request, account: Account): Promise<Response> {
// No GPU and no key of its own: with hosted runs on, the files a run on this install's GPUs may use (the policy says
- // which kinds; checked again once the file's kind is known), else nothing.
+ // which kinds), and a Kinetic Motion clip or poster; checked again once the file's type is known. Else nothing.
const own = !!accountGpu(account.id) || accountProviders(account.id).length > 0;
- const hosted = own ? null : await hostedUploads(account.id);
- if (!own && !hosted) return json(403, { error: paidAllowed() ? CONNECT_GPU_UPLOAD_MESSAGE : CONNECT_GPU_UPLOAD_OPEN_MESSAGE, code: "connect-gpu" }, { [CONNECT_GPU_HEADER]: "1" });
+ const without: Without | null = own ? null : { hosted: await hostedUploads(account.id), kinetic: request.headers.get(KINETIC_UPLOAD_HEADER) === "1" };
+ if (without && !without.hosted && !without.kinetic) return connectFirst();
+ // Only a clip or a poster then: refused before a byte is read when it says it is anything else.
+ if (without?.kinetic && !without.hosted && !isMultipart(request) && !KINETIC_TYPES.test(declaredType(request.headers.get("content-type"), displayName(request.headers.get("x-file-name"))))) return connectFirst();
if (!diskHasRoom()) return json(503, { error: ACCOUNT_MESSAGES.diskLow });
// A fair share: 60 an hour, 300 a day, 2 at once.
const hour = hit(`up:h:${account.id}`, ACCOUNT_LIMITS.uploadsPerHour, 60 * 60_000);
@@ -190,14 +210,14 @@ async function accountUpload(request: Request, account: Account): Promise<Respon
return json(429, { error: ACCOUNT_MESSAGES.uploadsBusy }, { "Retry-After": "10" });
}
try {
- return await accountUploadBody(request, account, hosted);
+ return await accountUploadBody(request, account, without);
} finally {
releaseAll();
release();
}
}
-async function accountUploadBody(request: Request, account: Account, hosted: { image: boolean; video: boolean; audio: boolean } | null): Promise<Response> {
+async function accountUploadBody(request: Request, account: Account, without: Without | null): Promise<Response> {
const lengthHeader = request.headers.get("content-length");
const length = lengthHeader === null ? NaN : Number(lengthHeader);
if (!Number.isFinite(length) || length < 0) return json(411, { error: ACCOUNT_MESSAGES.lengthNeeded });
@@ -247,9 +267,10 @@ async function accountUploadBody(request: Request, account: Account, hosted: { i
const sniffed = sniffMedia(head, declaredType(declaredFull, name));
if (!sniffed) return drop(415, ACCOUNT_MESSAGES.wrongType);
if (bytes > KIND_CAP[sniffed.kind]) return drop(413, KIND_MESSAGE[sniffed.kind]);
- if (hosted && !hosted[sniffed.kind as "image" | "video" | "audio"]) {
+ // Without a GPU or key of its own: a kind its hosted runs take, or a Kinetic Motion clip or poster.
+ if (without && !without.hosted?.[sniffed.kind] && !(without.kinetic && KINETIC_TYPES.test(sniffed.contentType))) {
fs.rmSync(dest, { force: true });
- return json(403, { error: CONNECT_GPU_UPLOAD_MESSAGE, code: "connect-gpu" }, { [CONNECT_GPU_HEADER]: "1" });
+ return connectFirst();
}
if (sniffed.kind === "image") {
const size = imageSize(head);
diff --git a/src/components/motion/save.ts b/src/components/motion/save.ts
index a97d5f51..248a40a5 100644
--- a/src/components/motion/save.ts
+++ b/src/components/motion/save.ts
@@ -4,18 +4,20 @@ import { useQueryClient } from "@tanstack/react-query";
import { useRouter } from "next/navigation";
import { useCallback, useRef, useState } from "react";
import { toast } from "sonner";
-import { uploadFile, useAskBeforeUpload, useIsAccount } from "@/lib/api";
+import { askToSignUp, uploadFile, useIsAccount, useIsGuest } from "@/lib/api";
import type { Generation } from "@/lib/catalog/types";
import { recipeKey, type Recipe } from "@/lib/motion/recipe";
import { responseError, toastError } from "@/lib/refusals";
/**
- * Everything made here goes through Fuobe: a finished render is uploaded (POST /api/uploads, the same rule as any
- * upload: the owner, or an account with its own GPU or key) and recorded as a Kinetic Motion result (POST
- * /api/generations/local), which shows in the Library (the owner's) or the account's own runs at once. The person
- * downloads it from there, never straight from the page.
+ * Everything made here goes through Fuobe: a finished render is uploaded (POST /api/uploads, marked as a Kinetic Motion
+ * result: the owner, or any account, with or without its own GPU or key, since no model makes it) and recorded as a
+ * Kinetic Motion result (POST /api/generations/local), which shows in the Library (the owner's) or the account's own
+ * runs at once. The person downloads it from there, never straight from the page.
*/
+const uploadKinetic = (file: File) => uploadFile(file, { kinetic: true });
+
export const MOTION_MODEL = "local-motion";
export interface MotionResult {
@@ -39,8 +41,8 @@ export interface SaveMeta {
export async function saveMotionResult(clip: MotionResult, meta: SaveMeta): Promise<Generation> {
const ext = clip.type === "video/webm" ? "webm" : "mp4";
const [asset, poster] = await Promise.all([
- uploadFile(new File([clip.blob], `kinetic-motion.${ext}`, { type: clip.type })),
- clip.poster ? uploadFile(new File([clip.poster], "kinetic-motion.png", { type: "image/png" })).catch(() => null) : null,
+ uploadKinetic(new File([clip.blob], `kinetic-motion.${ext}`, { type: clip.type })),
+ clip.poster ? uploadKinetic(new File([clip.poster], "kinetic-motion.png", { type: "image/png" })).catch(() => null) : null,
]);
const images = (meta.images ?? []).filter((u) => u.startsWith("/api/files/")).slice(0, 4);
const res = await fetch("/api/generations/local", {
@@ -65,13 +67,13 @@ export async function saveMotionResult(clip: MotionResult, meta: SaveMeta): Prom
export type SavePhase = { kind: "idle" } | { kind: "rendering"; done: number; total: number } | { kind: "saving" } | { kind: "saved"; id: string };
/**
- * Render-then-save for a page: asks first whoever couldn't save (a guest: "Create a free account"; an account with no
- * GPU or key: "Connect your GPU"), before anything renders. A look saves once per visit; a failed save keeps the
- * rendered clip, so Try again uploads without rendering again.
+ * Render-then-save for a page: a guest is asked to sign up ("Create a free account") before anything renders; the owner
+ * and every account save (an account needs no GPU or key of its own for this). A look saves once per visit; a failed
+ * save keeps the rendered clip, so Try again uploads without rendering again.
*/
export function useMotionSave() {
const qc = useQueryClient();
- const ask = useAskBeforeUpload();
+ const guest = useIsGuest();
const router = useRouter();
const account = useIsAccount();
const [phase, setPhase] = useState<SavePhase>({ kind: "idle" });
@@ -81,7 +83,10 @@ export function useMotionSave() {
const save = useCallback(
async (meta: SaveMeta, render: (signal: AbortSignal, progress: (done: number, total: number) => void) => Promise<MotionResult>): Promise<Generation | null> => {
- if (ask()) return null;
+ if (guest) {
+ askToSignUp("upload");
+ return null;
+ }
const key = recipeKey(meta.recipe);
if (saved.current.has(key)) {
toast(account ? "Already saved to your runs" : "Already saved to your Library", { action: { label: "Open", onClick: () => router.push("/library") } });
@@ -111,7 +116,7 @@ export function useMotionSave() {
if (abort.current === ctl) abort.current = null;
}
},
- [ask, account, qc, router],
+ [guest, account, qc, router],
);
const cancel = useCallback(() => abort.current?.abort(), []);
diff --git a/src/lib/api.ts b/src/lib/api.ts
index f928c9d5..8516a8cd 100644
--- a/src/lib/api.ts
+++ b/src/lib/api.ts
@@ -730,9 +730,12 @@ export function useShareActions() {
// ---------------------------------------------------------------------------
// Uploads & assets
-/** Upload a file as it is (streamed by the server: src/lib/upload.ts). */
-export async function uploadFile(file: File): Promise<Asset> {
- return postFile(file);
+/**
+ * Upload a file as it is (streamed by the server: src/lib/upload.ts). `kinetic`: a Kinetic Motion clip or poster
+ * rendered in the page, which any account may save (KINETIC_UPLOAD_HEADER).
+ */
+export async function uploadFile(file: File, opts: { kinetic?: boolean } = {}): Promise<Asset> {
+ return postFile(file, undefined, opts);
}
/** A stored file's uses: where it's used, in one line ("2 results and the element “Maya”"), empty when nothing uses it. */
diff --git a/src/lib/guest-access.ts b/src/lib/guest-access.ts
index ca592986..5f779add 100644
--- a/src/lib/guest-access.ts
+++ b/src/lib/guest-access.ts
@@ -211,7 +211,8 @@ export function accountMayChange(method: string, pathname: string, search: strin
// Like, pin or review many of its own runs at once (the route checks each is its own, and refuses the rest).
if (method === "POST" && pathname === "/api/generations/bulk") return true;
// A Kinetic Motion clip it rendered in its browser and uploaded, recorded as its own run (the route checks the files
- // are its own, its run rate and the studio's checks; a grade or a Relight blend stays the owner's there).
+ // are its own, its run rate and the studio's checks; a grade or a Relight blend stays the owner's there). No model
+ // runs, so it needs no GPU or key of its own.
if (method === "POST" && pathname === "/api/generations/local") return true;
return isPriceCheck(method, pathname, search);
}
@@ -283,6 +284,12 @@ export const CONNECT_GPU_MESSAGE = "Connect your GPU to run this. It's free.";
export const CONNECT_GPU_UPLOAD_MESSAGE = "Connect your GPU, or add a fal.ai or Replicate key, to add your own files.";
/** The same, on a studio with paid models off (no keys). */
export const CONNECT_GPU_UPLOAD_OPEN_MESSAGE = "Connect your GPU to add your own files.";
+/**
+ * Sent with the upload of a Kinetic Motion clip (or its poster) rendered in the browser, set to "1". Saving one needs no
+ * model, so an account with neither its own GPU nor its own key may upload it too: an MP4 or WebM clip, or a PNG
+ * poster, within the account's space and upload limits (src/app/api/uploads).
+ */
+export const KINETIC_UPLOAD_HEADER = "x-fuobe-kinetic";
/** An account with neither its own GPU nor its own key (the proxy's answer to a run): the card it opens offers both. */
export const CONNECT_GPU_OR_KEY_MESSAGE = CONNECT_GPU_MESSAGE;
diff --git a/src/lib/upload.ts b/src/lib/upload.ts
index 38545b03..977171ad 100644
--- a/src/lib/upload.ts
+++ b/src/lib/upload.ts
@@ -1,4 +1,5 @@
import type { Asset } from "@/lib/api";
+import { KINETIC_UPLOAD_HEADER } from "@/lib/guest-access";
import { responseError } from "@/lib/refusals";
/**
@@ -6,12 +7,13 @@ import { responseError } from "@/lib/refusals";
* instead of reading a whole form into memory. Throws with the server's own message ("That clip is over 95 MB…"),
* marked when the refusal shows its own card (src/lib/refusals.ts).
*/
-export async function postFile(file: File, signal?: AbortSignal): Promise<Asset> {
+export async function postFile(file: File, signal?: AbortSignal, opts: { kinetic?: boolean } = {}): Promise<Asset> {
const res = await fetch("/api/uploads", {
method: "POST",
body: file,
signal,
- headers: { "Content-Type": file.type || "application/octet-stream", "X-File-Name": encodeURIComponent(file.name) },
+ // A Kinetic Motion clip or poster rendered in the page: any account may save one (KINETIC_UPLOAD_HEADER).
+ headers: { "Content-Type": file.type || "application/octet-stream", "X-File-Name": encodeURIComponent(file.name), ...(opts.kinetic && { [KINETIC_UPLOAD_HEADER]: "1" }) },
});
const body = (await res.json().catch(() => ({}))) as Asset & { error?: string };
if (!res.ok) throw responseError(res, body.error ?? "That upload didn't go through. Please try again.");
diff --git a/tests/e2e/kinetic-endcard.mjs b/tests/e2e/kinetic-endcard.mjs
index 73f00fb8..b081642c 100644
--- a/tests/e2e/kinetic-endcard.mjs
+++ b/tests/e2e/kinetic-endcard.mjs
@@ -10,8 +10,8 @@
// Checks. Owner: the preview animates (pixels differ between 0.2 s and 1.0 s, equal at 2.0 s and 2.4 s); Iris renders
// to an MP4 whose frame count is round(seconds × fps); Generate sends the clip and the run joins it after the ad; "Save
// the end card" makes a Library result whose file is the uploaded clip. Account with a stand-in key: uploads its clip,
-// records it, sees it in its own runs and downloads it; the owner's Library doesn't list it. Account with neither: the
-// upload is refused (connect-gpu). Guest: the page's note, and the record route answers 401. Reduced motion: the rest
+// records it, sees it in its own runs and downloads it; the owner's Library doesn't list it. Account with neither: an
+// unmarked upload is refused (connect-gpu), a Kinetic clip uploads and records to its own runs. Guest: the page's note, and the record route answers 401. Reduced motion: the rest
// frame and no autoplay. Phone 390 × 844: no sideways scroll, 44 px chips and scrub bar. Frame times on desktop and on
// a 4× throttled phone. Evidence: MP4s of the five styles, contact sheets, screenshots, timings.
import { spawn, execSync } from "node:child_process";
@@ -76,8 +76,8 @@ async function stopAll() {
await fal.close();
}
-const api = async (route, { method = "GET", body, cookie, raw, type } = {}) => {
- const headers = { Origin: APP, ...(cookie && { cookie }) };
+const api = async (route, { method = "GET", body, cookie, raw, type, kinetic } = {}) => {
+ const headers = { Origin: APP, ...(cookie && { cookie }), ...(kinetic && { "x-fuobe-kinetic": "1" }) };
if (raw) Object.assign(headers, { "Content-Type": type, "X-File-Name": encodeURIComponent(`file.${type.split("/")[1]}`) });
else headers["Content-Type"] = "application/json";
const res = await fetch(APP + route, { method, headers, ...(raw ? { body: raw } : body !== undefined && { body: JSON.stringify(body) }) });
@@ -313,10 +313,17 @@ try {
const stolen = await api("/api/generations/local", { method: "POST", cookie: acct, body: { feature: "kinetic-end-card", modelId: "local-motion", op: "motion", prompt: "x", inputs: {}, params: { extra: { motion: recipe } }, output: { url: sent.endCard.clip, kind: "video", contentType: "video/mp4" } } });
check(stolen.status === 403, `the account can't record the owner's clip (${stolen.status})`);
- // ---- An account with neither a GPU nor a key: the upload asks it to connect one.
+ // ---- An account with neither a GPU nor a key: its own files ask it to connect one, but a Kinetic Motion clip (no
+ // model makes it) saves to its own runs.
const bare = cookieOf(await api("/api/auth/signup", { method: "POST", body: { email: "[email protected]", password: "account password" } }));
- const refused = await api("/api/uploads", { method: "POST", cookie: bare, raw: mine, type: "video/mp4" });
- check(refused.status === 403 && refused.json?.code === "connect-gpu", `an account with no GPU or key can't upload (${refused.status} ${refused.json?.code})`);
+ const bareUp = await api("/api/uploads", { method: "POST", cookie: bare, raw: mine, type: "video/mp4", kinetic: true });
+ check(bareUp.status === 201, `an account with no GPU or key uploads its Kinetic clip (${bareUp.status})`);
+ const bareRec = await api("/api/generations/local", { method: "POST", cookie: bare, body: { feature: "kinetic-end-card", modelId: "local-motion", op: "motion", prompt: "Sora Skin · Daily Veil SPF 50", title: "Sora Skin end card", inputs: {}, params: { extra: { motion: recipe } }, output: { url: bareUp.json?.url, kind: "video", contentType: "video/mp4" } } });
+ check(bareRec.status === 201 && bareRec.json?.status === "succeeded", `an account with no GPU or key records its clip (${bareRec.status})`);
+ check(((await api("/api/generations?limit=50", { cookie: bare })).json?.items ?? []).some((g) => g.id === bareRec.json?.id), "it shows in that account's own runs");
+ // (Refused before the body is read: a small one, so the connection stays usable.)
+ const refused = await api("/api/uploads", { method: "POST", cookie: bare, raw: mine.subarray(0, 4096), type: "video/mp4" });
+ check(refused.status === 403 && refused.json?.code === "connect-gpu", `an account with no GPU or key can't upload its own files (${refused.status} ${refused.json?.code})`);
// ---- Guest (phone and desktop): the page's note, the end card previews live on a sample kit with their words, and
// saving it opens the sign-up card. The record route asks to sign up.
diff --git a/tests/e2e/kinetic-templates.mjs b/tests/e2e/kinetic-templates.mjs
index 4850c1da..c7e5b83f 100644
--- a/tests/e2e/kinetic-templates.mjs
+++ b/tests/e2e/kinetic-templates.mjs
@@ -11,7 +11,8 @@
// it shows under "Made with this template", opens in the viewer and downloads as the stored MP4 (1080 × 1920, 150
// frames). Account with a stand-in key: Logo Sting with its own logo from the Brand row, saved to its own runs, listed
// in its strip and downloaded; the owner's Library doesn't list it, the owner's Accounts' runs does. Account with
-// neither: Save opens the Connect card and nothing is uploaded. Guest: the fields and preview work, Save opens the
+// neither: Save to your runs saves the clip at 1440 and 390 with no Connect card, and its own picture upload is still
+// refused. Guest: the fields and preview work, Save opens the
// sign-up card before anything renders, a code template shows no "not available" note while an AI template still does.
// Covers: the ten code templates' tiles show their versioned cover and clip. Phone 390 and desktop 1440 for each
// viewer: no sideways scroll, controls at least 44 px. Evidence: screenshots, the saved clips, timings.
@@ -257,18 +258,32 @@ try {
await ctx.close();
}
- // ---- An account with neither a GPU nor a key: Save asks it to connect one, before anything renders.
+ // ---- An account with neither a GPU nor a key: no model makes a Kinetic clip, so it saves to its own runs too (phone
+ // and desktop), and no Connect card opens.
const bare = cookieOf(await api("/api/auth/signup", { method: "POST", body: { email: "[email protected]", password: "account password" } }));
- const bctx = await withCookie(bare, DESKTOP);
- const bp = await bctx.newPage();
- let bareUploads = 0;
- bp.on("request", (r) => r.url().endsWith("/api/uploads") && bareUploads++);
- await openTemplate(bp, "ms-big-number");
- await bp.getByRole("button", { name: "Save to your runs" }).click();
- check(await bp.getByText(/Connect your GPU/).first().waitFor({ timeout: 10_000 }).then(() => true, () => false), "account without a GPU or key: Save opens the Connect card");
- check(!(await bp.getByText(/^Rendering \d+ of/).isVisible().catch(() => false)) && bareUploads === 0, `account without a GPU or key: nothing renders or uploads (${bareUploads} uploads)`);
- await bp.screenshot({ path: path.join(out, "account-bare-save.png") });
- await bctx.close();
+ for (const [name, vp] of [["1440", DESKTOP], ["390", { ...PHONE, deviceScaleFactor: 3 }]]) {
+ const bctx = await withCookie(bare, vp);
+ const bp = await bctx.newPage();
+ await openTemplate(bp, "ms-big-number");
+ await layoutChecks(bp, "account without a GPU or key", name);
+ if (name === "390") await bp.getByRole("textbox", { name: "The number", exact: true }).fill("4,210");
+ const rec = bp.waitForResponse((r) => r.url().endsWith("/api/generations/local") && r.request().method() === "POST", { timeout: 180_000 });
+ await bp.getByRole("button", { name: "Save to your runs" }).click();
+ check((await rec).status() === 201, `account without a GPU or key ${name}: its clip is recorded`);
+ check(await bp.getByText("Saved to your runs").first().waitFor({ timeout: 30_000 }).then(() => true, () => false), `account without a GPU or key ${name}: the toast says it's in its runs`);
+ check(!(await bp.getByText(/Connect your GPU/).first().isVisible().catch(() => false)), `account without a GPU or key ${name}: no Connect card`);
+ await bp.screenshot({ path: path.join(out, `account-bare-save-${name}.png`) });
+ await bctx.close();
+ }
+ const bareRuns = (await api("/api/generations?features=marketing-kinetic&limit=20", { cookie: bare })).json?.items ?? [];
+ check(bareRuns.length === 2 && bareRuns.every((x) => x.modelId === "local-motion" && x.status === "succeeded"), `account without a GPU or key: both clips are in its own runs (${bareRuns.length})`);
+ const bareFile = bareRuns[0] ? await api(bareRuns[0].outputs[0].url, { cookie: bare }) : null;
+ check(bareFile?.status === 200 && mp4Frames(bareFile.buf) > 0, "account without a GPU or key: it downloads its clip from Fuobe");
+ const ownerSees = (await api("/api/generations?limit=200", { cookie: owner })).json?.items ?? [];
+ check(!ownerSees.some((x) => bareRuns.some((b) => b.id === x.id)), "the owner's Library doesn't list them");
+ // Its own files still ask it to connect one: an upload without the Kinetic mark.
+ const plain = await fetch(APP + "/api/uploads", { method: "POST", headers: { Origin: APP, cookie: bare, "Content-Type": "image/png", "X-File-Name": "logo.png" }, body: logo });
+ check(plain.status === 403 && (await plain.json()).code === "connect-gpu", `account without a GPU or key: its own picture still asks to connect a GPU (${plain.status})`);
// ---- Guest: fields and preview work, Save asks to sign up first, AI templates keep their note.
for (const [name, vp] of [["390", { ...PHONE, deviceScaleFactor: 3 }], ["1440", DESKTOP]]) {
diff --git a/tests/kinetic-account-save.test.ts b/tests/kinetic-account-save.test.ts
new file mode 100644
index 00000000..bf2f2f7b
--- /dev/null
+++ b/tests/kinetic-account-save.test.ts
@@ -0,0 +1,183 @@
+import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";
+import { TINY_PNG } from "./helpers/fake-comfy-runner";
+import { tempDir } from "./helpers/temp-dir";
+
+// Saving a Kinetic Motion result needs no model: the owner and every account (with or without its own GPU or key)
+// upload the clip and its poster (sent with KINETIC_UPLOAD_HEADER) and record it (POST /api/generations/local), within
+// the account's space and limits; a guest is asked to sign up. Anything else an account without a GPU or key uploads
+// still answers "Connect your GPU", and the header lets through only a clip (MP4, WebM) or a PNG poster.
+
+const dir = tempDir("fuobe-kinetic-save-");
+process.env.FUOBE_DATA_DIR = dir;
+process.env.FUOBE_PUBLIC_SIGNUP = "1";
+delete process.env.FUOBE_PASSWORD;
+delete process.env.FUOBE_ALLOWED_ORIGINS;
+delete process.env.FUOBE_MODERATION_URL;
+globalThis.__fuobeTestDiskFree = 1e13;
+
+const auth = await import("@/server/auth");
+const keys = await import("@/server/account-keys");
+const uploads = await import("@/app/api/uploads/route");
+const local = await import("@/app/api/generations/local/route");
+const { CONNECT_GPU_HEADER, GUEST_HEADER, KINETIC_UPLOAD_HEADER } = await import("@/lib/guest-access");
+const { accountUsage, ACCOUNT_LIMITS } = await import("@/server/account-files");
+const { generationAccount, fileAccount } = await import("@/server/account-library");
+const { filesRel } = await import("@/server/storage");
+const { hit, resetRates } = await import("@/server/rate");
+const { recipe } = await import("./helpers/motion");
+afterAll(() => {
+ globalThis.__fuobeTestDiskFree = undefined;
+});
+
+const MP4 = Buffer.concat([Buffer.from([0, 0, 0, 0x18]), Buffer.from("ftypisom"), Buffer.alloc(400, 1)]);
+// A WebM header: EBML, then its DocType "webm".
+const WEBM = Buffer.concat([Buffer.from([0x1a, 0x45, 0xdf, 0xa3, 0x9f, 0x42, 0x86, 0x81, 0x01, 0x42, 0x82, 0x84]), Buffer.from("webm"), Buffer.alloc(400, 0)]);
+const JPEG = Buffer.concat([Buffer.from([0xff, 0xd8, 0xff, 0xe0]), Buffer.alloc(400, 2)]);
+
+let owner = "";
+let withKey = { id: "", cookie: "" };
+let withGpu = { id: "", cookie: "" };
+let bare = { id: "", cookie: "" };
+let n = 0;
+const newAccount = () => {
+ const a = auth.createAccount(`kinetic-save-${n++}@example.com`, "long enough");
+ return { id: a.id, cookie: auth.createSession(a.id).value };
+};
+beforeAll(() => {
+ auth.setPassword("install password");
+ owner = auth.createSession().value;
+ withKey = newAccount();
+ keys.saveAccountKey(withKey.id, "fal", "acct-fal-kinetic");
+ withGpu = newAccount();
+ auth.setAccountGpu(withGpu.id, { url: "https://gpu-kinetic.example" });
+ bare = newAccount();
+});
+beforeEach(() => resetRates());
+
+const cookieHeader = (cookie?: string): Record<string, string> => (cookie ? { cookie: `${auth.SESSION_COOKIE}=${cookie}` } : {});
+
+function upload(bytes: Buffer, type: string, name: string, o: { cookie?: string; kinetic?: boolean } = {}) {
+ const headers: Record<string, string> = { host: "localhost:3000", "content-type": type, "x-file-name": encodeURIComponent(name), "content-length": String(bytes.length), ...cookieHeader(o.cookie), ...(o.kinetic && { [KINETIC_UPLOAD_HEADER]: "1" }) };
+ return uploads.POST(new Request("http://localhost:3000/api/uploads", { method: "POST", headers, body: new Uint8Array(bytes), duplex: "half" } as RequestInit));
+}
+
+const record = (output: string, poster: string | undefined, cookie?: string) =>
+ local.POST(
+ new Request("http://localhost:3000/api/generations/local", {
+ method: "POST",
+ headers: { "content-type": "application/json", host: "localhost:3000", ...cookieHeader(cookie) },
+ body: JSON.stringify({
+ feature: "marketing-kinetic",
+ modelId: "local-motion",
+ op: "motion",
+ prompt: "Close the month before lunch.",
+ title: "Kinetic Headline",
+ inputs: {},
+ params: { extra: { motion: recipe("end-card/draw-on") } },
+ output: { url: output, kind: "video", contentType: "video/mp4", ...(poster && { meta: { poster } }) },
+ }),
+ }),
+ );
+
+/** Upload the clip and its poster as the Kinetic save does, then record it. */
+async function save(cookie?: string) {
+ const clip = await upload(MP4, "video/mp4", "kinetic-motion.mp4", { cookie, kinetic: true });
+ const poster = await upload(TINY_PNG, "image/png", "kinetic-motion.png", { cookie, kinetic: true });
+ const clipBody = clip.status === 201 ? ((await clip.json()) as { url: string }) : null;
+ const posterBody = poster.status === 201 ? ((await poster.json()) as { url: string }) : null;
+ const rec = clipBody ? await record(clipBody.url, posterBody?.url, cookie) : null;
+ return { clip, poster, clipUrl: clipBody?.url, posterUrl: posterBody?.url, rec };
+}
+
+describe("saving a Kinetic Motion result", () => {
+ it("the owner saves it to the Library", async () => {
+ const s = await save(owner);
+ expect(s.clip.status).toBe(201);
+ expect(s.poster.status).toBe(201);
+ expect(s.rec?.status).toBe(201);
+ const g = (await s.rec!.json()) as { id: string };
+ expect(generationAccount(g.id)).toBeNull();
+ });
+
+ it("an account with its own key saves it to its own runs", async () => {
+ const s = await save(withKey.cookie);
+ expect(s.rec?.status).toBe(201);
+ const g = (await s.rec!.json()) as { id: string };
+ expect(generationAccount(g.id)).toBe(withKey.id);
+ expect(fileAccount(filesRel(s.clipUrl!)!)).toBe(withKey.id);
+ });
+
+ it("an account with neither a GPU nor a key saves it too, as its own run and files, counted in its space", async () => {
+ const before = accountUsage(bare.id).uploads;
+ const s = await save(bare.cookie);
+ expect(s.clip.status).toBe(201);
+ expect(s.poster.status).toBe(201);
+ expect(s.rec?.status).toBe(201);
+ const g = (await s.rec!.json()) as { id: string };
+ expect(generationAccount(g.id)).toBe(bare.id);
+ expect(fileAccount(filesRel(s.clipUrl!)!)).toBe(bare.id);
+ expect(fileAccount(filesRel(s.posterUrl!)!)).toBe(bare.id);
+ expect(accountUsage(bare.id).uploads).toBe(before + MP4.length + TINY_PNG.length);
+ // A WebM clip too.
+ expect((await upload(WEBM, "video/webm", "kinetic-motion.webm", { cookie: bare.cookie, kinetic: true })).status).toBe(201);
+ });
+
+ it("a guest is asked to sign up, for the upload and the record", async () => {
+ const s = await save(undefined);
+ expect(s.clip.status).toBe(401);
+ expect(s.clip.headers.get(GUEST_HEADER)).toBe("1");
+ const r = await record("/api/files/uploads/x.mp4", undefined, undefined);
+ expect(r.status).toBe(401);
+ });
+});
+
+describe("an account with neither a GPU nor a key", () => {
+ it("still can't add its own files: an upload without the Kinetic mark says Connect your GPU", async () => {
+ for (const [bytes, type, name] of [
+ [MP4, "video/mp4", "clip.mp4"],
+ [TINY_PNG, "image/png", "p.png"],
+ ] as const) {
+ const r = await upload(bytes, type, name, { cookie: bare.cookie });
+ expect(r.status).toBe(403);
+ expect(r.headers.get(CONNECT_GPU_HEADER)).toBe("1");
+ expect((await r.json()).code).toBe("connect-gpu");
+ }
+ });
+
+ it("with the mark, only a clip or a PNG poster: anything else is refused, before reading when it says so", async () => {
+ const said = await upload(JPEG, "image/jpeg", "p.jpg", { cookie: bare.cookie, kinetic: true });
+ expect(said.status).toBe(403);
+ expect((await said.json()).code).toBe("connect-gpu");
+ // A picture that says it is a clip: its bytes decide.
+ const lied = await upload(JPEG, "video/mp4", "k.mp4", { cookie: bare.cookie, kinetic: true });
+ expect(lied.status).toBe(403);
+ expect((await lied.json()).code).toBe("connect-gpu");
+ const sound = await upload(MP4, "audio/mp4", "k.m4a", { cookie: bare.cookie, kinetic: true });
+ expect(sound.status).toBe(403);
+ });
+
+ it("is held to the upload limits: 60 an hour", async () => {
+ for (let i = 0; i < ACCOUNT_LIMITS.uploadsPerHour; i++) hit(`up:h:${bare.id}`, ACCOUNT_LIMITS.uploadsPerHour, 60 * 60_000);
+ const r = await upload(MP4, "video/mp4", "kinetic-motion.mp4", { cookie: bare.cookie, kinetic: true });
+ expect(r.status).toBe(429);
+ });
+
+ it("is held to its run rate when it records: 60 an hour", async () => {
+ const clip = (await (await upload(MP4, "video/mp4", "kinetic-motion.mp4", { cookie: bare.cookie, kinetic: true })).json()) as { url: string };
+ for (let i = 0; i < ACCOUNT_LIMITS.runsPerHour; i++) hit(`run:${bare.id}`, ACCOUNT_LIMITS.runsPerHour, 60 * 60_000);
+ expect((await record(clip.url, undefined, bare.cookie)).status).toBe(429);
+ });
+
+ it("can't record another account's clip", async () => {
+ const theirs = (await (await upload(MP4, "video/mp4", "kinetic-motion.mp4", { cookie: withKey.cookie, kinetic: true })).json()) as { url: string };
+ expect((await record(theirs.url, undefined, bare.cookie)).status).toBe(403);
+ });
+});
+
+describe("an account with its own GPU", () => {
+ it("uploads as before, marked or not", async () => {
+ expect((await upload(MP4, "video/mp4", "clip.mp4", { cookie: withGpu.cookie })).status).toBe(201);
+ expect((await upload(TINY_PNG, "image/png", "p.png", { cookie: withGpu.cookie })).status).toBe(201);
+ expect((await upload(TINY_PNG, "image/png", "p.png", { cookie: withGpu.cookie, kinetic: true })).status).toBe(201);
+ });
+});
diff --git a/tests/motion-no-direct-download.test.ts b/tests/motion-no-direct-download.test.ts
index 1c648b6c..84324df4 100644
--- a/tests/motion-no-direct-download.test.ts
+++ b/tests/motion-no-direct-download.test.ts
@@ -28,6 +28,8 @@ describe("no direct download of a motion render", () => {
it("saves through an upload and a recorded result", () => {
const save = fs.readFileSync(path.join(ROOT, "src/components/motion/save.ts"), "utf8");
expect(save).toContain("uploadFile(");
+ // Marked as a Kinetic Motion result: any account may save one, with or without its own GPU or key.
+ expect(save).toContain("{ kinetic: true }");
expect(save).toContain('"/api/generations/local"');
expect(save).toContain('op: "motion"');
});