feat(editor): bridge the advanced photo editor into the event workflow
CI / build (push) Has been cancelled
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:
@@ -0,0 +1,67 @@
|
||||
import type { PhotoRecord } from '../types';
|
||||
import { getAsset, putAsset } from './db';
|
||||
|
||||
const CACHE_LIMIT = 6;
|
||||
const cache = new Map<string, ImageBitmap>();
|
||||
|
||||
/** 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`;
|
||||
return `/api/photos/${encodeURIComponent(photo.id)}/original`;
|
||||
}
|
||||
|
||||
async function fetchRemote(photo: PhotoRecord): Promise<Blob | null> {
|
||||
try {
|
||||
const res = await fetch(remoteAssetUrl(photo), { credentials: 'same-origin' });
|
||||
if (!res.ok) return null;
|
||||
const blob = await res.blob();
|
||||
// Cache it locally so the photo keeps working offline after the first look.
|
||||
await putAsset(photo.id, blob).catch(() => undefined);
|
||||
return blob;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export async function getBitmap(photo: PhotoRecord): Promise<ImageBitmap> {
|
||||
const hit = cache.get(photo.id);
|
||||
if (hit) {
|
||||
cache.delete(photo.id);
|
||||
cache.set(photo.id, hit);
|
||||
return hit;
|
||||
}
|
||||
|
||||
let blob = await getAsset(photo.id);
|
||||
if (!blob) blob = (await fetchRemote(photo)) ?? undefined;
|
||||
if (!blob) {
|
||||
throw new Error(
|
||||
photo.raw
|
||||
? 'This raw file has no editable proxy yet. Sign in to the server and sync to fetch it.'
|
||||
: 'Original image data is missing from browser storage',
|
||||
);
|
||||
}
|
||||
|
||||
// Apply EXIF orientation so the pixels the editor works on are upright.
|
||||
const bitmap = await createImageBitmap(blob, { imageOrientation: 'from-image' });
|
||||
cache.set(photo.id, bitmap);
|
||||
while (cache.size > CACHE_LIMIT) {
|
||||
const first = cache.keys().next();
|
||||
if (first.done) break;
|
||||
const old = cache.get(first.value);
|
||||
cache.delete(first.value);
|
||||
old?.close();
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
export function evictBitmap(photoId: string) {
|
||||
const bmp = cache.get(photoId);
|
||||
if (!bmp) return;
|
||||
cache.delete(photoId);
|
||||
bmp.close();
|
||||
}
|
||||
|
||||
export function clearBitmapCache() {
|
||||
for (const bmp of cache.values()) bmp.close();
|
||||
cache.clear();
|
||||
}
|
||||
Reference in New Issue
Block a user