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
@@ -2,6 +2,7 @@ import { NextRequest } from "next/server";
import { authenticateBridge } from "@/db/bridge";
import {
BRIDGE_SESSION_TTL_SECONDS,
bridgeReturnUrl,
signBridgeToken,
} from "@/lib/bridge";
import { errorResponse, jsonResponse } from "@/lib/http";
@@ -36,5 +37,9 @@ export const POST = async (
sessionId: auth.session.id,
eventId: auth.session.eventId,
expiresAt: auth.session.expiresAt,
// Carried from the browser-facing request that opened the editor so the
// editor can link back to the address the user actually reached.
returnUrl:
auth.payload.ret ?? bridgeReturnUrl(auth.session.eventId) ?? null,
});
};
@@ -4,11 +4,17 @@ import { mkdir, rename, unlink, writeFile } from "node:fs/promises";
import path from "node:path";
import { authenticateBridge, getBridgePhoto, saveBridgeRender } from "@/db/bridge";
import {
advancedStoredNameForEventPhoto,
editedStoredNameForEventPhoto,
eventPhotoPath,
} from "@/lib/event-photos";
import { errorResponse, jsonResponse } from "@/lib/http";
import { mediaStorage } from "@/lib/media-storage";
import {
defaultPhotoAdjustments,
parseStoredPhotoAdjustments,
} from "@/lib/photo-adjustments";
import { renderPhotoJpeg } from "@/lib/photo-render";
const MAX_BODY_BYTES = 64 * 1024 * 1024;
const MAX_RECIPE_BYTES = 512 * 1024;
@@ -19,9 +25,10 @@ const MAX_JPEG_BYTES = 48 * 1024 * 1024;
* Body: { jpeg: <base64>, edits: <advanced recipe>, width, height }
*
* The advanced editor renders in the browser, so the server only has to store
* the result. The JPEG becomes the photo's edited version (used by the gallery,
* thumbnails and delivery exports) and the recipe is kept so the editor can be
* reopened with its sliders intact.
* the result. The JPEG is kept as the photo's advanced render (its own file, so
* the simple editor can layer on top) and the recipe is kept so the editor can
* be reopened with its sliders intact. Any simple-editor layer is rebuilt on
* top of the new render, so the two editors never disagree.
*/
export const POST = async (
req: NextRequest,
@@ -70,11 +77,11 @@ export const POST = async (
const storage = await mediaStorage();
if (!storage.ok) return errorResponse(503, storage.message);
const storedName = editedStoredNameForEventPhoto(
const advancedStoredName = advancedStoredNameForEventPhoto(
auth.session.eventId,
photo.id,
);
const target = eventPhotoPath(storage.root, storedName);
const target = eventPhotoPath(storage.root, advancedStoredName);
const temporary = `${target}.${randomUUID()}.tmp`;
try {
await mkdir(path.dirname(target), { recursive: true });
@@ -85,10 +92,40 @@ export const POST = async (
return errorResponse(500, "the edited image could not be saved");
}
// A photo the simple editor also adjusted keeps that layer: re-render it on
// the new advanced render so the saved JPEG still shows both recipes.
const quick = parseStoredPhotoAdjustments(photo.editJson);
const hasQuickLayer =
JSON.stringify(quick) !== JSON.stringify(defaultPhotoAdjustments());
let editedStoredName = advancedStoredName;
let editedSizeBytes = data.byteLength;
if (hasQuickLayer) {
editedStoredName = editedStoredNameForEventPhoto(auth.session.eventId, photo.id);
const layered = eventPhotoPath(storage.root, editedStoredName);
try {
const rendered = await renderPhotoJpeg({
filePath: target,
kind: "image",
adjustments: quick,
});
await mkdir(path.dirname(layered), { recursive: true });
const layeredTemporary = `${layered}.${randomUUID()}.tmp`;
await writeFile(layeredTemporary, rendered.data);
await rename(layeredTemporary, layered);
editedSizeBytes = rendered.data.byteLength;
} catch (error) {
console.error("simple edit layer rebuild failed", error);
return errorResponse(
500,
"the simple editor's adjustments could not be rebuilt on the new render",
);
}
}
const editedAt = await saveBridgeRender({
photoId: photo.id,
editedStoredName: storedName,
editedSizeBytes: data.byteLength,
editedStoredName,
editedSizeBytes,
advancedEditJson: recipe,
editedBy: auth.user.id,
});
@@ -100,6 +137,6 @@ export const POST = async (
return jsonResponse({
ok: true,
editedAt,
editedSizeBytes: data.byteLength,
editedSizeBytes,
});
};
@@ -4,9 +4,9 @@ import { createReadStream } from "node:fs";
import { mkdir, readFile, rename, stat, writeFile } from "node:fs/promises";
import path from "node:path";
import { Readable } from "node:stream";
import sharp from "sharp";
import { authenticateBridge, getBridgePhoto } from "@/db/bridge";
import {
bridgeEditedThumbStoredNameForEventPhoto,
bridgeProxyStoredNameForEventPhoto,
bridgeThumbStoredNameForEventPhoto,
eventPhotoPath,
@@ -14,7 +14,7 @@ import {
import { errorResponse } from "@/lib/http";
import { mediaStorage } from "@/lib/media-storage";
import { defaultPhotoAdjustments } from "@/lib/photo-adjustments";
import { renderPhotoJpeg } from "@/lib/photo-render";
import { renderPhotoJpeg, renderPhotoThumbnail } from "@/lib/photo-render";
const PROXY_MAX_EDGE = 4000;
const THUMB_MAX_EDGE = 480;
@@ -31,14 +31,25 @@ function imageResponse(data: Buffer, contentType = "image/jpeg"): Response {
});
}
/** Reads a cached derivative or writes it atomically on first use. */
/**
* Reads a cached derivative or writes it atomically on first use. When
* `newerThan` is given, a cache older than that timestamp is rebuilt, so a
* thumbnail of a re-rendered edit never goes stale.
*/
async function cached(
filePath: string,
produce: () => Promise<Buffer>,
newerThan?: number,
): Promise<Buffer> {
try {
const info = await stat(filePath);
if (info.isFile() && info.size > 0) return readFile(filePath);
if (
info.isFile() &&
info.size > 0 &&
(newerThan === undefined || info.mtimeMs >= newerThan)
) {
return readFile(filePath);
}
} catch {
// Not generated yet.
}
@@ -51,24 +62,12 @@ async function cached(
}
async function thumbFor(filePath: string, kind: "raw" | "image") {
if (kind === "raw") {
const rendered = await renderPhotoJpeg({
filePath,
kind,
adjustments: defaultPhotoAdjustments(),
maxDimension: THUMB_MAX_EDGE,
});
return rendered.data;
}
return sharp(filePath)
.resize({
width: THUMB_MAX_EDGE,
height: THUMB_MAX_EDGE,
fit: "inside",
withoutEnlargement: true,
})
.jpeg({ quality: 82, mozjpeg: true })
.toBuffer();
return renderPhotoThumbnail({
filePath,
kind,
maxDimension: THUMB_MAX_EDGE,
quality: 82,
});
}
/**
@@ -126,13 +125,33 @@ export const GET = async (
}
if (variant === "thumb") {
// With a saved edit, the grid should show the photo as it was developed —
// the editor's own look — not the untouched original.
let sourcePath = originalPath;
let sourceKind: "raw" | "image" = photo.kind;
let thumbName = bridgeThumbStoredNameForEventPhoto(
auth.session.eventId,
photo.id,
);
let editedMtime: number | undefined;
if (photo.editedStoredName) {
const editedPath = eventPhotoPath(storage.root, photo.editedStoredName);
const edited = await stat(editedPath).catch(() => null);
if (edited?.isFile()) {
sourcePath = editedPath;
sourceKind = "image";
editedMtime = edited.mtimeMs;
thumbName = bridgeEditedThumbStoredNameForEventPhoto(
auth.session.eventId,
photo.id,
);
}
}
try {
const thumbPath = eventPhotoPath(
storage.root,
bridgeThumbStoredNameForEventPhoto(auth.session.eventId, photo.id),
);
const data = await cached(thumbPath, () =>
thumbFor(originalPath, photo.kind),
const data = await cached(
eventPhotoPath(storage.root, thumbName),
() => thumbFor(sourcePath, sourceKind),
editedMtime,
);
return imageResponse(data);
} catch {
@@ -10,6 +10,17 @@ import { mediaStorage } from "@/lib/media-storage";
import { eventPhotoPath } from "@/lib/event-photos";
import sharp from "sharp";
/** The advanced editor's saved slider recipe, or null when it cannot be read. */
function savedRecipe(json: string | null): unknown {
if (!json) return null;
try {
const parsed = JSON.parse(json) as unknown;
return parsed && typeof parsed === "object" ? parsed : null;
} catch {
return null;
}
}
/** Reads the header dimensions without decoding the whole file. */
async function imageSize(
path: string,
@@ -77,6 +88,12 @@ export const GET = async (
width: sizes.get(row.id)?.width ?? 0,
height: sizes.get(row.id)?.height ?? 0,
takenAt: row.createdAt,
// Reopening the editor restores the sliders exactly as they were saved;
// the editor falls back to neutral when this is null.
edits: savedRecipe(row.advancedEditJson),
// Stamps the thumbnail URL so a newly saved edit is not masked by a
// cached grid thumbnail from before it was rendered.
editedAt: row.editedAt,
})),
editor: { returnUrl: bridgeReturnUrl(auth.session.eventId) },
});
+10 -3
View File
@@ -1,5 +1,6 @@
import { NextRequest } from "next/server";
import { gateSession } from "@/auth/api";
import { requestOrigin } from "@/auth/magic-link";
import { bridgeUser, createBridgeSession } from "@/db/bridge";
import { getEventAccess } from "@/db/events";
import { errorResponse, jsonResponse } from "@/lib/http";
@@ -7,7 +8,6 @@ import {
BRIDGE_LOGIN_TTL_SECONDS,
advancedEditorUrl,
bridgeConfigured,
bridgeReturnUrl,
signBridgeToken,
} from "@/lib/bridge";
@@ -19,7 +19,7 @@ import {
* dashboard session; the editor only ever sees the scoped token.
*/
export const POST = async (
_req: NextRequest,
req: NextRequest,
{ params }: { params: Promise<{ id: string }> },
) => {
const gate = await gateSession();
@@ -45,6 +45,12 @@ export const POST = async (
eventId: id,
});
// This request comes from the user's browser, so its origin is the address
// that actually works for them. `NEXTAUTH_URL` cannot be trusted here: the
// compose default is http://localhost:3000 even when the app is served from
// a LAN address. PUBLIC_ORIGIN still wins inside requestOrigin().
const returnUrl = `${requestOrigin(req)}/events/${id}`;
const token = signBridgeToken({
sid: session.id,
eid: id,
@@ -53,11 +59,12 @@ export const POST = async (
name: user.name,
kind: "login",
exp: Math.floor(Date.now() / 1000) + BRIDGE_LOGIN_TTL_SECONDS,
ret: returnUrl,
});
return jsonResponse({
url: `${editor}/api/bridge/login?token=${encodeURIComponent(token)}`,
expiresAt: session.expiresAt,
returnUrl: bridgeReturnUrl(id),
returnUrl,
});
};
+34 -16
View File
@@ -17,10 +17,12 @@ import { mediaStorage } from "@/lib/media-storage";
* GET /api/events/:id/download
*
* Streams every photo on the event as one ZIP, preserving folder names. Saved
* edits are included beside their originals as `<name>-edited.jpg`. The
* archive is store-only: JPEGs and camera RAW files are already compressed, so
* deflating them would add CPU and latency without shrinking the download.
* Anyone assigned to the event (or a manager) can download it.
* edits are included beside their originals as `<name>-edited.jpg`. With
* `?edited=1` the archive contains only the saved edits, which is what a
* photographer wants to hand on after a grading pass. The archive is
* store-only: JPEGs and camera RAW files are already compressed, so deflating
* them would add CPU and latency without shrinking the download. Anyone
* assigned to the event (or a manager) can download it.
*/
export const GET = async (
req: NextRequest,
@@ -36,13 +38,22 @@ export const GET = async (
// `?folderId=` narrows the archive to one folder, so a photographer can pull
// just the shots they need without downloading the whole event.
const folderId = req.nextUrl.searchParams.get("folderId")?.trim() || null;
const onlyEdited = req.nextUrl.searchParams.get("edited") === "1";
const photos = (await listEventPhotosForArchive(id)).filter(
(photo) => !folderId || photo.folderId === folderId,
(photo) =>
(!folderId || photo.folderId === folderId) &&
(!onlyEdited || Boolean(photo.editedStoredName)),
);
if (photos.length === 0) {
return errorResponse(
404,
folderId ? "this folder has no photos" : "this event has no photos",
onlyEdited
? folderId
? "this folder has no edited photos"
: "this event has no edited photos"
: folderId
? "this folder has no photos"
: "this event has no photos",
);
}
@@ -55,13 +66,15 @@ export const GET = async (
filename: string;
storedName: string;
}[] = [];
for (const photo of photos) {
entries.push({
key: `${photo.id}:original`,
folderName: photo.folderName,
filename: photo.filename,
storedName: photo.storedName,
});
if (!onlyEdited) {
for (const photo of photos) {
entries.push({
key: `${photo.id}:original`,
folderName: photo.folderName,
filename: photo.filename,
storedName: photo.storedName,
});
}
}
for (const photo of photos) {
if (!photo.editedStoredName) continue;
@@ -124,9 +137,14 @@ export const GET = async (
"content-type": "application/zip",
"content-disposition": photoContentDisposition(
eventArchiveFilename(
folderId
? `${access.event.title} - ${photos[0].folderName}`
: access.event.title,
[
folderId
? `${access.event.title} - ${photos[0].folderName}`
: access.event.title,
onlyEdited ? "edited" : null,
]
.filter(Boolean)
.join(" - "),
),
false,
),
@@ -1,10 +1,11 @@
import { NextRequest } from "next/server";
import { randomUUID } from "node:crypto";
import { mkdir, rename, stat, unlink, writeFile } from "node:fs/promises";
import { copyFile, mkdir, rename, stat, unlink, writeFile } from "node:fs/promises";
import path from "node:path";
import { gateSession } from "@/auth/api";
import { getEventPhotoAccess, updateEventPhotoEdit } from "@/db/events";
import {
advancedStoredNameForEventPhoto,
editedPhotoFilename,
editedStoredNameForEventPhoto,
eventPhotoPath,
@@ -12,18 +13,43 @@ import {
} from "@/lib/event-photos";
import { errorResponse, jsonResponse } from "@/lib/http";
import { mediaStorage } from "@/lib/media-storage";
import { normalizePhotoAdjustments } from "@/lib/photo-adjustments";
import {
defaultPhotoAdjustments,
normalizePhotoAdjustments,
parseStoredPhotoAdjustments,
} from "@/lib/photo-adjustments";
import { PhotoRenderError, renderPhotoJpeg } from "@/lib/photo-render";
const MAX_EDIT_BODY_BYTES = 32 * 1024;
/** True when the advanced editor has left a recipe that describes its render. */
function hasAdvancedRecipe(json: string | null): boolean {
if (!json) return false;
try {
const parsed: unknown = JSON.parse(json);
return Boolean(
parsed && typeof parsed === "object" && Object.keys(parsed).length > 0,
);
} catch {
return false;
}
}
function isNeutral(adjustments: ReturnType<typeof defaultPhotoAdjustments>) {
return (
JSON.stringify(adjustments) === JSON.stringify(defaultPhotoAdjustments())
);
}
/**
* POST /api/events/:id/folders/:folderId/photos/:photoId/edit
* Body: { adjustments: PhotoAdjustments }
*
* Saves the recipe and renders a fresh full-resolution JPEG beside the
* original. The original file is never changed, so an edit can always be
* reopened and adjusted again.
* original. When the advanced editor has already rendered this photo, that
* render is the base and the simple recipe is layered on top, so saving here
* never throws the advanced edit away. The original is never changed, so an
* edit can always be reopened and adjusted again.
*/
export const POST = async (
req: NextRequest,
@@ -59,8 +85,12 @@ export const POST = async (
if (!storage.ok) return errorResponse(503, storage.message);
const body = (await req.json().catch(() => null)) as
| { adjustments?: unknown }
| { adjustments?: unknown; takeOver?: unknown }
| null;
// Taking over retires the advanced recipe: the sliders are rendered from the
// original file instead of on top of the advanced render, so the look is not
// applied twice.
const takeOver = body?.takeOver === true;
const adjustments = normalizePhotoAdjustments(body?.adjustments);
if (!adjustments) {
return errorResponse(400, "invalid photo adjustments");
@@ -80,11 +110,69 @@ export const POST = async (
);
const editedPath = eventPhotoPath(storage.root, editedStoredName);
// The advanced editor's render is the base for the simple recipe.
let renderPath = sourcePath;
let renderKind = access.photo.kind;
const advancedStoredName = advancedStoredNameForEventPhoto(
access.eventId,
access.photo.id,
);
const advancedPath = eventPhotoPath(storage.root, advancedStoredName);
if (!takeOver && hasAdvancedRecipe(access.photo.advancedEditJson)) {
let advancedInfo = await stat(advancedPath).catch(() => null);
if (!advancedInfo?.isFile()) {
// Rows saved before the advanced render had its own file kept it in the
// edited path; copy it aside once so layered renders never compound.
const previous = access.photo.editedStoredName;
if (previous && previous !== advancedStoredName) {
const legacyPath = eventPhotoPath(storage.root, previous);
const legacyInfo = await stat(legacyPath).catch(() => null);
if (legacyInfo?.isFile()) {
await mkdir(path.dirname(advancedPath), { recursive: true });
await copyFile(legacyPath, advancedPath).catch(() => undefined);
advancedInfo = await stat(advancedPath).catch(() => null);
}
}
}
if (advancedInfo?.isFile()) {
renderPath = advancedPath;
renderKind = "image";
}
// Nothing layered on top: keep the advanced render as the saved edit
// instead of re-rendering it. This is a save with no slider changes, so
// say so rather than claiming a new JPEG was written.
if (renderPath === advancedPath && isNeutral(adjustments)) {
const info = await stat(advancedPath);
const alreadySaved =
access.photo.editedStoredName === advancedStoredName &&
JSON.stringify(parseStoredPhotoAdjustments(access.photo.editJson)) ===
JSON.stringify(adjustments);
const updated = await updateEventPhotoEdit({
photoId: access.photo.id,
editJson: JSON.stringify(adjustments),
editedStoredName: advancedStoredName,
editedSizeBytes: info.size,
editedBy: gate.id,
clearAdvancedEdit: false,
});
if (!updated) return errorResponse(404, "unknown photo");
return jsonResponse({
ok: true,
unchanged: alreadySaved,
adjustments,
editedFilename: editedPhotoFilename(access.photo.filename),
editedSizeBytes: info.size,
editedAt: updated.editedAt,
});
}
}
let rendered: Awaited<ReturnType<typeof renderPhotoJpeg>>;
try {
rendered = await renderPhotoJpeg({
filePath: sourcePath,
kind: access.photo.kind,
filePath: renderPath,
kind: renderKind,
adjustments,
});
} catch (error) {
@@ -113,6 +201,7 @@ export const POST = async (
editedStoredName,
editedSizeBytes: rendered.data.byteLength,
editedBy: gate.id,
clearAdvancedEdit: takeOver,
});
if (!updated) {
await unlink(editedPath).catch(() => undefined);
@@ -127,6 +216,7 @@ export const POST = async (
editedAt: updated.editedAt,
width: rendered.width,
height: rendered.height,
tookOver: takeOver,
});
} catch (error) {
await unlink(editedPath).catch(() => undefined);
@@ -6,6 +6,7 @@ import { gateSession } from "@/auth/api";
import { deleteEventPhoto, getEventPhotoAccess } from "@/db/events";
import { canDeleteEventPhoto } from "@/lib/event-access";
import {
advancedStoredNameForEventPhoto,
editedPhotoFilename,
eventPhotoPath,
isBrowserRenderablePhoto,
@@ -19,8 +20,11 @@ import { mediaStorage } from "@/lib/media-storage";
*
* Streams the original bytes to anyone assigned to the event (or a manager).
* `variant=edited` serves the generated full-resolution JPEG instead, so the
* gallery can show the saved look without replacing the original. RAW files
* always download; `?download=1` forces an attachment for JPEGs too.
* gallery can show the saved look without replacing the original.
* `variant=advanced` serves the advanced editor's own render (without any
* simple-editor layer), which is the base the simple editor previews on top of
* so its sliders can be re-applied without baking them twice. RAW files always
* download; `?download=1` forces an attachment for JPEGs too.
*/
export const GET = async (
req: NextRequest,
@@ -43,7 +47,9 @@ export const GET = async (
return errorResponse(404, "unknown photo");
}
const wantsEdited = req.nextUrl.searchParams.get("variant") === "edited";
const variant = req.nextUrl.searchParams.get("variant");
const wantsEdited = variant === "edited";
const wantsAdvanced = variant === "advanced";
if (wantsEdited && !access.photo.editedStoredName) {
return errorResponse(404, "this photo has no saved edit");
}
@@ -51,13 +57,27 @@ export const GET = async (
const storage = await mediaStorage();
if (!storage.ok) return errorResponse(503, storage.message);
const filePath = eventPhotoPath(
storage.root,
wantsEdited
? access.photo.editedStoredName!
: access.photo.storedName,
);
const filename = wantsEdited
let servedStoredName = access.photo.storedName;
if (wantsEdited) {
servedStoredName = access.photo.editedStoredName!;
} else if (wantsAdvanced) {
const advancedName = advancedStoredNameForEventPhoto(id, access.photo.id);
const advancedInfo = await stat(
eventPhotoPath(storage.root, advancedName),
).catch(() => null);
if (advancedInfo?.isFile()) {
servedStoredName = advancedName;
} else if (access.photo.editedStoredName) {
// Rows saved before the advanced render had its own file kept it here.
servedStoredName = access.photo.editedStoredName;
} else {
return errorResponse(404, "this photo has no advanced edit");
}
}
const generated = wantsEdited || wantsAdvanced;
const filePath = eventPhotoPath(storage.root, servedStoredName);
const filename = generated
? editedPhotoFilename(access.photo.filename)
: access.photo.filename;
let size: number;
@@ -69,7 +89,7 @@ export const GET = async (
const inline =
req.nextUrl.searchParams.get("download") !== "1" &&
(wantsEdited || isBrowserRenderablePhoto(access.photo.filename));
(generated || isBrowserRenderablePhoto(access.photo.filename));
const stream = createReadStream(filePath);
return new Response(
@@ -77,7 +97,7 @@ export const GET = async (
{
status: 200,
headers: {
"content-type": wantsEdited ? "image/jpeg" : access.photo.mimeType,
"content-type": generated ? "image/jpeg" : access.photo.mimeType,
"content-length": String(size),
"content-disposition": photoContentDisposition(filename, inline),
"cache-control": "private, max-age=0, must-revalidate",
@@ -2,7 +2,6 @@ import { NextRequest } from "next/server";
import { randomUUID } from "node:crypto";
import { mkdir, readFile, rename, stat, writeFile } from "node:fs/promises";
import path from "node:path";
import sharp from "sharp";
import { gateSession } from "@/auth/api";
import { getEventPhotoAccess } from "@/db/events";
import {
@@ -12,8 +11,7 @@ import {
} from "@/lib/event-photos";
import { errorResponse } from "@/lib/http";
import { mediaStorage } from "@/lib/media-storage";
import { defaultPhotoAdjustments } from "@/lib/photo-adjustments";
import { PhotoRenderError, renderPhotoJpeg } from "@/lib/photo-render";
import { PhotoRenderError, renderPhotoThumbnail } from "@/lib/photo-render";
/**
* GET /api/events/:id/folders/:folderId/photos/:photoId/thumb
@@ -69,20 +67,15 @@ export const GET = async (
let data: Buffer;
try {
if (access.photo.kind === "raw") {
const rendered = await renderPhotoJpeg({
if (
access.photo.kind === "raw" ||
isBrowserRenderablePhoto(access.photo.filename)
) {
data = await renderPhotoThumbnail({
filePath: sourcePath,
kind: "raw",
adjustments: defaultPhotoAdjustments(),
kind: access.photo.kind,
maxDimension: 640,
});
data = rendered.data;
} else if (isBrowserRenderablePhoto(access.photo.filename)) {
data = await sharp(sourcePath, { failOn: "none", limitInputPixels: 500_000_000 })
.autoOrient()
.resize(640, 640, { fit: "inside", withoutEnlargement: true })
.jpeg({ quality: 72 })
.toBuffer();
} else {
return errorResponse(415, "this photo format has no thumbnail");
}