Skip to content

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 Relink from Folder and post-import missing-asset toast

lvalics733717b2f7ec
diff --git a/apps/web/src/components/editor/AssetsPanel.tsx b/apps/web/src/components/editor/AssetsPanel.tsx
index d0a3c61c..9c018705 100644
--- a/apps/web/src/components/editor/AssetsPanel.tsx
+++ b/apps/web/src/components/editor/AssetsPanel.tsx
@@ -512,6 +512,57 @@ export const AssetsPanel: React.FC = () => {
[replaceMediaAsset],
);
+ const handleRelinkFromFolder = useCallback(async () => {
+ if (!("showDirectoryPicker" in window)) {
+ toast.error("Folder picker not supported", "Please relink assets individually using the refresh button on each missing asset.");
+ return;
+ }
+ let dirHandle: FileSystemDirectoryHandle;
+ try {
+ dirHandle = await (window as unknown as { showDirectoryPicker: () => Promise<FileSystemDirectoryHandle> }).showDirectoryPicker();
+ } catch {
+ return; // user cancelled
+ }
+
+ const placeholders = useProjectStore.getState().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>();
+ 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);
+ }
+ }
+
+ setIsImporting(true);
+ let linked = 0;
+ for (const item of placeholders) {
+ const match = fileMap.get(item.name.toLowerCase());
+ if (match) {
+ setImportProgress(`Relinking ${item.name}…`);
+ try {
+ await replaceMediaAsset(item.id, match);
+ linked++;
+ } catch (err) {
+ console.error(`[AssetsPanel] Failed to relink ${item.name}:`, err);
+ }
+ }
+ }
+ setIsImporting(false);
+ setImportProgress("");
+
+ if (linked > 0) {
+ toast.success(`Relinked ${linked} of ${placeholders.length} asset${placeholders.length !== 1 ? "s" : ""}`);
+ } else {
+ toast.error("No matches found", "None of the files in the selected folder matched the missing assets by filename.");
+ }
+ }, [replaceMediaAsset]);
+
// Handle drag start for timeline placement
const handleItemDragStart = useCallback(
(e: React.DragEvent, item: MediaItem) => {
@@ -752,6 +803,13 @@ export const AssetsPanel: React.FC = () => {
{missingAssetsCount}
</div>
</button>
+ <button
+ onClick={handleRelinkFromFolder}
+ className="w-full px-3 py-2 rounded-lg border border-yellow-500/40 bg-yellow-500/5 text-yellow-500 text-xs font-medium transition-all hover:bg-yellow-500/15 flex items-center gap-2"
+ >
+ <RefreshCw size={14} />
+ <span>Relink from Folder…</span>
+ </button>
</div>
)}
diff --git a/apps/web/src/components/editor/ScriptViewDialog.tsx b/apps/web/src/components/editor/ScriptViewDialog.tsx
index ab6ba107..8cee5450 100644
--- a/apps/web/src/components/editor/ScriptViewDialog.tsx
+++ b/apps/web/src/components/editor/ScriptViewDialog.tsx
@@ -20,6 +20,7 @@ import {
Button,
} from "@openreel/ui";
import { useProjectStore } from "../../stores/project-store";
+import { toast } from "../../stores/notification-store";
import { createProjectSerializer, createStorageEngine } from "@openreel/core";
import type { ValidationResult } from "@openreel/core/storage/schema-types";
@@ -176,6 +177,15 @@ export const ScriptViewDialog: React.FC<ScriptViewDialogProps> = ({
if (importedProject) {
useProjectStore.getState().loadProject(importedProject);
onClose();
+ const missingCount = importedProject.mediaLibrary.items.filter(
+ (item) => item.isPlaceholder,
+ ).length;
+ if (missingCount > 0) {
+ toast.warning(
+ `${missingCount} asset${missingCount !== 1 ? "s" : ""} need relinking`,
+ "Go to Assets panel → click \"Relink from Folder\" to restore missing media.",
+ );
+ }
}
} catch (error) {
setValidation({