OpenReel Video - Professional browser-based video editor. Open source CapCut alternative. 100% browser-based, no installation, no cloud uploads, no watermarks.
TypeScript
feat(assets): add folder hint to JSON and persist directory handle for auto-restore
lvalicsdc8d08e2705c
diff --git a/.serena/.gitignore b/.serena/.gitignorenew file mode 100644index 00000000..2e510aff--- /dev/null+++ b/.serena/.gitignore@@ -0,0 +1,2 @@+/cache+/project.local.ymldiff --git a/.serena/project.yml b/.serena/project.ymlnew file mode 100644index 00000000..77baec76--- /dev/null+++ b/.serena/project.yml@@ -0,0 +1,135 @@+# the name by which the project can be referenced within Serena+project_name: "openreel-video"+++# list of languages for which language servers are started; choose from:+# al bash clojure cpp csharp+# csharp_omnisharp dart elixir elm erlang+# fortran fsharp go groovy haskell+# java julia kotlin lua markdown+# matlab nix pascal perl php+# php_phpactor powershell python python_jedi r+# rego ruby ruby_solargraph rust scala+# swift terraform toml typescript typescript_vts+# vue yaml zig+# (This list may be outdated. For the current list, see values of Language enum here:+# https://github.com/oraios/serena/blob/main/src/solidlsp/ls_config.py+# For some languages, there are alternative language servers, e.g. csharp_omnisharp, ruby_solargraph.)+# Note:+# - For C, use cpp+# - For JavaScript, use typescript+# - For Free Pascal/Lazarus, use pascal+# Special requirements:+# Some languages require additional setup/installations.+# See here for details: https://oraios.github.io/serena/01-about/020_programming-languages.html#language-servers+# When using multiple languages, the first language server that supports a given file will be used for that file.+# The first language is the default language and the respective language server will be used as a fallback.+# Note that when using the JetBrains backend, language servers are not used and this list is correspondingly ignored.+languages:+- typescript++# the encoding used by text files in the project+# For a list of possible encodings, see https://docs.python.org/3.11/library/codecs.html#standard-encodings+encoding: "utf-8"++# line ending convention to use when writing source files.+# Possible values: unset (use global setting), "lf", "crlf", or "native" (platform default)+# This does not affect Serena's own files (e.g. memories and configuration files), which always use native line endings.+line_ending:++# The language backend to use for this project.+# If not set, the global setting from serena_config.yml is used.+# Valid values: LSP, JetBrains+# Note: the backend is fixed at startup. If a project with a different backend+# is activated post-init, an error will be returned.+language_backend:++# whether to use project's .gitignore files to ignore files+ignore_all_files_in_gitignore: true++# list of additional paths to ignore in this project.+# Same syntax as gitignore, so you can use * and **.+# Note: global ignored_paths from serena_config.yml are also applied additively.+ignored_paths: []++# whether the project is in read-only mode+# If set to true, all editing tools will be disabled and attempts to use them will result in an error+# Added on 2025-04-18+read_only: false++# list of tool names to exclude. We recommend not excluding any tools, see the readme for more details.+# Below is the complete list of tools for convenience.+# To make sure you have the latest list of tools, and to view their descriptions,+# execute `uv run scripts/print_tool_overview.py`.+#+# * `activate_project`: Activates a project by name.+# * `check_onboarding_performed`: Checks whether project onboarding was already performed.+# * `create_text_file`: Creates/overwrites a file in the project directory.+# * `delete_lines`: Deletes a range of lines within a file.+# * `delete_memory`: Deletes a memory from Serena's project-specific memory store.+# * `execute_shell_command`: Executes a shell command.+# * `find_referencing_code_snippets`: Finds code snippets in which the symbol at the given location is referenced.+# * `find_referencing_symbols`: Finds symbols that reference the symbol at the given location (optionally filtered by type).+# * `find_symbol`: Performs a global (or local) search for symbols with/containing a given name/substring (optionally filtered by type).+# * `get_current_config`: Prints the current configuration of the agent, including the active and available projects, tools, contexts, and modes.+# * `get_symbols_overview`: Gets an overview of the top-level symbols defined in a given file.+# * `initial_instructions`: Gets the initial instructions for the current project.+# Should only be used in settings where the system prompt cannot be set,+# e.g. in clients you have no control over, like Claude Desktop.+# * `insert_after_symbol`: Inserts content after the end of the definition of a given symbol.+# * `insert_at_line`: Inserts content at a given line in a file.+# * `insert_before_symbol`: Inserts content before the beginning of the definition of a given symbol.+# * `list_dir`: Lists files and directories in the given directory (optionally with recursion).+# * `list_memories`: Lists memories in Serena's project-specific memory store.+# * `onboarding`: Performs onboarding (identifying the project structure and essential tasks, e.g. for testing or building).+# * `prepare_for_new_conversation`: Provides instructions for preparing for a new conversation (in order to continue with the necessary context).+# * `read_file`: Reads a file within the project directory.+# * `read_memory`: Reads the memory with the given name from Serena's project-specific memory store.+# * `remove_project`: Removes a project from the Serena configuration.+# * `replace_lines`: Replaces a range of lines within a file with new content.+# * `replace_symbol_body`: Replaces the full definition of a symbol.+# * `restart_language_server`: Restarts the language server, may be necessary when edits not through Serena happen.+# * `search_for_pattern`: Performs a search for a pattern in the project.+# * `summarize_changes`: Provides instructions for summarizing the changes made to the codebase.+# * `switch_modes`: Activates modes by providing a list of their names+# * `think_about_collected_information`: Thinking tool for pondering the completeness of collected information.+# * `think_about_task_adherence`: Thinking tool for determining whether the agent is still on track with the current task.+# * `think_about_whether_you_are_done`: Thinking tool for determining whether the task is truly completed.+# * `write_memory`: Writes a named memory (for future reference) to Serena's project-specific memory store.+excluded_tools: []++# list of tools to include that would otherwise be disabled (particularly optional tools that are disabled by default)+included_optional_tools: []++# fixed set of tools to use as the base tool set (if non-empty), replacing Serena's default set of tools.+# This cannot be combined with non-empty excluded_tools or included_optional_tools.+fixed_tools: []++# list of mode names to that are always to be included in the set of active modes+# The full set of modes to be activated is base_modes + default_modes.+# If the setting is undefined, the base_modes from the global configuration (serena_config.yml) apply.+# Otherwise, this setting overrides the global configuration.+# Set this to [] to disable base modes for this project.+# Set this to a list of mode names to always include the respective modes for this project.+base_modes:++# list of mode names that are to be activated by default.+# The full set of modes to be activated is base_modes + default_modes.+# If the setting is undefined, the default_modes from the global configuration (serena_config.yml) apply.+# Otherwise, this overrides the setting from the global configuration (serena_config.yml).+# This setting can, in turn, be overridden by CLI parameters (--mode).+default_modes:++# initial prompt for the project. It will always be given to the LLM upon activating the project+# (contrary to the memories, which are loaded on demand).+initial_prompt: ""++# time budget (seconds) per tool call for the retrieval of additional symbol information+# such as docstrings or parameter information.+# This overrides the corresponding setting in the global configuration; see the documentation there.+# If null or missing, use the setting from the global configuration.+symbol_info_budget:++# list of regex patterns which, when matched, mark a memory entry as read‑only.+# Extends the list from the global configuration, merging the two lists.+read_only_memory_patterns: []diff --git a/apps/web/src/components/editor/AssetsPanel.tsx b/apps/web/src/components/editor/AssetsPanel.tsxindex 7f30bbf6..b336b520 100644--- a/apps/web/src/components/editor/AssetsPanel.tsx+++ b/apps/web/src/components/editor/AssetsPanel.tsx@@ -36,7 +36,7 @@ import { AspectRatioMatchDialog } from "./dialogs/AspectRatioMatchDialog";import { AIGenTab } from "./AIGenTab";import { useTtsAudioStore } from "../../stores/tts-store";import { toast } from "../../stores/notification-store";-import { saveFileHandle } from "../../services/media-storage";+import { saveFileHandle, saveDirectoryHandle } from "../../services/media-storage";import { IconButton, Input, ScrollArea } from "@openreel/ui";const formatDuration = (seconds: number): string => {@@ -563,29 +563,34 @@ export const AssetsPanel: React.FC = () => {return; // user cancelled}- const placeholders = useProjectStore.getState().project.mediaLibrary.items.filter(- (item) => item.isPlaceholder,- );+ const { project } = useProjectStore.getState();+ const placeholders = project.mediaLibrary.items.filter((item) => item.isPlaceholder);if (placeholders.length === 0) return;- // Build a filename → File map from the chosen folder (using entries() for name+handle pairs)- const fileMap = new Map<string, File>();+ // Persist the directory handle for future auto-restore+ try { await saveDirectoryHandle(project.id, dirHandle); } catch { /* best-effort */ }++ // Build a filename → {File, handle} map (keyed by lowercase name)+ const fileMap = new Map<string, { file: File; handle: FileSystemFileHandle }>();const entries = (dirHandle as unknown as { entries: () => AsyncIterableIterator<[string, FileSystemHandle]> }).entries();- for await (const [name, handle] of entries) {- if (handle.kind === "file") {- const file = await (handle as FileSystemFileHandle).getFile();- fileMap.set(name.toLowerCase(), file);+ for await (const [, fh] of entries) {+ if ((fh as FileSystemHandle).kind === "file") {+ const fileHandle = fh as FileSystemFileHandle;+ const file = await fileHandle.getFile();+ fileMap.set(file.name.toLowerCase(), { file, handle: fileHandle });}}setIsImporting(true);let linked = 0;for (const item of placeholders) {- const match = fileMap.get(item.name.toLowerCase());- if (match) {+ const entry = fileMap.get(item.name.toLowerCase());+ if (entry) {setImportProgress(`Relinking ${item.name}…`);try {- await replaceMediaAsset(item.id, match);+ // Save individual file handle for future auto-restore+ try { await saveFileHandle(entry.file.name, entry.file.size, entry.handle); } catch { /* best-effort */ }+ await replaceMediaAsset(item.id, entry.file, dirHandle.name);linked++;} catch (err) {console.error(`[AssetsPanel] Failed to relink ${item.name}:`, err);diff --git a/apps/web/src/services/media-storage.ts b/apps/web/src/services/media-storage.tsindex 2fa49369..c20ead39 100644--- a/apps/web/src/services/media-storage.ts+++ b/apps/web/src/services/media-storage.ts@@ -55,6 +55,14 @@ export async function loadFileHandle(name: string, size: number): Promise<FileSyreturn storage.loadFileHandle(name, size);}+export async function saveDirectoryHandle(projectId: string, handle: FileSystemDirectoryHandle): Promise<void> {+ await storage.saveDirectoryHandle(projectId, handle);+}++export async function loadDirectoryHandle(projectId: string): Promise<{ handle: FileSystemDirectoryHandle; folderName: string } | null> {+ return storage.loadDirectoryHandle(projectId);+}+export async function getStorageStats(): Promise<{used: number;quota: number;diff --git a/apps/web/src/stores/project-store.ts b/apps/web/src/stores/project-store.tsindex d139b8d6..5e74f837 100644--- a/apps/web/src/stores/project-store.ts+++ b/apps/web/src/stores/project-store.ts@@ -54,6 +54,7 @@ import {deleteMediaBlob,loadProjectMedia,loadFileHandle,+ loadDirectoryHandle,} from "../services/media-storage";import { restoreMediaItem } from "../utils/media-recovery";import { projectManager } from "../services/project-manager";@@ -104,7 +105,7 @@ export interface ProjectState {// Media library actionsimportMedia: (file: File) => Promise<ActionResult>;deleteMedia: (mediaId: string) => Promise<ActionResult>;- replaceMediaAsset: (mediaId: string, file: File) => Promise<ActionResult>;+ replaceMediaAsset: (mediaId: string, file: File, sourceFolder?: string) => Promise<ActionResult>;renameMedia: (mediaId: string, name: string) => Promise<ActionResult>;getMediaItem: (mediaId: string) => MediaItem | undefined;@@ -484,18 +485,49 @@ export const useProjectStore = create<ProjectState>()(if (placeholders.length > 0 && "FileSystemFileHandle" in window) {(async () => {let restored = 0;+ const stillMissing: typeof placeholders = [];++ // Tier 1: try individual file handles (follow file across folder moves)for (const item of placeholders) {if (!item.sourceFile) continue;try {const handle = await loadFileHandle(item.sourceFile.name, item.sourceFile.size);- if (!handle) continue;+ if (!handle) { stillMissing.push(item); continue; }const file = await handle.getFile();- await get().replaceMediaAsset(item.id, file);+ await get().replaceMediaAsset(item.id, file, item.sourceFile.folder);restored++;} catch {- // Handle stale or permission-denied — silently skip+ stillMissing.push(item); // stale handle}}++ // Tier 2: scan the stored relink folder for files not found via handle+ if (stillMissing.length > 0) {+ try {+ const dirInfo = await loadDirectoryHandle(fixedProject.id);+ if (dirInfo) {+ const fileMap = new Map<string, { file: File; folder: string }>();+ const entries = (dirInfo.handle as unknown as { entries: () => AsyncIterableIterator<[string, FileSystemHandle]> }).entries();+ for await (const [, fh] of entries) {+ if ((fh as FileSystemHandle).kind === "file") {+ const f = await (fh as FileSystemFileHandle).getFile();+ fileMap.set(`${f.name.toLowerCase()}:${f.size}`, { file: f, folder: dirInfo.folderName });+ }+ }+ for (const item of stillMissing) {+ if (!item.sourceFile) continue;+ const entry = fileMap.get(`${item.sourceFile.name.toLowerCase()}:${item.sourceFile.size}`);+ if (entry) {+ try {+ await get().replaceMediaAsset(item.id, entry.file, entry.folder);+ restored++;+ } catch { /* skip */ }+ }+ }+ }+ } catch { /* dir handle stale or unavailable */ }+ }+if (restored > 0) {console.info(`[ProjectStore] Auto-restored ${restored} asset(s) from file handles`);}@@ -739,7 +771,7 @@ export const useProjectStore = create<ProjectState>()(return result;},- replaceMediaAsset: async (mediaId: string, file: File) => {+ replaceMediaAsset: async (mediaId: string, file: File, sourceFolder?: string) => {const { project } = get();try {@@ -828,7 +860,7 @@ export const useProjectStore = create<ProjectState>()(filmstripThumbnails:filmstripThumbnails.length > 0 ? filmstripThumbnails : undefined,isPlaceholder: false,- sourceFile: { name: file.name, size: file.size, lastModified: file.lastModified },+ sourceFile: { name: file.name, size: file.size, lastModified: file.lastModified, folder: sourceFolder },};const updatedItems = project.mediaLibrary.items.map((item) =>diff --git a/packages/core/src/storage/storage-engine.ts b/packages/core/src/storage/storage-engine.tsindex 74641c37..a9b7ffec 100644--- a/packages/core/src/storage/storage-engine.ts+++ b/packages/core/src/storage/storage-engine.ts@@ -101,6 +101,10 @@ export class StorageEngine implements IStorageEngine {if (!db.objectStoreNames.contains(STORES.FILE_HANDLES)) {db.createObjectStore(STORES.FILE_HANDLES, { keyPath: "key" });}++ if (!db.objectStoreNames.contains(STORES.DIR_HANDLES)) {+ db.createObjectStore(STORES.DIR_HANDLES, { keyPath: "key" });+ }}/**@@ -414,6 +418,31 @@ export class StorageEngine implements IStorageEngine {});}+ async saveDirectoryHandle(projectId: string, handle: FileSystemDirectoryHandle): Promise<void> {+ const db = await this.getDb();+ return new Promise((resolve, reject) => {+ const tx = db.transaction(STORES.DIR_HANDLES, "readwrite");+ const store = tx.objectStore(STORES.DIR_HANDLES);+ const request = store.put({ key: projectId, handle, folderName: handle.name });+ request.onsuccess = () => resolve();+ request.onerror = () => reject(request.error);+ });+ }++ async loadDirectoryHandle(projectId: string): Promise<{ handle: FileSystemDirectoryHandle; folderName: string } | null> {+ const db = await this.getDb();+ return new Promise((resolve, reject) => {+ const tx = db.transaction(STORES.DIR_HANDLES, "readonly");+ const store = tx.objectStore(STORES.DIR_HANDLES);+ const request = store.get(projectId);+ request.onsuccess = () => {+ const rec = request.result as { handle: FileSystemDirectoryHandle; folderName: string } | undefined;+ resolve(rec ? { handle: rec.handle, folderName: rec.folderName } : null);+ };+ request.onerror = () => reject(request.error);+ });+ }+close(): void {if (this.db) {this.db.close();diff --git a/packages/core/src/storage/types.ts b/packages/core/src/storage/types.tsindex 495f7283..d2ce30bd 100644--- a/packages/core/src/storage/types.ts+++ b/packages/core/src/storage/types.ts@@ -1,6 +1,6 @@import type { Project, MediaMetadata } from "../types";-export const DB_VERSION = 2;+export const DB_VERSION = 3;export const DB_NAME = "openreel-db";@@ -10,6 +10,7 @@ export const STORES = {CACHE: "cache",WAVEFORMS: "waveforms",FILE_HANDLES: "fileHandles",+ DIR_HANDLES: "dirHandles",} as const;export interface ProjectRecord {@@ -53,6 +54,13 @@ export interface FileHandleRecord {readonly handle: FileSystemFileHandle;}+/** Keyed by projectId — stores the last folder the user relinked from, per project */+export interface DirHandleRecord {+ readonly key: string; // projectId+ readonly handle: FileSystemDirectoryHandle;+ readonly folderName: string;+}+export interface StorageUsage {readonly used: number;readonly quota: number;@@ -107,6 +115,8 @@ export interface IStorageEngine {// File handle operations (for cross-session asset restoration)saveFileHandle(name: string, size: number, handle: FileSystemFileHandle): Promise<void>;loadFileHandle(name: string, size: number): Promise<FileSystemFileHandle | null>;+ saveDirectoryHandle(projectId: string, handle: FileSystemDirectoryHandle): Promise<void>;+ loadDirectoryHandle(projectId: string): Promise<{ handle: FileSystemDirectoryHandle; folderName: string } | null>;// Storage infogetStorageUsage(): Promise<StorageUsage>;diff --git a/packages/core/src/types/project.ts b/packages/core/src/types/project.tsindex a0e262d1..e6f8552d 100644--- a/packages/core/src/types/project.ts+++ b/packages/core/src/types/project.ts@@ -41,7 +41,7 @@ export interface MediaItem {readonly isPlaceholder?: boolean;readonly originalUrl?: string;/** File hint stored in JSON for cross-session/cross-machine asset matching */- readonly sourceFile?: { name: string; size: number; lastModified: number };+ readonly sourceFile?: { name: string; size: number; lastModified: number; folder?: string };}/** Thumbnail for filmstrip display in timeline */diff --git a/start.sh b/start.shnew file mode 100755index 00000000..7038066a--- /dev/null+++ b/start.sh@@ -0,0 +1,21 @@+#!/bin/bash+# OpenReel Video - Local Development Start Script++set -e++echo "=== OpenReel Video - Dev Setup ==="++# Install dependencies if needed+if [ ! -d "node_modules" ]; then+ echo "Installing dependencies..."+ pnpm install+fi++# Build WASM modules if not built+if [ ! -d "packages/core/src/wasm/build" ]; then+ echo "Building WASM modules..."+ pnpm build:wasm+fi++echo "Starting dev server at http://localhost:5174"+pnpm dev -- --port 5174