Vercel/app/admin/photos/[photoId]/edit/page.tsx
Sam Becker b8c01492b8
Store optimized assets for all photos (#304)
* Begin storing optimized photo files

* Increase optimized image size to 1080

* Refactor photo/storage modules

* Refine storage file naming api

* Simplify photo storage api

* Finalize photo storage api

* Start storing/serving optimized photos

* Finalize optimized photo asset generation

* Temporarily allow static optimization on PREVIEW branches

* Restore static optimization as production-only

* Remove og image inline-flex class

* Tweak convert upload signature

* Refactor optimized file storage

* Display optimized files when they exist in photo form

* Create small disclosure component

* Report photo storage files more accurately

* Sort optimized files

* Generate optimized storage files when updating/syncing photos

* Include source bucket when copying files with MinIO

* Make deleting files more resilient
2025-09-06 23:20:20 -05:00

72 lines
1.7 KiB
TypeScript

import { redirect } from 'next/navigation';
import {
getPhotoNoStore,
getUniqueFilmsCached,
getUniqueRecipesCached,
getUniqueTagsCached,
} from '@/photo/cache';
import { PATH_ADMIN } from '@/app/path';
import PhotoEditPageClient from '@/photo/PhotoEditPageClient';
import {
AI_CONTENT_GENERATION_ENABLED,
BLUR_ENABLED,
IS_PREVIEW,
} from '@/app/config';
import { blurImageFromUrl, resizeImageFromUrl } from '@/photo/server';
import {
getOptimizedPhotoUrlForManipulation,
getStorageUrlsForPhoto,
} from '@/photo/storage';
export default async function PhotoEditPage({
params,
}: {
params: Promise<{ photoId: string }>
}) {
const { photoId } = await params;
const [
photo,
uniqueTags,
uniqueRecipes,
uniqueFilms,
] = await Promise.all([
getPhotoNoStore(photoId, true),
getUniqueTagsCached(),
getUniqueRecipesCached(),
getUniqueFilmsCached(),
]);
if (!photo) { redirect(PATH_ADMIN); }
const photoStorageUrls = await getStorageUrlsForPhoto(photo);
const hasAiTextGeneration = AI_CONTENT_GENERATION_ENABLED;
// Only generate image thumbnails when AI generation is enabled
const imageThumbnailBase64 = AI_CONTENT_GENERATION_ENABLED
? await resizeImageFromUrl(
getOptimizedPhotoUrlForManipulation(photo.url, IS_PREVIEW),
)
: '';
const blurData = BLUR_ENABLED
? await blurImageFromUrl(
getOptimizedPhotoUrlForManipulation(photo.url, IS_PREVIEW),
)
: '';
return (
<PhotoEditPageClient {...{
photo,
photoStorageUrls,
uniqueTags,
uniqueRecipes,
uniqueFilms,
hasAiTextGeneration,
imageThumbnailBase64,
blurData,
}} />
);
};