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.

1.6 KB
Raw Blame
import { z } from "zod";
import { asViewer, guestRun, onceForAccount, pressIdOf, runAccountTool, toolViewer } from "@/server/account-tool-run";
import { handle, rereadSeries, rereadSteps, seriesClip } from "@/server/content-factory";
import { body } from "@/server/faceless";
import { planned } from "@/server/faceless-account";

const Read = z.object({ engine: z.enum(["cloud", "open"]) });

/**
 * Read the reference clip again (on either engine). An account's runs on its own GPU or key, on its own clip, after the
 * checks a studio run gets (src/server/account-tool-run.ts); a guest signs up first.
 */
export async function POST(request: Request, ctx: RouteContext<"/api/content-factory/series/[id]/read">) {
  const viewer = toolViewer(request);
  if (viewer.kind === "guest") return guestRun();
  return handle(async () => {
    const { id } = await ctx.params;
    const { engine } = await body(request, Read, "Pick an engine");
    if (viewer.kind === "owner") return Response.json(await rereadSeries(id, engine));
    const clip = asViewer(viewer, () => seriesClip(id));
    // On this install's GPUs, a resend of this press (its id in the header) gets the reading the first one started.
    return onceForAccount(
      viewer.account,
      `content-factory-read:${id}`,
      pressIdOf(request),
      () => runAccountTool(request, viewer.account, { tool: "content-factory", files: [clip], plan: () => planned(() => rereadSteps(id, engine)), start: () => rereadSeries(id, engine) }),
      ({ value, gpuWarning }) => Response.json({ ...value, ...(gpuWarning && { gpuWarning }) }),
    );
  }, request);
}