feat(editor): bridge the advanced photo editor into the event workflow
CI / build (push) Has been cancelled

Event photos can now be opened in Lumenroom, a WebGL2 develop module, from the
photo editor's Advanced button. The dashboard signs a short-lived token scoped
to one user and event; Lumenroom exchanges it, imports the event's photo list
and proxies bytes on demand, so nothing is copied and the temporary catalog
expires with the bridge session. Saving in Lumenroom renders the photo and
writes it back as the event's edited JPEG, with the advanced recipe kept in
event_photos.advanced_edit_json.

Lumenroom is vendored under lumenroom/ and built as a second compose service,
so one clone and `docker compose up -d --build` deploys both apps.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
2026-11-21 01:34:20 +00:00
parent 982f9048e1
commit 0cb315ea88
89 changed files with 22087 additions and 1 deletions
+224
View File
@@ -0,0 +1,224 @@
import { useEffect, useRef, useState } from 'react';
import type { CloudImport, ImportProgress } from '../lib/import';
import { importFiles, isSupportedFile } from '../lib/import';
import { isRawFile, RAW_ACCEPT } from '../lib/raw';
import type { EventRecord, PhotoRecord } from '../types';
interface Props {
events: EventRecord[];
initialEventId: string;
initialFiles: File[];
onClose: () => void;
onImported: (photos: PhotoRecord[], eventId: string) => void;
onCreateEvent: (name: string) => Promise<EventRecord>;
cloud?: CloudImport | null;
onNeedServer: () => void;
}
export default function ImportModal({
events,
initialEventId,
initialFiles,
onClose,
onImported,
onCreateEvent,
cloud,
onNeedServer,
}: Props) {
const startId = initialEventId !== 'all' && initialEventId !== 'unsorted' ? initialEventId : events[0]?.id ?? '__new';
const [eventId, setEventId] = useState(startId);
const [newName, setNewName] = useState('');
const [files, setFiles] = useState<File[]>(initialFiles);
const [dragOver, setDragOver] = useState(false);
const [busy, setBusy] = useState(false);
const [progress, setProgress] = useState<ImportProgress | null>(null);
const [failures, setFailures] = useState<string[]>([]);
const inputRef = useRef<HTMLInputElement>(null);
const rawCount = files.filter(isRawFile).length;
useEffect(() => {
// Capture phase: Escape closes this dialog even while a photo is open behind it.
const onKey = (e: KeyboardEvent) => {
if (e.key !== 'Escape') return;
e.preventDefault();
e.stopImmediatePropagation();
if (!busy) onClose();
};
window.addEventListener('keydown', onKey, true);
return () => window.removeEventListener('keydown', onKey, true);
}, [busy, onClose]);
const addFiles = (list: FileList | null) => {
if (!list) return;
const incoming = Array.from(list).filter(isSupportedFile);
setFiles((prev) => {
const seen = new Set(prev.map((f) => `${f.name}:${f.size}`));
return [...prev, ...incoming.filter((f) => !seen.has(`${f.name}:${f.size}`))];
});
};
const run = async () => {
if (!files.length || busy) return;
setBusy(true);
setFailures([]);
try {
let targetId = eventId;
if (targetId === '__new') {
const created = await onCreateEvent(newName || `Event ${new Date().toLocaleDateString()}`);
targetId = created.id;
}
const result = await importFiles(files, targetId, [], setProgress, cloud ?? null);
if (result.photos.length) onImported(result.photos, targetId);
if (result.failed.length) {
setFailures(result.failed.map((f) => `${f.name} — ${f.reason}`));
setBusy(false);
setFiles([]);
setProgress(null);
if (result.photos.length) setTimeout(onClose, 1200);
} else {
onClose();
}
} catch (err) {
setFailures([err instanceof Error ? err.message : 'Import failed']);
setBusy(false);
}
};
return (
<div className="modal-backdrop" onPointerDown={(e) => e.target === e.currentTarget && !busy && onClose()}>
<div className="modal">
<header className="modal-head">
<h2>Import photos</h2>
<button className="icon-btn" onClick={onClose} disabled={busy}>
✕
</button>
</header>
<div className="modal-body">
<label className="field">
<span>Event / album</span>
<select value={eventId} onChange={(e) => setEventId(e.target.value)} disabled={busy}>
{events.map((ev) => (
<option key={ev.id} value={ev.id}>
{ev.name}
</option>
))}
<option value="__new">+ New event…</option>
</select>
</label>
{eventId === '__new' && (
<label className="field">
<span>New event name</span>
<input
value={newName}
placeholder={`Event ${new Date().toLocaleDateString()}`}
onChange={(e) => setNewName(e.target.value)}
disabled={busy}
/>
</label>
)}
<div
className={`dropzone ${dragOver ? 'over' : ''}`}
onDragOver={(e) => {
e.preventDefault();
setDragOver(true);
}}
onDragLeave={() => setDragOver(false)}
onDrop={(e) => {
e.preventDefault();
setDragOver(false);
addFiles(e.dataTransfer.files);
}}
onClick={() => inputRef.current?.click()}
>
<div className="dropzone-icon">⤒</div>
<div>
<strong>Drop photos here</strong>
<p className="muted">
or click to choose files. JPEG, PNG, WebP, AVIF, TIFF and camera raw (CR2, CR3, NEF,
ARW, ORF, RW2, RAF, DNG, PEF…) — raw needs the team server.
</p>
</div>
<input
ref={inputRef}
type="file"
accept={`image/*,${RAW_ACCEPT}`}
multiple
hidden
onChange={(e) => addFiles(e.target.files)}
/>
</div>
{files.length > 0 && (
<div className="file-summary">
<span>
{files.length} file{files.length === 1 ? '' : 's'} ready ·{' '}
{(files.reduce((sum, f) => sum + f.size, 0) / (1024 * 1024)).toFixed(1)} MB
{rawCount > 0 ? ` · ${rawCount} raw` : ''}
</span>
<button className="link-btn" onClick={() => setFiles([])} disabled={busy}>
Clear
</button>
</div>
)}
{rawCount > 0 && !cloud && (
<div className="banner warn">
<strong>
{rawCount} raw file{rawCount === 1 ? '' : 's'} cannot be read by the browser.
</strong>{' '}
They are decoded by the team server, so sign in before importing — or import them later
from the library.
<button className="btn primary small banner-action" onClick={onNeedServer} disabled={busy}>
Sign in to the server
</button>
</div>
)}
{rawCount > 0 && cloud && (
<div className="banner info">
Raw files are demosaiced by the server (LibRaw), a few at a time in parallel. Each file
usually takes 2–4 seconds.
</div>
)}
{progress && (
<div className="progress">
<div className="progress-bar">
<div
className="progress-fill"
style={{ width: `${progress.total ? (progress.done / progress.total) * 100 : 0}%` }}
/>
</div>
<div className="muted small">
{progress.done} / {progress.total} {progress.current ? `· ${progress.current}` : ''}
</div>
</div>
)}
{failures.length > 0 && (
<div className="failures">
<strong>Some files could not be imported</strong>
<ul>
{failures.map((f) => (
<li key={f}>{f}</li>
))}
</ul>
</div>
)}
</div>
<footer className="modal-foot">
<button className="btn ghost" onClick={onClose} disabled={busy}>
Cancel
</button>
<button className="btn primary" onClick={() => void run()} disabled={busy || !files.length}>
{busy ? 'Importing…' : `Import ${files.length || ''}`}
</button>
</footer>
</div>
</div>
);
}