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.

Uploads: Voice Record, the audio tools and the drop zones ask first too

Adarsh7c79017bff7c
diff --git a/src/components/ads/multiplier.tsx b/src/components/ads/multiplier.tsx
index 83282a42..4de8bc25 100644
--- a/src/components/ads/multiplier.tsx
+++ b/src/components/ads/multiplier.tsx
@@ -15,7 +15,7 @@ import { VideoTrimmer } from "@/components/studio/video-trimmer";
import { initialClip, mentionedImages, MULTIPLIER, MULTIPLIER_MODELS, multiplierResolution, type ClipRange as Range, type MarketingRun, type RunEstimate } from "@/lib/catalog/marketing";
import { formatCost } from "@/lib/format";
import { probeBlob, probeUrl } from "@/lib/media-probe";
-import { useModelAccess } from "@/lib/api";
+import { useAskBeforeUpload, useModelAccess } from "@/lib/api";
import { keepOffered, offered } from "@/lib/model-access";
import { cn } from "@/lib/utils";
import { toastError } from "@/lib/refusals";
@@ -42,6 +42,8 @@ function ReferenceDrop({ onFile, onPick }: { onFile: (f: File) => void; onPick:
const input = useRef<HTMLInputElement>(null);
const [over, setOver] = useState(false);
const [lib, setLib] = useState(false);
+ // A guest, or an account with neither its own GPU nor its own key, gets its card instead of the file chooser.
+ const askFirst = useAskBeforeUpload();
return (
<div
onDragOver={(e) => (e.preventDefault(), setOver(true))}
@@ -50,7 +52,7 @@ function ReferenceDrop({ onFile, onPick }: { onFile: (f: File) => void; onPick:
e.preventDefault();
setOver(false);
const f = e.dataTransfer.files[0];
- if (f) onFile(f);
+ if (f && !askFirst()) onFile(f);
}}
className={cn("flex aspect-[4/3] flex-col items-center justify-center rounded-2xl border-2 border-dashed border-border-strong p-6 text-center transition-colors sm:aspect-video", over && "border-primary bg-brand-faint")}
>
@@ -60,7 +62,7 @@ function ReferenceDrop({ onFile, onPick }: { onFile: (f: File) => void; onPick:
MP4, MOV or WebM · {MULTIPLIER.minSeconds}–{MULTIPLIER.maxSeconds} seconds (trim a longer one here)
</p>
<div className="mt-4 flex flex-wrap justify-center gap-2">
- <Button onClick={() => input.current?.click()}>
+ <Button onClick={() => askFirst() || input.current?.click()}>
<Upload /> Upload video
</Button>
<Popover open={lib} onOpenChange={setLib}>
@@ -95,7 +97,10 @@ function MentionImages({ value, onChange, onMention, max }: { value: string[]; o
const input = useRef<HTMLInputElement>(null);
const [busy, setBusy] = useState(0);
const [lib, setLib] = useState(false);
+ // A guest, or an account with neither its own GPU nor its own key, gets its card instead of the file chooser.
+ const askFirst = useAskBeforeUpload();
const add = async (files: File[]) => {
+ if (!files.length || askFirst()) return;
const room = max - value.length;
if (room <= 0) return void toast(`Up to ${max} images`);
setBusy(Math.min(room, files.length));
@@ -131,7 +136,7 @@ function MentionImages({ value, onChange, onMention, max }: { value: string[]; o
))}
{value.length + busy < max && (
<div className="relative flex size-16 shrink-0 flex-col overflow-hidden rounded-xl border border-dashed border-border-strong">
- <button type="button" onClick={() => input.current?.click()} className="flex flex-1 flex-col items-center justify-center gap-0.5 text-[10px] text-muted-foreground hover:bg-brand-faint hover:text-brand-text" aria-label="Add images">
+ <button type="button" onClick={() => askFirst() || input.current?.click()} className="flex flex-1 flex-col items-center justify-center gap-0.5 text-[10px] text-muted-foreground hover:bg-brand-faint hover:text-brand-text" aria-label="Add images">
<ImagePlus className="size-4" />
Add
</button>
diff --git a/src/components/audio-tools/audio-tools.tsx b/src/components/audio-tools/audio-tools.tsx
index 8a0b02e6..8c47909b 100644
--- a/src/components/audio-tools/audio-tools.tsx
+++ b/src/components/audio-tools/audio-tools.tsx
@@ -12,7 +12,7 @@ import { ACCEPT, fileToList, fileToSlot, kindOfFile, LibraryGrid, wrongKindMessa
import { Segmented } from "@/components/faceless/controls";
import { Panel, ToolHero, ToolShell } from "@/components/av/tool-shell";
import { useDraft } from "@/components/av/use-draft";
-import { useEngine, useGenerations } from "@/lib/api";
+import { useAskBeforeUpload, useEngine, useGenerations } from "@/lib/api";
import {
clock,
CROSSFADE_MAX,
@@ -77,15 +77,18 @@ function AddAudio({ multiple, onFiles, onPick, compact, disabled }: { multiple?:
const input = useRef<HTMLInputElement>(null);
const [over, setOver] = useState(false);
const [picking, setPicking] = useState(false);
+ // A guest, or an account with neither its own GPU nor its own key, gets its card instead of the file chooser.
+ const askFirst = useAskBeforeUpload();
const take = (list: FileList | null | undefined) => {
const files = [...(list ?? [])];
+ if (!files.length || askFirst()) return;
const audio = files.filter((f) => kindOfFile(f) === "audio");
if (files.length > audio.length) toast(wrongKindMessage("audio"));
if (audio.length) onFiles(multiple ? audio : audio.slice(0, 1));
};
const buttons = (
<div className="flex flex-wrap items-center justify-center gap-1.5">
- <Button size="sm" variant={compact ? "outline" : "default"} className="rounded-full" onClick={() => input.current?.click()} disabled={disabled}>
+ <Button size="sm" variant={compact ? "outline" : "default"} className="rounded-full" onClick={() => askFirst() || input.current?.click()} disabled={disabled}>
{compact ? <Plus className="size-3.5" /> : <Upload className="size-3.5" />} {compact ? "Add a clip" : multiple ? "Upload audio clips" : "Upload audio"}
</Button>
<Popover open={picking} onOpenChange={setPicking}>
diff --git a/src/components/audio-tools/split-tool.tsx b/src/components/audio-tools/split-tool.tsx
index 2ae26fe1..9289de5b 100644
--- a/src/components/audio-tools/split-tool.tsx
+++ b/src/components/audio-tools/split-tool.tsx
@@ -14,7 +14,7 @@ import { ACCEPT, fileToSlot, kindOfFile, LibraryGrid, type SlotValue } from "@/c
import { Segmented } from "@/components/faceless/controls";
import { Panel, ToolHero, ToolShell } from "@/components/av/tool-shell";
import { useGeneration } from "@/components/av/use-generation";
-import { useEngine, useGenerations } from "@/lib/api";
+import { useAskBeforeUpload, useEngine, useGenerations } from "@/lib/api";
import type { AudioToolPreview } from "@/lib/av/audio-tools";
import {
backgroundLowered,
@@ -140,8 +140,10 @@ function AddMedia({ onPick, onUpdate }: { onPick: (s: Source) => void; onUpdate:
const input = useRef<HTMLInputElement>(null);
const [over, setOver] = useState(false);
const [picking, setPicking] = useState(false);
+ // A guest, or an account with neither its own GPU nor its own key, gets its card instead of the file chooser.
+ const askFirst = useAskBeforeUpload();
const take = (f: File | undefined) => {
- if (!f) return;
+ if (!f || askFirst()) return;
const kind = kindOfFile(f);
if (kind !== "audio" && kind !== "video") return void toast("Audio or video only — drop a sound file or a clip here");
void uploadSource(f, kind, onPick, onUpdate);
@@ -169,7 +171,7 @@ function AddMedia({ onPick, onUpdate }: { onPick: (s: Source) => void; onUpdate:
<p className="mt-1 text-[13px] text-muted-foreground">A song, podcast, film clip or video, up to 200 MB</p>
</div>
<div className="flex flex-wrap items-center justify-center gap-1.5">
- <Button size="sm" className="rounded-full" onClick={() => input.current?.click()}>
+ <Button size="sm" className="rounded-full" onClick={() => askFirst() || input.current?.click()}>
<Upload className="size-3.5" /> Upload audio or video
</Button>
<Popover open={picking} onOpenChange={setPicking}>
diff --git a/src/components/av/media-drop.tsx b/src/components/av/media-drop.tsx
index c218d38d..e0462322 100644
--- a/src/components/av/media-drop.tsx
+++ b/src/components/av/media-drop.tsx
@@ -6,12 +6,15 @@ import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/popover";
import { ACCEPT, fileToSlot, kindOfFile, LibraryGrid, wrongKindMessage, type SlotValue } from "@/components/studio/media-slot";
+import { useAskBeforeUpload } from "@/lib/api";
import { cn } from "@/lib/utils";
import { realDuration } from "./frame-sampler";
/**
* A large drop zone for the one video (or photo) a tool works on: drop, click or pick from the
* library; then a preview with Replace / Remove. Reports the clip's length once the browser knows it.
+ * Someone whose upload would be refused (a guest, an account with neither its own GPU nor its own key)
+ * is asked first instead of getting the file chooser, unless the file stays in the browser (`local`).
*/
export function MediaDrop({
kind,
@@ -51,8 +54,12 @@ export function MediaDrop({
const input = useRef<HTMLInputElement>(null);
const [over, setOver] = useState(false);
const [picking, setPicking] = useState(false);
+ const askFirst = useAskBeforeUpload();
+ /** True when the upload would be refused and its card opened instead. */
+ const refused = () => !local && askFirst();
+ const choose = () => refused() || input.current?.click();
const take = (f: File | undefined) => {
- if (!f) return;
+ if (!f || refused()) return;
if (kindOfFile(f) !== kind) return void toast(wrongKindMessage(kind));
onFile?.(f);
if (local) {
@@ -139,7 +146,7 @@ export function MediaDrop({
<Loader2 className="size-3 animate-spin" /> Uploading…
</span>
)}
- <Button variant="ghost" size="sm" className="rounded-full" onClick={() => input.current?.click()}>
+ <Button variant="ghost" size="sm" className="rounded-full" onClick={choose}>
<RefreshCw className="size-3.5" /> Replace
</Button>
<Button variant="ghost" size="icon-sm" className="rounded-full" aria-label={`Remove ${kind === "video" ? "the video" : "the photo"}`} onClick={() => onChange(null)}>
@@ -175,7 +182,7 @@ export function MediaDrop({
{hint && <p className="mt-1 text-[13px] text-muted-foreground">{hint}</p>}
</div>
<div className="flex flex-wrap items-center justify-center gap-1.5">
- <Button size="sm" className="rounded-full" onClick={() => input.current?.click()}>
+ <Button size="sm" className="rounded-full" onClick={choose}>
<Upload className="size-3.5" /> Upload {kind === "video" ? "a video" : "a photo"}
</Button>
{library}
diff --git a/src/components/studio/voice-recorder.tsx b/src/components/studio/voice-recorder.tsx
index be9011bb..e173a70e 100644
--- a/src/components/studio/voice-recorder.tsx
+++ b/src/components/studio/voice-recorder.tsx
@@ -3,7 +3,7 @@
import { Loader2, Mic, Square } from "lucide-react";
import { useEffect, useRef, useState } from "react";
import { toast } from "sonner";
-import { uploadFile } from "@/lib/api";
+import { uploadFile, useAskBeforeUpload } from "@/lib/api";
import { cn } from "@/lib/utils";
import { toastError } from "@/lib/refusals";
import type { SlotValue } from "./media-slot";
@@ -40,7 +40,7 @@ export async function toWav(blob: Blob): Promise<File> {
}
}
-/** Mic button: record a voice sample, convert it to WAV and upload it. */
+/** Mic button: record a voice sample, convert it to WAV and upload it. Whoever the upload would refuse is asked first. */
export function VoiceRecorder({ onRecorded, max = 60, className }: { onRecorded: (v: SlotValue) => void; max?: number; className?: string }) {
const [state, setState] = useState<"idle" | "recording" | "saving">("idle");
const [secs, setSecs] = useState(0);
@@ -56,8 +56,11 @@ export function VoiceRecorder({ onRecorded, max = 60, className }: { onRecorded:
);
const stop = () => rec.current?.state === "recording" && rec.current.stop();
+ // A guest, or an account with neither its own GPU nor its own key, gets its card before the microphone: the sample would be refused.
+ const askFirst = useAskBeforeUpload();
const start = async () => {
+ if (askFirst()) return;
let stream: MediaStream;
try {
stream = await navigator.mediaDevices.getUserMedia({ audio: { echoCancellation: true, noiseSuppression: true } });