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:
@@ -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(),
|
||||
);
|
||||
|
||||
@@ -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 }) => {
|
||||
|
||||
@@ -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())));
|
||||
|
||||
@@ -653,15 +653,22 @@ export default function App() {
|
||||
height: activePhoto.height,
|
||||
}),
|
||||
});
|
||||
const data = (await res.json().catch(() => ({}))) as { error?: string };
|
||||
const data = (await res.json().catch(() => ({}))) as {
|
||||
error?: string;
|
||||
thumbVersion?: number;
|
||||
};
|
||||
if (!res.ok) throw new Error(data.error || 'The photo could not be saved');
|
||||
if (typeof data.thumbVersion === 'number') {
|
||||
// Refresh the grid thumbnail so it shows this render, not the original.
|
||||
updatePhoto(activePhoto.id, { thumbVersion: data.thumbVersion });
|
||||
}
|
||||
setToast(`Saved ${activePhoto.name} to the event`);
|
||||
} catch (err) {
|
||||
setToast(err instanceof Error ? err.message : 'The photo could not be saved');
|
||||
} finally {
|
||||
setBridgeBusy(false);
|
||||
}
|
||||
}, [activePhoto, bridgeEvent]);
|
||||
}, [activePhoto, bridgeEvent, updatePhoto]);
|
||||
|
||||
const handleCloudLogin = useCallback(
|
||||
async (email: string, password: string) => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { ASPECTS, defaultEdits, thumbTransform } from '../lib/edits';
|
||||
import { getBitmap } from '../lib/images';
|
||||
import { getBitmap, thumbSrc } from '../lib/images';
|
||||
import { rotatedBounds, Renderer } from '../gl/renderer';
|
||||
import type { Edits, EventRecord, PhotoRecord, Preset } from '../types';
|
||||
import ContextMenu, { type MenuEntry } from './ContextMenu';
|
||||
@@ -703,7 +703,7 @@ export default function Develop({
|
||||
title={p.name}
|
||||
>
|
||||
<img
|
||||
src={p.thumbUrl ?? p.thumb}
|
||||
src={thumbSrc(p)}
|
||||
alt={p.name}
|
||||
loading="lazy"
|
||||
draggable={false}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useRef, useState } from 'react';
|
||||
import { COLOR_LABELS, isEdited, thumbTransform } from '../lib/edits';
|
||||
import { draggedPhotoIds, endDrag, PHOTO_DRAG, startPhotoDrag } from '../lib/drag';
|
||||
import { thumbSrc } from '../lib/images';
|
||||
import type { ColorLabel, Flag, PhotoRecord } from '../types';
|
||||
import Stars, { ColorSwatches, FlagButtons } from './Stars';
|
||||
|
||||
@@ -312,7 +313,7 @@ export default function LibraryGrid({
|
||||
>
|
||||
<div className="card-thumb">
|
||||
<img
|
||||
src={p.thumbUrl ?? p.thumb}
|
||||
src={thumbSrc(p)}
|
||||
alt={p.name}
|
||||
loading="lazy"
|
||||
draggable={false}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { computeAutoEdits } from '../lib/auto';
|
||||
import { clamp } from '../lib/curves';
|
||||
import type { CurveChannel, Edits, EventRecord, HistoryEntry, PhotoRecord, Preset } from '../types';
|
||||
import CurveEditor from './CurveEditor';
|
||||
import { getBitmap } from '../lib/images';
|
||||
import { getBitmap, thumbSrc } from '../lib/images';
|
||||
import { grainSampleWindow, rotatedBounds, Renderer } from '../gl/renderer';
|
||||
import { applyFilmVariant, FILM_VARIANTS, type FilmVariant } from '../lib/presets';
|
||||
import { usePresetThumbs } from './PresetThumbs';
|
||||
@@ -653,7 +653,7 @@ export function NavigatorPanel({ photo }: { photo: PhotoRecord }) {
|
||||
</div>
|
||||
<div className="navigator-thumb">
|
||||
<img
|
||||
src={photo.thumbUrl ?? photo.thumb}
|
||||
src={thumbSrc(photo)}
|
||||
alt={photo.name}
|
||||
style={{ transform: thumbTransform(photo) }}
|
||||
/>
|
||||
|
||||
@@ -266,6 +266,7 @@ export function normalizePhoto(input: Partial<PhotoRecord> & { id: string }): Ph
|
||||
decode: input.decode,
|
||||
previewUrl: input.previewUrl,
|
||||
thumbUrl: input.thumbUrl,
|
||||
thumbVersion: input.thumbVersion,
|
||||
name: input.name ?? 'Untitled',
|
||||
width: input.width ?? 0,
|
||||
height: input.height ?? 0,
|
||||
|
||||
@@ -4,6 +4,17 @@ import { getAsset, putAsset } from './db';
|
||||
const CACHE_LIMIT = 6;
|
||||
const cache = new Map<string, ImageBitmap>();
|
||||
|
||||
/**
|
||||
* Grid/filmstrip thumbnail URL. The version stamp changes when the saved edit is
|
||||
* re-rendered, so the browser does not keep showing the pre-edit thumbnail.
|
||||
*/
|
||||
export function thumbSrc(photo: PhotoRecord): string {
|
||||
if (!photo.thumbUrl) return photo.thumb;
|
||||
return photo.thumbVersion
|
||||
? `${photo.thumbUrl}?v=${photo.thumbVersion}`
|
||||
: photo.thumbUrl;
|
||||
}
|
||||
|
||||
/** Where to fetch the original (or raw proxy) when it is not cached on this device. */
|
||||
export function remoteAssetUrl(photo: PhotoRecord): string {
|
||||
if (photo.raw) return photo.previewUrl || `/api/photos/${encodeURIComponent(photo.id)}/preview`;
|
||||
|
||||
@@ -562,6 +562,9 @@ img {
|
||||
overflow-y: auto;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
||||
/* Keep every row at its natural height. Without this, a large library makes
|
||||
the auto rows shrink to fit the viewport and the thumbnails collapse. */
|
||||
grid-auto-rows: max-content;
|
||||
gap: 12px;
|
||||
padding: 14px;
|
||||
align-content: start;
|
||||
|
||||
@@ -103,6 +103,8 @@ export interface PhotoRecord {
|
||||
previewUrl?: string;
|
||||
/** server URL for the grid thumbnail */
|
||||
thumbUrl?: string;
|
||||
/** bumps the thumbnail URL whenever the saved edit is re-rendered */
|
||||
thumbVersion?: number;
|
||||
/** Set when the photo is proxied from a dashboard bridge session. */
|
||||
bridgeSource?: { sessionId: string; sourceId: string };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user