fix(canvas): 画布删除 - 删除云端记录并等待本地持久化

This commit is contained in:
ddCat
2026-08-22 12:33:34 +08:00
parent e3da713970
commit 13702e662d
4 changed files with 95 additions and 16 deletions

View File

@@ -5,7 +5,7 @@ import { resourceFileUrl, resourceIdFromStorageKey, resourceStorageKey, uploadRe
import type { Asset } from "@/stores/use-asset-store";
import { useAssetStore } from "@/stores/use-asset-store";
import type { CanvasProject } from "@/stores/canvas/use-canvas-store";
import { useCanvasStore } from "@/stores/canvas/use-canvas-store";
import { flushCanvasStorePersistence, useCanvasStore } from "@/stores/canvas/use-canvas-store";
let activeRemoteUserId = "";
let applyingRemoteState = false;
@@ -177,6 +177,22 @@ export async function deleteAssetWithRemoteSync(id: string) {
});
}
export async function deleteCanvasProjectsWithRemoteSync(ids: string[]) {
const projectIds = [...new Set(ids.map((id) => id.trim()).filter(Boolean))];
if (!projectIds.length) return;
await withRemoteUserDataSyncPaused(async () => {
if (activeRemoteUserId) {
for (const id of projectIds) {
await deleteRemoteCanvasProject(id);
remoteProjectVersions.delete(id);
}
}
useCanvasStore.getState().deleteProjects(projectIds);
// 删除完成后再返回,确保刷新不会读到尚未写入 IndexedDB 的旧快照。
await flushCanvasStorePersistence();
});
}
export async function saveRemoteUserDataNow() {
if (!activeRemoteUserId) return;
if (syncPauseCount) {