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.

Upload boxes say the clip size the viewer can upload

Adarshebc2a2a1b8b9
diff --git a/src/components/genjutsu/character-panel.tsx b/src/components/genjutsu/character-panel.tsx
index 81901512..d7fefb10 100644
--- a/src/components/genjutsu/character-panel.tsx
+++ b/src/components/genjutsu/character-panel.tsx
@@ -33,6 +33,7 @@ import {
import type { GenjutsuTarget, Maker } from "@/lib/catalog/genjutsu";
import { cloudSharpenUsd, OPEN_TIER_OFF, SHARPEN_COPY, type SharpenTier } from "@/lib/catalog/sharpen";
import type { Engine } from "@/lib/catalog/types";
+import { limitMb, useClipLimit } from "@/lib/clip-limit";
/** The Quality field's short hint: H3's own sizes in words, a finishing size's price (cloud) or "Free · your GPU". */
export function qualityShort(engine: Engine, q: CharacterChoice): string {
@@ -356,6 +357,8 @@ export function CharacterFacts({
/** Why the studio can't be opened with the clip yet (it is still uploading). */
waiting?: string | null;
}) {
+ // The clip size this viewer may upload (an account's is smaller than the studio's own).
+ const clipMax = useClipLimit(CHARACTER_SWAP.maxBytes);
return (
<div className="space-y-2 text-[12px] leading-snug text-muted-foreground">
{cut && (
@@ -368,7 +371,7 @@ export function CharacterFacts({
{CHARACTER_LIMITS.map((l) => (
<li key={l}>{l}</li>
))}
- <li>Clips up to {CHARACTER_SWAP.maxBytes / 1024 / 1024} MB</li>
+ <li>Clips up to {limitMb(clipMax)} MB</li>
</ul>
{engine === "open" && maker?.h3 && (
<p className="flex gap-1.5">
diff --git a/src/components/genjutsu/genjutsu-studio.tsx b/src/components/genjutsu/genjutsu-studio.tsx
index ad462a97..bfb2f279 100644
--- a/src/components/genjutsu/genjutsu-studio.tsx
+++ b/src/components/genjutsu/genjutsu-studio.tsx
@@ -25,6 +25,7 @@ import { radioKeys, radioTab } from "@/components/studio/radio-keys";
import { SketchEditor, type Stroke } from "@/components/studio/sketch-editor";
import { VideoTrimmer, type TrimRange, type VideoTrimmerHandle } from "@/components/studio/video-trimmer";
import { openInStudio } from "@/components/swap-studio/hooks";
+import { limitMb, useClipLimit } from "@/lib/clip-limit";
import { ExampleRow } from "@/components/studio/example-row";
import { onAttr, TAB_PILL, TabRow } from "@/components/ui/tab-row";
import { useEngine, useGenerations, useIsOwner, useModelAccess, useSoundLive, useStatus } from "@/lib/api";
@@ -84,9 +85,9 @@ import { ModeExample, ModeExampleRow } from "./mode-example";
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog";
import { exampleFor, MARKED_NOTE, OWN_CHARACTER_FIELDS, partLimits, sameRecipe, toRecipe, type GenjutsuExampleCard, type ModeExamples } from "@/lib/examples/genjutsu";
-/** The upload box's line: the mode's own window (Character swap: 5–15 s of one shot). */
-const limits = (mode: GenjutsuMode) =>
- `MP4, MOV or WebM · ${mode === "character" ? `${CHARACTER_SWAP.minSeconds}–${CHARACTER_SWAP.maxSeconds}` : mode === "picture" ? "2–15" : mode === "finish" ? "up to 60" : `${GENJUTSU.minSeconds}–${GENJUTSU.maxSeconds}`} s are used · ${GENJUTSU.maxBytes / 1024 / 1024} MB`;
+/** The upload box's line: the mode's own window (Character swap: 5–15 s of one shot), and the clip size the viewer may upload. */
+const limits = (mode: GenjutsuMode, maxBytes: number) =>
+ `MP4, MOV or WebM · ${mode === "character" ? `${CHARACTER_SWAP.minSeconds}–${CHARACTER_SWAP.maxSeconds}` : mode === "picture" ? "2–15" : mode === "finish" ? "up to 60" : `${GENJUTSU.minSeconds}–${GENJUTSU.maxSeconds}`} s are used · ${limitMb(maxBytes)} MB`;
interface Paint {
mask: string;
@@ -141,7 +142,9 @@ export function GenjutsuStudio({ examples, modeExamples, live }: { examples?: Ex
const shownExamples = owner && ownerExamples.data ? ownerExamples.data : modeExamples;
const access = useModelAccess();
const [mode, setModeState] = useState<GenjutsuMode>("motion");
- const source = useSourceClip(GENJUTSU.maxBytes);
+ // The clip size this viewer may upload: an account's is smaller than the studio's own (src/lib/clip-limit.ts).
+ const clipMax = useClipLimit(GENJUTSU.maxBytes);
+ const source = useSourceClip(clipMax);
const clip = source.clip;
const trimmer = useRef<VideoTrimmerHandle>(null);
const [range, setRange] = useState<TrimRange | null>(null);
@@ -836,7 +839,7 @@ export function GenjutsuStudio({ examples, modeExamples, live }: { examples?: Ex
{!clip ? (
<ClipDrop
accept={GENJUTSU.accept}
- limits={limits(mode)}
+ limits={limits(mode, clipMax)}
onFile={(f) => {
const err = source.pick(f);
if (err) toast.error(err);
diff --git a/src/components/shorts/use-source-clip.ts b/src/components/shorts/use-source-clip.ts
index 4d18f875..8c822f94 100644
--- a/src/components/shorts/use-source-clip.ts
+++ b/src/components/shorts/use-source-clip.ts
@@ -1,6 +1,7 @@
"use client";
import { useCallback, useEffect, useRef, useState } from "react";
+import { postFileWithProgress } from "@/lib/upload";
/**
* The clip a studio works on: shown at once from the file (object URL), uploaded in the background
@@ -43,25 +44,8 @@ export function checkClipFile(file: File, maxBytes: number): string | null {
return null;
}
-function upload(file: File, onProgress: (p: number) => void, signal: AbortSignal): Promise<{ url: string; name?: string }> {
- return new Promise((resolve, reject) => {
- const xhr = new XMLHttpRequest();
- xhr.open("POST", "/api/uploads");
- xhr.responseType = "json";
- xhr.upload.onprogress = (e) => e.lengthComputable && onProgress(e.loaded / e.total);
- xhr.onload = () => {
- const body = xhr.response as { url?: string; name?: string; error?: string } | null;
- if (xhr.status >= 200 && xhr.status < 300 && body?.url) resolve({ url: body.url, name: body.name });
- else reject(new Error(body?.error ?? "That upload didn't go through. Please try again."));
- };
- xhr.onerror = () => reject(new Error("Upload failed — check your connection"));
- xhr.onabort = () => reject(new DOMException("Aborted", "AbortError"));
- signal.addEventListener("abort", () => xhr.abort());
- const form = new FormData();
- form.append("file", file);
- xhr.send(form);
- });
-}
+/** The file as the body (streamed to disk): an account's clip up to its limit, not only a small form. */
+const upload = (file: File, onProgress: (p: number) => void, signal: AbortSignal) => postFileWithProgress(file, onProgress, signal);
async function probe(url: string): Promise<SourceInfo> {
const res = await fetch("/api/shorts/probe", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ url }) });
diff --git a/src/lib/clip-limit.ts b/src/lib/clip-limit.ts
new file mode 100644
index 00000000..38756681
--- /dev/null
+++ b/src/lib/clip-limit.ts
@@ -0,0 +1,19 @@
+import { useIsOwner } from "@/lib/api";
+
+/**
+ * The largest clip a signed-in account uploads (src/server/account-files.ts ACCOUNT_LIMITS.videoBytes: under ComfyUI's
+ * default and a free tunnel's 100 MB).
+ */
+export const ACCOUNT_CLIP_BYTES = 95 * 1024 * 1024;
+
+/**
+ * The largest clip an upload box takes from whoever is looking: the tool's own limit for the studio's owner, an
+ * account's for anyone else (a guest uploads once signed up, as an account). What the box says and checks before a byte
+ * is sent, so a clip the upload would refuse is never sent.
+ */
+export function useClipLimit(toolMax: number): number {
+ return useIsOwner() ? toolMax : Math.min(toolMax, ACCOUNT_CLIP_BYTES);
+}
+
+/** A limit in whole MB, as the boxes say it. */
+export const limitMb = (bytes: number) => Math.round(bytes / 1024 / 1024);
diff --git a/src/lib/upload.ts b/src/lib/upload.ts
index 977171ad..2fa043ab 100644
--- a/src/lib/upload.ts
+++ b/src/lib/upload.ts
@@ -19,3 +19,28 @@ export async function postFile(file: File, signal?: AbortSignal, opts: { kinetic
if (!res.ok) throw responseError(res, body.error ?? "That upload didn't go through. Please try again.");
return body;
}
+
+/**
+ * postFile with its progress (fetch can't report an upload's): the file as the body, its type and name in headers, so a
+ * clip up to the viewer's limit is streamed to disk (a form is only taken from an account while small). Aborts with
+ * `signal` (an AbortError).
+ */
+export function postFileWithProgress(file: File, onProgress: (p: number) => void, signal?: AbortSignal): Promise<{ url: string; name?: string }> {
+ return new Promise((resolve, reject) => {
+ const xhr = new XMLHttpRequest();
+ xhr.open("POST", "/api/uploads");
+ xhr.responseType = "json";
+ xhr.setRequestHeader("Content-Type", file.type || "application/octet-stream");
+ xhr.setRequestHeader("X-File-Name", encodeURIComponent(file.name));
+ xhr.upload.onprogress = (e) => e.lengthComputable && onProgress(e.loaded / e.total);
+ xhr.onload = () => {
+ const body = xhr.response as { url?: string; name?: string; error?: string } | null;
+ if (xhr.status >= 200 && xhr.status < 300 && body?.url) resolve({ url: body.url, name: body.name });
+ else reject(new Error(body?.error ?? "That upload didn't go through. Please try again."));
+ };
+ xhr.onerror = () => reject(new Error("Upload failed — check your connection"));
+ xhr.onabort = () => reject(new DOMException("Aborted", "AbortError"));
+ signal?.addEventListener("abort", () => xhr.abort());
+ xhr.send(file);
+ });
+}