Open source CapCut alternative.
TypeScript
feat(site): engine health lists the features the build carries [rebuild]
David Le88a31978b46b
diff --git a/site/src/cut/lib/api.ts b/site/src/cut/lib/api.tsindex a3b43f36..1e6bdce7 100644--- a/site/src/cut/lib/api.ts+++ b/site/src/cut/lib/api.ts@@ -61,6 +61,7 @@ export const ENGINE_LOST_EVENT = "cut-engine-lost";* connect. */export function engineLost() {resolvedOrigin = null;+ features = null;gateOpened = new Promise<void>((resolve) => {openGate = resolve;});@@ -171,6 +172,22 @@ export function engineOrigin(): string {return resolvedOrigin ?? "";}+// What the connected engine build can carry (see lib/engineFeatures.ts),+// read from its health answer once per connection. An engine from before the+// list existed answers with none, so work it would drop is refused up front.+let features: Promise<ReadonlySet<string>> | null = null;++export function engineFeatures(): Promise<ReadonlySet<string>> {+ features ??= fetch(`${engineOrigin()}/api/cut/engine/health`)+ .then((res) => res.json() as Promise<{ features?: string[] }>)+ .then((body) => new Set(Array.isArray(body.features) ? body.features : []) as ReadonlySet<string>)+ .catch(() => {+ features = null;+ return new Set<string>();+ });+ return features;+}+// The signed-in Donkey account, set by RequireSession once the session// resolves. Every engine URL carries it (the `u` param) — headers can't,// because media loads as plain <video>/<img> src. Local data is shared by everydiff --git a/site/src/cut/lib/engineFeatures.ts b/site/src/cut/lib/engineFeatures.tsnew file mode 100644index 00000000..31af00c3--- /dev/null+++ b/site/src/cut/lib/engineFeatures.ts@@ -0,0 +1,9 @@+/**+ * What this engine build can carry beyond the shape every build shares. The+ * engine lists these in its health answer; the page reads them before it+ * hands an engine work an older app would silently drop. A build from before+ * the list existed answers with none.+ */+export const ENGINE_FEATURES = ["export.range", "export.name"] as const;++export type EngineFeature = (typeof ENGINE_FEATURES)[number];diff --git a/site/src/cut/server/http/engine.ts b/site/src/cut/server/http/engine.tsindex 0f871935..61f47109 100644--- a/site/src/cut/server/http/engine.ts+++ b/site/src/cut/server/http/engine.ts@@ -1,4 +1,5 @@import os from "node:os";+import { ENGINE_FEATURES } from "../../lib/engineFeatures";/** The engine's version: the Donkey app passes its own release version when it* spawns the engine, so engine updates ride app updates. "dev" everywhere@@ -23,6 +24,7 @@ export const engineApi = {engine: "donkey-cut",version: engineVersion(),user: engineUser(),+ features: ENGINE_FEATURES,});},};