feat(editor): finish the quick/advanced editor handoff
CI / build (push) Has been cancelled

Reopen advanced edits from their saved recipe, seed or take over the quick
editor from them, refresh thumbnails after a save, and add an edited-only
download. Also fixes the Lumenroom library collapsing to slivers on large
shoots and documents deploying both containers on a new host.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
This commit is contained in:
2026-11-21 06:35:24 +00:00
parent ab4a07a40f
commit ebe0c77f7e
35 changed files with 1844 additions and 150 deletions
+36 -7
View File
@@ -9,7 +9,7 @@
import crypto from 'node:crypto';
import { BRIDGE_SECRET, BRIDGE_TTL_HOURS, GLENLOCH_URL } from './config.mjs';
import { db, removeEvent, removePhoto, saveEvent, savePhoto } from './db.mjs';
import { db, getPhoto, removeEvent, removePhoto, saveEvent, savePhoto } from './db.mjs';
import { removeAsset } from './storage.mjs';
const VERSION = 'g1';
@@ -173,11 +173,17 @@ function photoRecordFrom(photo, eventId, sessionId, index) {
meta: {},
thumb: '',
thumbUrl: `/api/photos/${id}/thumb`,
// Thumbnail of the saved edit; the timestamp keeps the browser from reusing
// a thumbnail rendered before the edit was saved.
thumbVersion: photo.editedAt ? Date.parse(photo.editedAt) || undefined : undefined,
rating: 0,
flag: 'none',
color: '',
keywords: [],
edits: {},
// The dashboard sends back the recipe saved for this photo, so reopening
// the advanced editor starts from the sliders the user left it with.
edits:
photo.edits && typeof photo.edits === 'object' ? photo.edits : {},
history: [],
raw,
previewUrl: raw ? `/api/photos/${id}/preview` : undefined,
@@ -189,7 +195,7 @@ function photoRecordFrom(photo, eventId, sessionId, index) {
* Mirrors one event into the local catalog. The photo bytes stay on the
* dashboard; only metadata, previews and thumbnails are temporary here.
*/
export async function importBridgeEvent({ serviceToken, sessionId }) {
export async function importBridgeEvent({ serviceToken, sessionId, returnUrl }) {
const expiresAt =
Date.now() + Math.max(1, BRIDGE_TTL_HOURS) * 60 * 60 * 1000;
@@ -198,12 +204,35 @@ export async function importBridgeEvent({ serviceToken, sessionId }) {
serviceToken,
);
const eventId = bridgeEventId(listing.event.id);
// Preserve anything still unsaved locally before the import replaces rows, so
// reopening the editor never discards work in progress.
const localEdits = new Map();
for (const row of photosForEvent.all(eventId)) {
const record = getPhoto(row.id);
if (record?.edits && Object.keys(record.edits).length > 0) {
localEdits.set(row.id, record);
}
}
dropBridgeEvent(eventId);
const returnUrl = listing.editor?.returnUrl ?? null;
saveEvent(eventRecordFrom(listing, eventId, sessionId, returnUrl, expiresAt), 0);
// The exchange hands back the dashboard address the browser actually used;
// the listing's value is a fallback derived from server configuration and may
// point at localhost in a LAN deployment.
const dashboardReturn =
typeof returnUrl === 'string' && /^https?:\/\//i.test(returnUrl)
? returnUrl
: listing.editor?.returnUrl ?? null;
saveEvent(eventRecordFrom(listing, eventId, sessionId, dashboardReturn, expiresAt), 0);
listing.photos.forEach((photo, index) => {
savePhoto(photoRecordFrom(photo, eventId, sessionId, index));
const record = photoRecordFrom(photo, eventId, sessionId, index);
const local = localEdits.get(record.id);
if (local) {
record.edits = local.edits;
if (Array.isArray(local.history) && local.history.length > 0) {
record.history = local.history;
}
}
savePhoto(record);
});
bridgeInsert.run(
eventId,
@@ -211,7 +240,7 @@ export async function importBridgeEvent({ serviceToken, sessionId }) {
serviceToken,
GLENLOCH_URL,
listing.event.id,
returnUrl,
dashboardReturn,
expiresAt,
Date.now(),
);
+13 -1
View File
@@ -39,6 +39,7 @@ import {
findPreview,
findThumb,
removeAsset,
removeThumb,
storageBytes,
writeOriginal,
writePreview,
@@ -302,6 +303,7 @@ route('GET', '/api/bridge/login', async ({ req, res, url }) => {
const imported = await importBridgeEvent({
serviceToken: service.token,
sessionId: payload.sid,
returnUrl: service.returnUrl,
});
const sessionToken = createSession(row.id);
res.writeHead(302, {
@@ -459,7 +461,17 @@ route('POST', '/api/bridge/export', async ({ req, res }) => {
if (result.status >= 400) {
return error(res, result.status, result.body?.error || 'The edit could not be saved to the event');
}
return json(res, 200, result.body ?? { ok: true });
// The grid now shows the dashboard's thumbnail of this render, so drop the
// cached copy and bump the URL the browser asks for.
await removeThumb(body.photoId).catch(() => undefined);
const thumbVersion = Date.now();
const stored = getPhoto(body.photoId);
if (stored) {
stored.thumbVersion = thumbVersion;
savePhoto(stored);
}
return json(res, 200, { ...(result.body ?? { ok: true }), thumbVersion });
});
route('PUT', '/api/photos/:id', async ({ req, res, params }) => {
+6
View File
@@ -70,6 +70,12 @@ export function findThumb(id) {
return fs.existsSync(p) ? p : null;
}
/** Drops the cached grid thumbnail so the next request refetches it. */
export async function removeThumb(id) {
const thumb = findThumb(id);
if (thumb) await fsp.rm(thumb, { force: true });
}
export async function removeAsset(id) {
const files = [findOriginal(id), findPreview(id), findThumb(id)];
await Promise.all(files.map((f) => (f ? fsp.rm(f, { force: true }) : Promise.resolve())));