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
+116
View File
@@ -0,0 +1,116 @@
/**
* Signed hand-off tokens for the advanced editor bridge.
*
* The app never hands Lumenroom a password. Instead it mints a short-lived
* token scoped to one user and one event; Lumenroom verifies it with the same
* `BRIDGE_SECRET`, exchanges it for a longer service token, and uses that token
* for the server-to-server photo and save-back calls.
*/
import { createHmac, timingSafeEqual } from "node:crypto";
const VERSION = "g1";
export interface BridgeTokenPayload {
/** Bridge session row id. */
sid: string;
/** Event id the token is limited to. */
eid: string;
/** Glenloch user id. */
uid: string;
email: string;
name: string;
/** `login` is the one browser hop; `service` is used server-to-server. */
kind: "login" | "service";
/** Unix seconds. */
exp: number;
}
export const BRIDGE_LOGIN_TTL_SECONDS = 10 * 60;
export const BRIDGE_SESSION_TTL_SECONDS = 12 * 60 * 60;
function secret(): string | null {
return process.env.BRIDGE_SECRET?.trim() || null;
}
/** Advanced editing needs both a shared secret and somewhere to send the user. */
export function bridgeConfigured(): boolean {
return Boolean(secret() && advancedEditorUrl());
}
export function advancedEditorUrl(): string | null {
const url = process.env.LUMENROOM_URL?.trim();
return url ? url.replace(/\/+$/, "") : null;
}
function base64url(value: Buffer | string): string {
return Buffer.from(value)
.toString("base64")
.replace(/\+/g, "-")
.replace(/\//g, "_")
.replace(/=+$/, "");
}
function fromBase64url(value: string): Buffer {
return Buffer.from(value.replace(/-/g, "+").replace(/_/g, "/"), "base64");
}
function sign(body: string): Buffer {
return createHmac("sha256", secret() ?? "").update(body).digest();
}
export function signBridgeToken(payload: BridgeTokenPayload): string {
const body = base64url(JSON.stringify(payload));
return `${VERSION}.${body}.${base64url(sign(body))}`;
}
/** Null when the token is malformed, signed with another secret, or expired. */
export function verifyBridgeToken(
token: string | null | undefined,
now: number = Date.now(),
): BridgeTokenPayload | null {
if (!token) return null;
const parts = token.split(".");
if (parts.length !== 3 || parts[0] !== VERSION) return null;
const [, body, signature] = parts;
const expected = sign(body);
let supplied: Buffer;
try {
supplied = fromBase64url(signature);
} catch {
return null;
}
if (supplied.length !== expected.length) return null;
if (!timingSafeEqual(supplied, expected)) return null;
let parsed: unknown;
try {
parsed = JSON.parse(fromBase64url(body).toString("utf8"));
} catch {
return null;
}
if (!parsed || typeof parsed !== "object") return null;
const payload = parsed as Partial<BridgeTokenPayload>;
if (
typeof payload.sid !== "string" ||
typeof payload.eid !== "string" ||
typeof payload.uid !== "string" ||
typeof payload.email !== "string" ||
typeof payload.name !== "string" ||
(payload.kind !== "login" && payload.kind !== "service") ||
typeof payload.exp !== "number"
) {
return null;
}
if (payload.exp * 1000 <= now) return null;
return payload as BridgeTokenPayload;
}
/** Where the advanced editor sends a user back to after finishing. */
export function bridgeReturnUrl(eventId: string): string | null {
const origin = process.env.NEXTAUTH_URL?.trim();
if (!origin) return null;
return `${origin.replace(/\/+$/, "")}/events/${eventId}`;
}