Skip to content

Open source CapCut alternative.

TypeScript
1.0 KB
Raw Blame
// The local backend: the engine on this Mac. A pass-through to the existing
// engine transport in ../api, so request shapes are exactly what they were
// before the backend seam existed.
import { apiFetch, apiUrl, engineReady, engineOrigin, currentEngineUser } from "../api";
import type { CutBackend } from "./types";

export const localBackend: CutBackend = {
  kind: "local",
  caps: {
    importUrl: true,
    liveMic: true,
    transcribe: true,
    captionAi: true,
    revealInFinder: true,
    watch: true,
  },
  fetch: (path, init) => apiFetch(path, init),
  url: (path) => apiUrl(path),
};

export function captureLocalBackend(): CutBackend {
  const userId = currentEngineUser();
  const origin = engineOrigin();
  const scoped = (path: string) => userId
    ? `${path}${path.includes("?") ? "&" : "?"}u=${encodeURIComponent(userId)}` : path;
  return {
    ...localBackend,
    fetch: async (path, init) => fetch(`${origin || await engineReady()}${scoped(path)}`, init),
    url: (path) => `${origin}${scoped(path)}`,
  };
}