Open source CapCut alternative.
TypeScript
refactor(site): drop pre-scoping legacy data adoption [rebuild]
David Le44ce9ee534aa
diff --git a/site/src/cut/server/http/routes.ts b/site/src/cut/server/http/routes.tsindex 2157877b..850ec539 100644--- a/site/src/cut/server/http/routes.ts+++ b/site/src/cut/server/http/routes.ts@@ -1,4 +1,4 @@-import { adoptLegacyData, isValidCutUser, runWithCutUser } from "../userScope";+import { isValidCutUser, runWithCutUser } from "../userScope";import { matchRouteTable } from "./match";import { aiApi } from "./ai";import { engineApi } from "./engine";@@ -120,7 +120,6 @@ export async function runCutRoute({ status: 400, headers: { "Content-Type": "application/json" } });}- await adoptLegacyData(user);return runWithCutUser(user, () => match.handler(req, match.params));}diff --git a/site/src/cut/server/userScope.ts b/site/src/cut/server/userScope.tsindex d9e9aab7..4d23d58b 100644--- a/site/src/cut/server/userScope.ts+++ b/site/src/cut/server/userScope.ts@@ -1,8 +1,6 @@import { AsyncLocalStorage } from "node:async_hooks";-import { mkdir, rename } from "node:fs/promises";import path from "node:path";import { cutDataRoot } from "./dataDir";-import { exists } from "./util";/*** Every data route runs inside a signed-in user's scope: the page sends the@@ -38,27 +36,3 @@ export function currentCutUser(): string {if (!id) throw new Error("No user scope bound to this request.");return id;}--// Data written before user scoping lived directly under the data root. The-// first account to connect adopts it — the same single owner who could see it-// before — by moving those folders into its own scope.-const LEGACY_DIRS = ["projects", "library"];-let adopting: Promise<void> | null = null;--export function adoptLegacyData(id: string): Promise<void> {- adopting ??= (async () => {- const root = cutDataRoot();- for (const dir of LEGACY_DIRS) {- const from = path.join(root, dir);- if (!(await exists(from))) continue;- const to = path.join(root, "users", id, dir);- if (await exists(to)) continue;- await mkdir(path.dirname(to), { recursive: true });- await rename(from, to);- }- })().catch((err) => {- adopting = null; // retry on the next request instead of pinning the failure- throw err;- });- return adopting;-}