Open source CapCut alternative.
TypeScript
chore(site): wire Cut API routes, shared types & store actions
David Lec6c63ef90c8c
diff --git a/site/src/cut/lib/store.ts b/site/src/cut/lib/store.tsindex d57ff8ef..07a7e142 100644--- a/site/src/cut/lib/store.ts+++ b/site/src/cut/lib/store.ts@@ -16,6 +16,7 @@ import type {} from "./types";import { apiFetch } from "./api";import { emptySubtitles, mediaUrl, SPEED_MAX, SPEED_MIN, TRANSITION_MAX } from "./types";+import { readTextStyle } from "./textStyle";import { loadUiState, saveUiState } from "./uiState";const uid = () => crypto.randomUUID().slice(0, 8);@@ -69,6 +70,8 @@ interface EditorState {skimTime: number | null;/** TikTok publishing metadata (caption, hashtags, sound title). */publish: { caption: string; tags: string; soundTitle: string; handle: string };+ /** Free-form maker notes: published date, source links, reminders. */+ notes: { text: string; publishedAt: string; links: string[] };/** Subtitles: cues + visibility, persisted with the project. */subtitles: SubtitlesBlock;subtitleStatus: SubtitleStatus;@@ -115,9 +118,13 @@ interface EditorState {splitAtPlayhead: (at?: number) => void;setSkimTime: (t: number | null) => void;setPublish: (patch: Partial<{ caption: string; tags: string; soundTitle: string; handle: string }>) => void;+ setNotes: (patch: Partial<{ text: string; publishedAt: string; links: string[] }>) => void;/** Kick off (and poll) an on-device transcription of the current cut. */generateSubtitles: () => Promise<void>;- setSubtitlesView: (patch: Partial<Pick<SubtitlesBlock, "showOnVideo" | "showOnTimeline" | "locale">>) => void;+ /** Transcribe (if needed) then rewrite the cues into social captions in the+ * given style, one-to-one so cue timings are preserved. */+ generateCaptions: (style: "clean" | "hook" | "punchy") => Promise<void>;+ setSubtitlesView: (patch: Partial<Pick<SubtitlesBlock, "showOnVideo" | "showOnTimeline" | "locale" | "style">>) => void;/** Commit a cue's edited text (empty text deletes the cue). */setCueText: (id: string, text: string) => void;/** Split a cue at a character offset — at real word timings when known. */@@ -235,6 +242,7 @@ export const useEditor = create<EditorState>((set, get) => {timelineH: TIMELINE_H_DEFAULT,skimTime: null,publish: { caption: "", tags: "", soundTitle: "", handle: "" },+ notes: { text: "", publishedAt: "", links: [] },subtitles: emptySubtitles(),subtitleStatus: "idle",subtitleError: null,@@ -293,6 +301,11 @@ export const useEditor = create<EditorState>((set, get) => {soundTitle: doc.publish?.soundTitle ?? "",handle: doc.publish?.handle ?? "",},+ notes: {+ text: doc.notes?.text ?? "",+ publishedAt: doc.notes?.publishedAt ?? "",+ links: doc.notes?.links ?? [],+ },subtitles: doc.subtitles ?? emptySubtitles(),subtitleStatus: (doc.subtitles?.cues.length ?? 0) > 0 ? "ready" : "idle",loaded: true,@@ -414,6 +427,9 @@ export const useEditor = create<EditorState>((set, get) => {const t = get().currentTime;const total = totalDuration(get().clips);const start = Math.min(t, Math.max(0, total - 0.5));+ // Seed the visual style from the last-used title so repeated titles in a+ // project share one look; fall back to the built-in defaults.+ const remembered = readTextStyle();const overlay: TextOverlay = {id: uid(),text: "Your text",@@ -421,12 +437,15 @@ export const useEditor = create<EditorState>((set, get) => {end: Math.min(start + 3, Math.max(total, start + 3)),x: 0.5,y: 0.42,- size: 88,- font: "sf",- weight: 700,- color: "#FFFFFF",- shadow: true,- plate: false,+ size: remembered.size ?? 88,+ font: remembered.font ?? "sf",+ weight: remembered.weight ?? 700,+ color: remembered.color ?? "#FFFFFF",+ shadow: remembered.shadow ?? true,+ plate: remembered.plate ?? false,+ plateColor: remembered.plateColor,+ plateOpacity: remembered.plateOpacity,+ plateRadius: remembered.plateRadius,lane: 0,};set((s) => ({@@ -673,6 +692,7 @@ export const useEditor = create<EditorState>((set, get) => {if (get().skimTime !== t) set({ skimTime: t });},setPublish: (patch) => set((s) => ({ publish: { ...s.publish, ...patch } })),+ setNotes: (patch) => set((s) => ({ notes: { ...s.notes, ...patch } })),generateSubtitles: async () => {const s = get();@@ -757,6 +777,61 @@ export const useEditor = create<EditorState>((set, get) => {}},+ generateCaptions: async (style) => {+ const s = get();+ if (!s.projectId || s.subtitleStatus === "running") return;+ // Need cues first — transcribe if the cut hasn't been captioned yet.+ if (s.subtitles.cues.length === 0) {+ await s.generateSubtitles();+ if (get().subtitles.cues.length === 0) return; // no speech, or an error+ }+ const projectId = get().projectId;+ // Apply the look right away for instant feedback, then rewrite the text.+ set((cur) => ({+ subtitles: { ...cur.subtitles, style },+ subtitleStatus: "running",+ subtitleError: null,+ }));+ const cues = get().subtitles.cues;+ try {+ const res = await apiFetch("/api/cut/ai/captions", {+ method: "POST",+ headers: { "Content-Type": "application/json" },+ body: JSON.stringify({+ style,+ cues: cues.map((c) => ({ start: c.start, end: c.end, text: c.text })),+ }),+ });+ const body = (await res.json()) as { texts?: string[]; error?: string };+ if (get().projectId !== projectId) return;+ push();+ if (res.ok && Array.isArray(body.texts) && body.texts.length === cues.length) {+ const texts = body.texts;+ set((cur) => ({+ subtitles: {+ ...cur.subtitles,+ style,+ // Rewriting the text drops per-word timings (they no longer match),+ // but the cue's own start/end are untouched.+ cues: cur.subtitles.cues.map((c, i) =>+ texts[i] && texts[i] !== c.text ? { ...c, text: texts[i], words: undefined } : c+ ),+ },+ subtitleStatus: "ready",+ }));+ } else {+ // The style still applied; leave the text as-is.+ set({ subtitleStatus: "ready" });+ }+ } catch (err) {+ if (get().projectId !== projectId) return;+ set({+ subtitleStatus: "ready",+ subtitleError: err instanceof Error ? err.message : String(err),+ });+ }+ },+setSubtitlesView: (patch) =>set((s) => ({ subtitles: { ...s.subtitles, ...patch } })),@@ -1018,6 +1093,7 @@ export function serializeDoc(s: {overlays: TextOverlay[];aspect: Aspect;publish: { caption: string; tags: string; soundTitle: string; handle: string };+ notes: { text: string; publishedAt: string; links: string[] };subtitles: SubtitlesBlock;}): Partial<ProjectDoc> {const assets: StoredAsset[] = s.assets.map(@@ -1040,6 +1116,7 @@ export function serializeDoc(s: {aspect: s.aspect,subtitles: s.subtitles,publish: { ...s.publish },+ notes: { ...s.notes, links: [...s.notes.links] },};}diff --git a/site/src/cut/lib/types.ts b/site/src/cut/lib/types.tsindex 29a49193..df172619 100644--- a/site/src/cut/lib/types.ts+++ b/site/src/cut/lib/types.ts@@ -140,6 +140,8 @@ export interface SubtitlesBlock {showOnTimeline: boolean;locale?: string;generatedAt?: number;+ /** Caption look preset; absent = the plain "clean" subtitle style. */+ style?: "clean" | "hook" | "punchy";}export const emptySubtitles = (): SubtitlesBlock => ({@@ -191,6 +193,21 @@ export interface ProjectDoc {soundTitle?: string;handle?: string;};+ /** Free-form notes for the maker: published date, source links, reminders. */+ notes?: {+ text?: string;+ publishedAt?: string; // ISO date (yyyy-mm-dd)+ links?: string[];+ };+ /** Which project folder this belongs to (null/absent = ungrouped). */+ folderId?: string | null;+}++/** A named group of projects on the home screen. */+export interface ProjectFolder {+ id: string;+ name: string;+ createdAt: number;}export interface ProjectSummary {@@ -201,8 +218,16 @@ export interface ProjectSummary {duration: number;clipCount: number;assetCount: number;- /** Media file used for the card poster / hover preview. */+ /** Media file used for the card poster / hover fallback. */previewFile?: string;+ /** Source time (seconds) of the poster frame — the first clip's trim-in. */+ previewStart?: number;+ /** Whether a rendered proxy of the edit exists to play on hover. */+ hasPreview?: boolean;+ /** Folder this project is filed under (null = ungrouped). */+ folderId?: string | null;+ /** Total bytes on disk (media + exports + proxy), for cleanup decisions. */+ sizeBytes?: number;}export const mediaUrl = (projectId: string, fileName: string) =>diff --git a/site/src/cut/server/http/routes.ts b/site/src/cut/server/http/routes.tsindex d4e46077..3fee009a 100644--- a/site/src/cut/server/http/routes.ts+++ b/site/src/cut/server/http/routes.ts@@ -22,6 +22,11 @@ export const CUT_ROUTES: CutRoute[] = [{ method: "GET", path: "/api/cut/projects", handler: () => projectsApi.list() },{ method: "POST", path: "/api/cut/projects", handler: (req) => projectsApi.create(req) },+ { method: "GET", path: "/api/cut/projects/folders", handler: () => projectsApi.folders() },+ { method: "POST", path: "/api/cut/projects/folders", handler: (req) => projectsApi.createFolder(req) },+ { method: "PUT", path: "/api/cut/projects/folders/:id", handler: (req, p) => projectsApi.renameFolder(req, { id: p.id }) },+ { method: "DELETE", path: "/api/cut/projects/folders/:id", handler: (req, p) => projectsApi.deleteFolder(req, { id: p.id }) },+ { method: "POST", path: "/api/cut/projects/:id/move", handler: (req, p) => projectsApi.move(req, { id: p.id }) },{ method: "GET", path: "/api/cut/projects/:id", handler: (req, p) => projectsApi.get(req, { id: p.id }) },{ method: "PUT", path: "/api/cut/projects/:id", handler: (req, p) => projectsApi.put(req, { id: p.id }) },{ method: "DELETE", path: "/api/cut/projects/:id", handler: (req, p) => projectsApi.remove(req, { id: p.id }) },@@ -34,13 +39,22 @@ export const CUT_ROUTES: CutRoute[] = [{ method: "POST", path: "/api/cut/projects/:id/transcribe", handler: (req, p) => projectsApi.transcribeStart(req, { id: p.id }) },{ method: "GET", path: "/api/cut/projects/:id/transcribe", handler: (req, p) => projectsApi.transcribePoll(req, { id: p.id }) },{ method: "POST", path: "/api/cut/projects/:id/freeze", handler: (req, p) => projectsApi.freeze(req, { id: p.id }) },+ { method: "POST", path: "/api/cut/projects/:id/duplicate", handler: (req, p) => projectsApi.duplicate(req, { id: p.id }) },+ { method: "GET", path: "/api/cut/projects/:id/preview", handler: (req, p) => projectsApi.servePreview(req, { id: p.id }) },+ { method: "GET", path: "/api/cut/projects/:id/export-jobs", handler: (req, p) => exportApi.activeForProject(req, { id: p.id }) },{ method: "GET", path: "/api/cut/library", handler: () => libraryApi.list() },{ method: "POST", path: "/api/cut/library", handler: (req) => libraryApi.upload(req) },- { method: "DELETE", path: "/api/cut/library/:id", handler: (req, p) => libraryApi.remove(req, { id: p.id }) },{ method: "POST", path: "/api/cut/library/use", handler: (req) => libraryApi.use(req) },{ method: "POST", path: "/api/cut/library/save", handler: (req) => libraryApi.save(req) },+ { method: "POST", path: "/api/cut/library/import-url", handler: (req) => libraryApi.importUrl(req) },+ { method: "POST", path: "/api/cut/library/move", handler: (req) => libraryApi.move(req) },+ { method: "POST", path: "/api/cut/library/folders", handler: (req) => libraryApi.createFolder(req) },+ { method: "PUT", path: "/api/cut/library/folders/:id", handler: (req, p) => libraryApi.renameFolder(req, { id: p.id }) },+ { method: "DELETE", path: "/api/cut/library/folders/:id", handler: (req, p) => libraryApi.deleteFolder(req, { id: p.id }) },{ method: "GET", path: "/api/cut/library/media/:file", handler: (req, p) => libraryApi.serveMedia(req, { file: p.file }) },+ { method: "GET", path: "/api/cut/library/thumb/:id", handler: (req, p) => libraryApi.serveThumb(req, { id: p.id }) },+ { method: "DELETE", path: "/api/cut/library/:id", handler: (req, p) => libraryApi.remove(req, { id: p.id }) },{ method: "POST", path: "/api/cut/export", handler: (req) => exportApi.create(req) },{ method: "GET", path: "/api/cut/export/:jobId", handler: (req, p) => exportApi.status(req, { jobId: p.jobId }) },@@ -48,6 +62,7 @@ export const CUT_ROUTES: CutRoute[] = [{ method: "GET", path: "/api/cut/export/:jobId/file", handler: (req, p) => exportApi.file(req, { jobId: p.jobId }) },{ method: "POST", path: "/api/cut/ai/chat", handler: (req) => aiApi.chat(req) },+ { method: "POST", path: "/api/cut/ai/captions", handler: (req) => aiApi.captions(req) },{ method: "GET", path: "/api/cut/ai/models", handler: () => aiApi.models() },{ method: "GET", path: "/api/cut/ai/proxy", handler: (req) => aiApi.proxyCatalog(req) },{ method: "POST", path: "/api/cut/ai/proxy", handler: (req) => aiApi.proxyCall(req) },