Create polished demo videos without editing skills. Mac/Windows/Linux
Protect projectId from overwrite follow-up
webadderallcdd23789922c
diff --git a/electron/electron-env.d.ts b/electron/electron-env.d.tsindex 9e0adb6f..c24386a0 100644--- a/electron/electron-env.d.ts+++ b/electron/electron-env.d.ts@@ -341,6 +341,7 @@ interface Window {) => Promise<{success: boolean;path?: string;+ projectId?: string;message?: string;canceled?: boolean;error?: string;@@ -352,6 +353,7 @@ interface Window {) => Promise<{success: boolean;path?: string;+ projectId?: string;message?: string;canceled?: boolean;error?: string;diff --git a/electron/ipc/register/project.ts b/electron/ipc/register/project.tsindex e3fbd502..b041f7df 100644--- a/electron/ipc/register/project.ts+++ b/electron/ipc/register/project.ts@@ -1,4 +1,5 @@import { constants as fsConstants } from "node:fs";+import { randomUUID } from "node:crypto";import fs from "node:fs/promises";import path from "node:path";import { dialog, ipcMain, shell } from "electron";@@ -82,12 +83,55 @@ function getProjectVideoPath(projectData: unknown) {return typeof candidate.videoPath === "string" ? candidate.videoPath : null;}+function getProjectId(projectData: unknown) {+ if (!projectData || typeof projectData !== "object") {+ return null;+ }++ const candidate = projectData as { projectId?: unknown };+ return typeof candidate.projectId === "string" && candidate.projectId.trim().length > 0+ ? candidate.projectId+ : null;+}++function withProjectId(projectData: unknown, projectId: string) {+ if (!projectData || typeof projectData !== "object" || Array.isArray(projectData)) {+ return projectData;+ }++ return {+ ...projectData,+ projectId,+ };+}++function ensureProjectDataHasProjectId(projectData: unknown) {+ const existingProjectId = getProjectId(projectData);+ if (existingProjectId) {+ return {+ projectId: existingProjectId,+ projectData,+ };+ }++ const projectId = randomUUID();+ return {+ projectId,+ projectData: withProjectId(projectData, projectId),+ };+}++async function resolveComparablePath(filePath: string) {+ return fs.realpath(filePath).catch(() => path.resolve(filePath));+}+/*** Prevents a named save from silently overwriting a different project file.*/async function ensureNamedProjectSaveDoesNotOverwriteDifferentProject(targetProjectPath: string,projectData: unknown,+ activeProjectPath?: string | null,) {try {await fs.stat(targetProjectPath);@@ -98,34 +142,59 @@ async function ensureNamedProjectSaveDoesNotOverwriteDifferentProject(throw error;}- const incomingVideoPath = getProjectVideoPath(projectData);- if (!incomingVideoPath) {- return {- success: false,- message: "Unable to verify project identity for the chosen name",- };+ const targetResolvedPath = await resolveComparablePath(targetProjectPath);+ if (activeProjectPath) {+ const activeResolvedPath = await resolveComparablePath(activeProjectPath);+ if (activeResolvedPath === targetResolvedPath) {+ return { success: true };+ }}+ const incomingProjectId = getProjectId(projectData);+ const incomingVideoPath = getProjectVideoPath(projectData);+try {const existingProjectRaw = await fs.readFile(targetProjectPath, "utf-8");const existingProjectData = JSON.parse(existingProjectRaw) as unknown;+ const existingProjectId = getProjectId(existingProjectData);const existingVideoPath = getProjectVideoPath(existingProjectData);- if (existingVideoPath === incomingVideoPath) {- return { success: true };+ if (existingProjectId && incomingProjectId) {+ if (existingProjectId === incomingProjectId) {+ return { success: true };+ }++ return {+ success: false,+ message: "A different project already uses this name",+ };+ }++ if (existingVideoPath && incomingVideoPath && existingVideoPath !== incomingVideoPath) {+ return {+ success: false,+ message: "A different project already uses this name",+ };}++ if (!existingProjectId && !incomingProjectId && existingVideoPath && incomingVideoPath) {+ return {+ success: false,+ message: "Unable to verify project identity for the chosen name",+ };+ }++ return {+ success: false,+ message: "Unable to verify project identity for the chosen name",+ };} catch (error) {console.error("Failed to verify existing named project before overwrite:", error);return {success: false,- message: "A different project already uses this name",+ message: "Unable to verify project identity for the chosen name",};}-- return {- success: false,- message: "A different project already uses this name",- };}export function registerProjectHandlers() {@@ -213,18 +282,20 @@ export function registerProjectHandlers() {ipcMain.handle('save-project-file', async (_, projectData: unknown, suggestedName?: string, existingProjectPath?: string, thumbnailDataUrl?: string | null) => {try {const projectsDir = await getProjectsDir()+ const preparedProject = ensureProjectDataHasProjectId(projectData)const trustedExistingProjectPath = isTrustedProjectPath(existingProjectPath)? existingProjectPath: nullif (trustedExistingProjectPath) {- await fs.writeFile(trustedExistingProjectPath, JSON.stringify(projectData, null, 2), 'utf-8')+ await fs.writeFile(trustedExistingProjectPath, JSON.stringify(preparedProject.projectData, null, 2), 'utf-8')setCurrentProjectPath(trustedExistingProjectPath)await saveProjectThumbnail(trustedExistingProjectPath, thumbnailDataUrl)await rememberRecentProject(trustedExistingProjectPath)return {success: true,path: trustedExistingProjectPath,+ projectId: preparedProject.projectId,message: 'Project saved successfully'}}@@ -250,7 +321,7 @@ export function registerProjectHandlers() {}}- await fs.writeFile(result.filePath, JSON.stringify(projectData, null, 2), 'utf-8')+ await fs.writeFile(result.filePath, JSON.stringify(preparedProject.projectData, null, 2), 'utf-8')setCurrentProjectPath(result.filePath)await saveProjectThumbnail(result.filePath, thumbnailDataUrl)await rememberRecentProject(result.filePath)@@ -258,6 +329,7 @@ export function registerProjectHandlers() {return {success: true,path: result.filePath,+ projectId: preparedProject.projectId,message: 'Project saved successfully'}} catch (error) {@@ -281,6 +353,7 @@ export function registerProjectHandlers() {}const projectsDir = await getProjectsDir()+ const preparedProject = ensureProjectDataHasProjectId(projectData)const targetProjectPath = path.join(projectsDir,`${normalizedProjectName}.${PROJECT_FILE_EXTENSION}`,@@ -288,13 +361,14 @@ export function registerProjectHandlers() {const overwriteCheck = await ensureNamedProjectSaveDoesNotOverwriteDifferentProject(targetProjectPath,- projectData,+ preparedProject.projectData,+ currentProjectPath,)if (!overwriteCheck.success) {return overwriteCheck}- await fs.writeFile(targetProjectPath, JSON.stringify(projectData, null, 2), 'utf-8')+ await fs.writeFile(targetProjectPath, JSON.stringify(preparedProject.projectData, null, 2), 'utf-8')setCurrentProjectPath(targetProjectPath)await saveProjectThumbnail(targetProjectPath, thumbnailDataUrl)await rememberRecentProject(targetProjectPath)@@ -302,6 +376,7 @@ export function registerProjectHandlers() {return {success: true,path: targetProjectPath,+ projectId: preparedProject.projectId,message: 'Project saved successfully'}} catch (error) {diff --git a/src/components/video-editor/VideoEditor.tsx b/src/components/video-editor/VideoEditor.tsxindex f8dc0597..92aaf29e 100644--- a/src/components/video-editor/VideoEditor.tsx+++ b/src/components/video-editor/VideoEditor.tsx@@ -1592,7 +1592,11 @@ export default function VideoEditor() {setLastSavedSnapshot(cloneStructured(- createProjectData(sourcePath, buildPersistedEditorState(normalizedEditor)),+ createProjectData(+ sourcePath,+ buildPersistedEditorState(normalizedEditor),+ project.projectId ?? null,+ ),),);await refreshProjectLibrary();@@ -1605,8 +1609,12 @@ export default function VideoEditor() {if (!currentSourcePath) {return null;}- return createProjectData(currentSourcePath, currentPersistedEditorState);- }, [currentPersistedEditorState, currentSourcePath]);+ return createProjectData(+ currentSourcePath,+ currentPersistedEditorState,+ lastSavedSnapshot?.projectId ?? null,+ );+ }, [currentPersistedEditorState, currentSourcePath, lastSavedSnapshot?.projectId]);const syncRecordingSessionWebcam = useCallback(async (webcamPath: string | null) => {@@ -2120,7 +2128,11 @@ export default function VideoEditor() {const projectData =currentProjectSnapshot?.videoPath === currentSourcePath? currentProjectSnapshot- : createProjectData(currentSourcePath, currentPersistedEditorState);+ : createProjectData(+ currentSourcePath,+ currentPersistedEditorState,+ lastSavedSnapshot?.projectId ?? null,+ );const fileNameBase =currentSourcePath@@ -2159,7 +2171,15 @@ export default function VideoEditor() {if (result.path) {setCurrentProjectPath(result.path);}- setLastSavedSnapshot(cloneStructured(projectData));+ setLastSavedSnapshot(+ cloneStructured(+ createProjectData(+ projectData.videoPath,+ projectData.editor,+ result.projectId ?? projectData.projectId ?? null,+ ),+ ),+ );await refreshProjectLibrary();toast.success(`Project saved to ${result.path}`);@@ -2174,6 +2194,7 @@ export default function VideoEditor() {currentProjectPath,currentProjectSnapshot,currentPersistedEditorState,+ lastSavedSnapshot?.projectId,refreshProjectLibrary,remountPreview,],@@ -2222,7 +2243,11 @@ export default function VideoEditor() {const projectData =currentProjectSnapshot?.videoPath === currentSourcePath? currentProjectSnapshot- : createProjectData(currentSourcePath, currentPersistedEditorState);+ : createProjectData(+ currentSourcePath,+ currentPersistedEditorState,+ lastSavedSnapshot?.projectId ?? null,+ );const thumbnailDataUrl = await captureProjectThumbnail();const result = await window.electronAPI.saveProjectFileNamed(projectData,@@ -2243,7 +2268,15 @@ export default function VideoEditor() {if (result.path) {setCurrentProjectPath(result.path);}- setLastSavedSnapshot(cloneStructured(projectData));+ setLastSavedSnapshot(+ cloneStructured(+ createProjectData(+ projectData.videoPath,+ projectData.editor,+ result.projectId ?? projectData.projectId ?? null,+ ),+ ),+ );await refreshProjectLibrary();toast.success(result.path ? `Project saved to ${result.path}` : "Project saved");return true;@@ -2256,6 +2289,7 @@ export default function VideoEditor() {currentPersistedEditorState,currentProjectSnapshot,currentSourcePath,+ lastSavedSnapshot?.projectId,refreshProjectLibrary,remountPreview,],diff --git a/src/components/video-editor/projectPersistence.ts b/src/components/video-editor/projectPersistence.tsindex 71823988..04bac765 100644--- a/src/components/video-editor/projectPersistence.ts+++ b/src/components/video-editor/projectPersistence.ts@@ -118,6 +118,7 @@ export interface ProjectEditorState {export interface EditorProjectData {version: number;+ projectId?: string;videoPath: string;editor: Partial<ProjectEditorState>;}@@ -281,6 +282,7 @@ export function validateProjectData(candidate: unknown): candidate is EditorProjif (!candidate || typeof candidate !== "object") return false;const project = candidate as Partial<EditorProjectData>;if (typeof project.version !== "number") return false;+ if (project.projectId !== undefined && typeof project.projectId !== "string") return false;if (typeof project.videoPath !== "string" || !project.videoPath) return false;if (!project.editor || typeof project.editor !== "object") return false;return true;@@ -861,9 +863,13 @@ export function normalizeProjectEditor(editor: Partial<ProjectEditorState>): Proexport function createProjectData(videoPath: string,editor: Partial<ProjectEditorState>,+ projectId?: string | null,): EditorProjectData {return {version: PROJECT_VERSION,+ ...(typeof projectId === "string" && projectId.trim().length > 0+ ? { projectId }+ : {}),videoPath,editor,};