diff --git a/src/admin/AdminPhotoMenu.tsx b/src/admin/AdminPhotoMenu.tsx index 82126b4e..c32c7c84 100644 --- a/src/admin/AdminPhotoMenu.tsx +++ b/src/admin/AdminPhotoMenu.tsx @@ -1,4 +1,4 @@ -import { authCached } from '@/cache'; +import { authCached } from '@/auth/cache'; import AdminPhotoMenuClient, { AdminPhotoMenuClientProps } from './AdminPhotoMenuClient'; diff --git a/src/app/admin/photos/[photoId]/edit/page.tsx b/src/app/admin/photos/[photoId]/edit/page.tsx index 7e78b30b..2a5c2d6c 100644 --- a/src/app/admin/photos/[photoId]/edit/page.tsx +++ b/src/app/admin/photos/[photoId]/edit/page.tsx @@ -1,5 +1,5 @@ import { redirect } from 'next/navigation'; -import { getPhotoNoStore, getUniqueTagsCached } from '@/cache'; +import { getPhotoNoStore, getUniqueTagsCached } from '@/photo/cache'; import { PATH_ADMIN } from '@/site/paths'; import PhotoEditPageClient from '@/photo/PhotoEditPageClient'; diff --git a/src/app/admin/photos/page.tsx b/src/app/admin/photos/page.tsx index e8667098..f88d3b4f 100644 --- a/src/app/admin/photos/page.tsx +++ b/src/app/admin/photos/page.tsx @@ -14,10 +14,9 @@ import { import { titleForPhoto } from '@/photo'; import MoreComponentsClient from '@/components/MoreComponentsClient'; import { - getStoragePhotoUrlsNoStore, getPhotosCached, getPhotosCountIncludingHiddenCached, -} from '@/cache'; +} from '@/photo/cache'; import { AiOutlineEyeInvisible } from 'react-icons/ai'; import { PaginationParams, @@ -30,6 +29,7 @@ import StorageUrls from '@/admin/StorageUrls'; import { PRO_MODE_ENABLED } from '@/site/config'; import SubmitButtonWithStatus from '@/components/SubmitButtonWithStatus'; import IconGrSync from '@/site/IconGrSync'; +import { getStoragePhotoUrlsNoStore } from '@/services/storage/cache'; const DEBUG_PHOTO_BLOBS = false; diff --git a/src/app/admin/tags/[tag]/edit/page.tsx b/src/app/admin/tags/[tag]/edit/page.tsx index dc27e9b3..ed45870a 100644 --- a/src/app/admin/tags/[tag]/edit/page.tsx +++ b/src/app/admin/tags/[tag]/edit/page.tsx @@ -1,6 +1,6 @@ import AdminChildPage from '@/components/AdminChildPage'; import { redirect } from 'next/navigation'; -import { getPhotosCached, getPhotosTagCountCached } from '@/cache'; +import { getPhotosCached, getPhotosTagCountCached } from '@/photo/cache'; import TagForm from '@/tag/TagForm'; import { PATH_ADMIN, PATH_ADMIN_TAGS, pathForTag } from '@/site/paths'; import PhotoTag from '@/tag/PhotoTag'; diff --git a/src/app/admin/tags/page.tsx b/src/app/admin/tags/page.tsx index 54756b28..de41c0e6 100644 --- a/src/app/admin/tags/page.tsx +++ b/src/app/admin/tags/page.tsx @@ -5,7 +5,7 @@ import AdminGrid from '@/admin/AdminGrid'; import { Fragment } from 'react'; import DeleteButton from '@/admin/DeleteButton'; import { photoQuantityText } from '@/photo'; -import { getUniqueTagsHiddenCached } from '@/cache'; +import { getUniqueTagsHiddenCached } from '@/photo/cache'; import PhotoTag from '@/tag/PhotoTag'; import { formatTag, isTagFavs, sortTagsObject } from '@/tag'; import EditButton from '@/admin/EditButton'; diff --git a/src/app/admin/uploads/[uploadPath]/page.tsx b/src/app/admin/uploads/[uploadPath]/page.tsx index 17b43b52..9dca170b 100644 --- a/src/app/admin/uploads/[uploadPath]/page.tsx +++ b/src/app/admin/uploads/[uploadPath]/page.tsx @@ -3,7 +3,7 @@ import AdminChildPage from '@/components/AdminChildPage'; import { PATH_ADMIN, PATH_ADMIN_UPLOADS } from '@/site/paths'; import { extractExifDataFromBlobPath } from '@/photo/server'; import { redirect } from 'next/navigation'; -import { getUniqueTagsCached } from '@/cache'; +import { getUniqueTagsCached } from '@/photo/cache'; interface Params { params: { uploadPath: string } diff --git a/src/app/admin/uploads/page.tsx b/src/app/admin/uploads/page.tsx index 8108e6eb..ce1273c3 100644 --- a/src/app/admin/uploads/page.tsx +++ b/src/app/admin/uploads/page.tsx @@ -1,5 +1,5 @@ import StorageUrls from '@/admin/StorageUrls'; -import { getStorageUploadUrlsNoStore } from '@/cache'; +import { getStorageUploadUrlsNoStore } from '@/services/storage/cache'; import SiteGrid from '@/components/SiteGrid'; export default async function AdminUploadsPage() { diff --git a/src/app/api/route.ts b/src/app/api/route.ts index ba5f82ad..6c367600 100644 --- a/src/app/api/route.ts +++ b/src/app/api/route.ts @@ -1,4 +1,4 @@ -import { getPhotosCached } from '@/cache'; +import { getPhotosCached } from '@/photo/cache'; import { API_PHOTO_REQUEST_LIMIT, formatPhotoForApi } from '@/site/api'; import { BASE_URL, diff --git a/src/app/api/storage/vercel-blob/route.ts b/src/app/api/storage/vercel-blob/route.ts index e41543c6..6cc63e9b 100644 --- a/src/app/api/storage/vercel-blob/route.ts +++ b/src/app/api/storage/vercel-blob/route.ts @@ -1,5 +1,5 @@ import { auth } from '@/auth'; -import { revalidateAdminPaths, revalidatePhotosKey } from '@/cache'; +import { revalidateAdminPaths, revalidatePhotosKey } from '@/photo/cache'; import { ACCEPTED_PHOTO_FILE_TYPES, MAX_PHOTO_UPLOAD_SIZE_IN_BYTES, diff --git a/src/app/film/[simulation]/[photoId]/layout.tsx b/src/app/film/[simulation]/[photoId]/layout.tsx index 03d070a8..663d68bb 100644 --- a/src/app/film/[simulation]/[photoId]/layout.tsx +++ b/src/app/film/[simulation]/[photoId]/layout.tsx @@ -10,7 +10,7 @@ import { absolutePathForPhotoImage, } from '@/site/paths'; import PhotoDetailPage from '@/photo/PhotoDetailPage'; -import { getPhotoCached } from '@/cache'; +import { getPhotoCached } from '@/photo/cache'; import { ReactNode } from 'react'; import { FilmSimulation } from '@/simulation'; import { getPhotosFilmSimulationDataCached } from '@/simulation/data'; diff --git a/src/app/film/[simulation]/[photoId]/share/page.tsx b/src/app/film/[simulation]/[photoId]/share/page.tsx index 782e14df..0e5dca79 100644 --- a/src/app/film/[simulation]/[photoId]/share/page.tsx +++ b/src/app/film/[simulation]/[photoId]/share/page.tsx @@ -1,4 +1,4 @@ -import { getPhotoCached } from '@/cache'; +import { getPhotoCached } from '@/photo/cache'; import PhotoShareModal from '@/photo/PhotoShareModal'; import { FilmSimulation } from '@/simulation'; import { PATH_ROOT } from '@/site/paths'; diff --git a/src/app/film/[simulation]/image/route.tsx b/src/app/film/[simulation]/image/route.tsx index 7b41da1d..7146f9b6 100644 --- a/src/app/film/[simulation]/image/route.tsx +++ b/src/app/film/[simulation]/image/route.tsx @@ -1,14 +1,14 @@ -import { auth } from '@/auth'; -import { getImageCacheHeadersForAuth, getPhotosCached } from '@/cache'; +import { getPhotosCached } from '@/photo/cache'; import { IMAGE_OG_DIMENSION_SMALL, MAX_PHOTOS_TO_SHOW_PER_TAG, -} from '@/photo/image-response'; +} from '@/image-response'; import FilmSimulationImageResponse from - '@/photo/image-response/FilmSimulationImageResponse'; + '@/image-response/FilmSimulationImageResponse'; import { FilmSimulation } from '@/simulation'; import { getIBMPlexMonoMedium } from '@/site/font'; import { ImageResponse } from 'next/og'; +import { getImageResponseCacheControlHeaders } from '@/image-response/cache'; export const runtime = 'edge'; @@ -25,7 +25,7 @@ export async function GET( ] = await Promise.all([ getPhotosCached({ limit: MAX_PHOTOS_TO_SHOW_PER_TAG, simulation }), getIBMPlexMonoMedium(), - getImageCacheHeadersForAuth(await auth()), + getImageResponseCacheControlHeaders(), ]); const { width, height } = IMAGE_OG_DIMENSION_SMALL; diff --git a/src/app/grid/page.tsx b/src/app/grid/page.tsx index 52fb1571..e8938f4c 100644 --- a/src/app/grid/page.tsx +++ b/src/app/grid/page.tsx @@ -1,4 +1,4 @@ -import { getPhotosCached } from '@/cache'; +import { getPhotosCached } from '@/photo/cache'; import SiteGrid from '@/components/SiteGrid'; import { PHOTO_LOAD_MULTIPLE_GRID, @@ -6,7 +6,7 @@ import { } from '@/photo'; import PhotoGrid from '@/photo/PhotoGrid'; import PhotosEmptyState from '@/photo/PhotosEmptyState'; -import { MAX_PHOTOS_TO_SHOW_OG } from '@/photo/image-response'; +import { MAX_PHOTOS_TO_SHOW_OG } from '@/image-response'; import { Metadata } from 'next/types'; import PhotoGridSidebar from '@/photo/PhotoGridSidebar'; import { getPhotoSidebarDataCached } from '@/photo/data'; diff --git a/src/app/home-image/route.tsx b/src/app/home-image/route.tsx index d8c3c3c1..55eb29aa 100644 --- a/src/app/home-image/route.tsx +++ b/src/app/home-image/route.tsx @@ -1,12 +1,12 @@ -import { auth } from '@/auth'; -import { getImageCacheHeadersForAuth, getPhotosCached } from '@/cache'; +import { getPhotosCached } from '@/photo/cache'; import { IMAGE_OG_DIMENSION_SMALL, MAX_PHOTOS_TO_SHOW_OG, -} from '@/photo/image-response'; -import HomeImageResponse from '@/photo/image-response/HomeImageResponse'; +} from '@/image-response'; +import HomeImageResponse from '@/image-response/HomeImageResponse'; import { getIBMPlexMonoMedium } from '@/site/font'; import { ImageResponse } from 'next/og'; +import { getImageResponseCacheControlHeaders } from '@/image-response/cache'; export const runtime = 'edge'; @@ -17,7 +17,7 @@ export async function GET() { { fontFamily, fonts }, ] = await Promise.all([ getPhotosCached({ limit: MAX_PHOTOS_TO_SHOW_OG }), - getImageCacheHeadersForAuth(await auth()), + getImageResponseCacheControlHeaders(), getIBMPlexMonoMedium(), ]); diff --git a/src/app/og/page.tsx b/src/app/og/page.tsx index d0d38d46..ad856871 100644 --- a/src/app/og/page.tsx +++ b/src/app/og/page.tsx @@ -1,4 +1,4 @@ -import { getPhotosCached, getPhotosCountCached } from '@/cache'; +import { getPhotosCached, getPhotosCountCached } from '@/photo/cache'; import MoreComponentsClient from '@/components/MoreComponentsClient'; import StaggeredOgPhotos from '@/photo/StaggeredOgPhotos'; import { diff --git a/src/app/p/[photoId]/image/route.tsx b/src/app/p/[photoId]/image/route.tsx index 331977a1..21a62077 100644 --- a/src/app/p/[photoId]/image/route.tsx +++ b/src/app/p/[photoId]/image/route.tsx @@ -1,9 +1,9 @@ -import { auth } from '@/auth'; -import { getImageCacheHeadersForAuth, getPhotoCached } from '@/cache'; -import { IMAGE_OG_DIMENSION } from '@/photo/image-response'; -import PhotoImageResponse from '@/photo/image-response/PhotoImageResponse'; +import { getPhotoCached } from '@/photo/cache'; +import { IMAGE_OG_DIMENSION } from '@/image-response'; +import PhotoImageResponse from '@/image-response/PhotoImageResponse'; import { getIBMPlexMonoMedium } from '@/site/font'; import { ImageResponse } from 'next/og'; +import { getImageResponseCacheControlHeaders } from '@/image-response/cache'; export const runtime = 'edge'; @@ -18,7 +18,7 @@ export async function GET( ] = await Promise.all([ getPhotoCached(context.params.photoId), getIBMPlexMonoMedium(), - getImageCacheHeadersForAuth(await auth()), + getImageResponseCacheControlHeaders(), ]); if (!photo) { return new Response('Photo not found', { status: 404 }); } diff --git a/src/app/p/[photoId]/layout.tsx b/src/app/p/[photoId]/layout.tsx index 7305da5f..41ef856d 100644 --- a/src/app/p/[photoId]/layout.tsx +++ b/src/app/p/[photoId]/layout.tsx @@ -12,7 +12,7 @@ import { absolutePathForPhotoImage, } from '@/site/paths'; import PhotoDetailPage from '@/photo/PhotoDetailPage'; -import { getPhotosNearIdCached } from '@/cache'; +import { getPhotosNearIdCached } from '@/photo/cache'; import { getPhotoIds } from '@/services/vercel-postgres'; export async function generateStaticParams() { diff --git a/src/app/p/[photoId]/share/page.tsx b/src/app/p/[photoId]/share/page.tsx index fff8c1ba..4b8e6c73 100644 --- a/src/app/p/[photoId]/share/page.tsx +++ b/src/app/p/[photoId]/share/page.tsx @@ -1,4 +1,4 @@ -import { getPhotoCached } from '@/cache'; +import { getPhotoCached } from '@/photo/cache'; import PhotoShareModal from '@/photo/PhotoShareModal'; import { PATH_ROOT } from '@/site/paths'; import { redirect } from 'next/navigation'; diff --git a/src/app/page.tsx b/src/app/page.tsx index a7098e44..acaf7bff 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,11 +1,11 @@ -import { getPhotosCached, getPhotosCountCached } from '@/cache'; +import { getPhotosCached, getPhotosCountCached } from '@/photo/cache'; import { PHOTO_LOAD_MULTIPLE_ROOT, generateOgImageMetaForPhotos, } from '@/photo'; import PhotosEmptyState from '@/photo/PhotosEmptyState'; import { Metadata } from 'next/types'; -import { MAX_PHOTOS_TO_SHOW_OG } from '@/photo/image-response'; +import { MAX_PHOTOS_TO_SHOW_OG } from '@/image-response'; import PhotosLarge from '@/photo/PhotosLarge'; import { Suspense } from 'react'; import { MorePhotosRoot } from '@/photo/MorePhotosRoot'; diff --git a/src/app/sets/page.tsx b/src/app/sets/page.tsx index 39632593..a0f5dd46 100644 --- a/src/app/sets/page.tsx +++ b/src/app/sets/page.tsx @@ -1,11 +1,11 @@ -import { getPhotosCached } from '@/cache'; +import { getPhotosCached } from '@/photo/cache'; import InfoBlock from '@/components/InfoBlock'; import RedirectOnDesktop from '@/components/RedirectOnDesktop'; import SiteGrid from '@/components/SiteGrid'; import { generateOgImageMetaForPhotos } from '@/photo'; import PhotoGridSidebar from '@/photo/PhotoGridSidebar'; import { getPhotoSidebarDataCached } from '@/photo/data'; -import { MAX_PHOTOS_TO_SHOW_OG } from '@/photo/image-response'; +import { MAX_PHOTOS_TO_SHOW_OG } from '@/image-response'; import { PATH_GRID } from '@/site/paths'; import { Metadata } from 'next/types'; diff --git a/src/app/shot-on/[camera]/[photoId]/layout.tsx b/src/app/shot-on/[camera]/[photoId]/layout.tsx index 36e301bf..8ddb9514 100644 --- a/src/app/shot-on/[camera]/[photoId]/layout.tsx +++ b/src/app/shot-on/[camera]/[photoId]/layout.tsx @@ -10,7 +10,7 @@ import { absolutePathForPhotoImage, } from '@/site/paths'; import PhotoDetailPage from '@/photo/PhotoDetailPage'; -import { getPhotoCached } from '@/cache'; +import { getPhotoCached } from '@/photo/cache'; import { cameraFromPhoto } from '@/camera'; import { getPhotosCameraDataCached } from '@/camera/data'; import { ReactNode } from 'react'; diff --git a/src/app/shot-on/[camera]/[photoId]/share/page.tsx b/src/app/shot-on/[camera]/[photoId]/share/page.tsx index d6bc9ec9..15e02113 100644 --- a/src/app/shot-on/[camera]/[photoId]/share/page.tsx +++ b/src/app/shot-on/[camera]/[photoId]/share/page.tsx @@ -1,4 +1,4 @@ -import { getPhotoCached } from '@/cache'; +import { getPhotoCached } from '@/photo/cache'; import { cameraFromPhoto } from '@/camera'; import PhotoShareModal from '@/photo/PhotoShareModal'; import { PATH_ROOT } from '@/site/paths'; diff --git a/src/app/shot-on/[camera]/image/route.tsx b/src/app/shot-on/[camera]/image/route.tsx index 21473e2d..209454e0 100644 --- a/src/app/shot-on/[camera]/image/route.tsx +++ b/src/app/shot-on/[camera]/image/route.tsx @@ -1,13 +1,13 @@ -import { auth } from '@/auth'; -import { getImageCacheHeadersForAuth, getPhotosCached } from '@/cache'; +import { getPhotosCached } from '@/photo/cache'; import { getCameraFromKey } from '@/camera'; import { IMAGE_OG_DIMENSION_SMALL, MAX_PHOTOS_TO_SHOW_PER_TAG, -} from '@/photo/image-response'; -import CameraImageResponse from '@/photo/image-response/CameraImageResponse'; +} from '@/image-response'; +import CameraImageResponse from '@/image-response/CameraImageResponse'; import { getIBMPlexMonoMedium } from '@/site/font'; import { ImageResponse } from 'next/og'; +import { getImageResponseCacheControlHeaders } from '@/image-response/cache'; export const runtime = 'edge'; @@ -27,7 +27,7 @@ export async function GET( camera: camera, }), getIBMPlexMonoMedium(), - getImageCacheHeadersForAuth(await auth()), + getImageResponseCacheControlHeaders(), ]); const { width, height } = IMAGE_OG_DIMENSION_SMALL; diff --git a/src/app/tag/[tag]/[photoId]/layout.tsx b/src/app/tag/[tag]/[photoId]/layout.tsx index 240430a8..1d3695f2 100644 --- a/src/app/tag/[tag]/[photoId]/layout.tsx +++ b/src/app/tag/[tag]/[photoId]/layout.tsx @@ -10,7 +10,7 @@ import { absolutePathForPhotoImage, } from '@/site/paths'; import PhotoDetailPage from '@/photo/PhotoDetailPage'; -import { getPhotoCached } from '@/cache'; +import { getPhotoCached } from '@/photo/cache'; import { getPhotosTagDataCached } from '@/tag/data'; import { ReactNode } from 'react'; diff --git a/src/app/tag/[tag]/[photoId]/share/page.tsx b/src/app/tag/[tag]/[photoId]/share/page.tsx index 4ae863a0..76deedff 100644 --- a/src/app/tag/[tag]/[photoId]/share/page.tsx +++ b/src/app/tag/[tag]/[photoId]/share/page.tsx @@ -1,4 +1,4 @@ -import { getPhotoCached } from '@/cache'; +import { getPhotoCached } from '@/photo/cache'; import PhotoShareModal from '@/photo/PhotoShareModal'; import { PATH_ROOT } from '@/site/paths'; import { redirect } from 'next/navigation'; diff --git a/src/app/tag/[tag]/image/route.tsx b/src/app/tag/[tag]/image/route.tsx index 24437f8f..710842c0 100644 --- a/src/app/tag/[tag]/image/route.tsx +++ b/src/app/tag/[tag]/image/route.tsx @@ -1,12 +1,12 @@ -import { auth } from '@/auth'; -import { getImageCacheHeadersForAuth, getPhotosCached } from '@/cache'; +import { getPhotosCached } from '@/photo/cache'; import { IMAGE_OG_DIMENSION_SMALL, MAX_PHOTOS_TO_SHOW_PER_TAG, -} from '@/photo/image-response'; -import TagImageResponse from '@/photo/image-response/TagImageResponse'; +} from '@/image-response'; +import TagImageResponse from '@/image-response/TagImageResponse'; import { getIBMPlexMonoMedium } from '@/site/font'; import { ImageResponse } from 'next/og'; +import { getImageResponseCacheControlHeaders } from '@/image-response/cache'; export const runtime = 'edge'; @@ -23,7 +23,7 @@ export async function GET( ] = await Promise.all([ getPhotosCached({ limit: MAX_PHOTOS_TO_SHOW_PER_TAG, tag }), getIBMPlexMonoMedium(), - getImageCacheHeadersForAuth(await auth()), + getImageResponseCacheControlHeaders(), ]); const { width, height } = IMAGE_OG_DIMENSION_SMALL; diff --git a/src/app/template-image-tight/route.tsx b/src/app/template-image-tight/route.tsx index d813a2dd..cee5b868 100644 --- a/src/app/template-image-tight/route.tsx +++ b/src/app/template-image-tight/route.tsx @@ -1,13 +1,13 @@ -import { auth } from '@/auth'; -import { getImageCacheHeadersForAuth, getPhotosCached } from '@/cache'; +import { getPhotosCached } from '@/photo/cache'; import { IMAGE_OG_DIMENSION, MAX_PHOTOS_TO_SHOW_TEMPLATE_TIGHT, -} from '@/photo/image-response'; +} from '@/image-response'; import TemplateImageResponse from - '@/photo/image-response/TemplateImageResponse'; + '@/image-response/TemplateImageResponse'; import { getIBMPlexMonoMedium } from '@/site/font'; import { ImageResponse } from 'next/og'; +import { getImageResponseCacheControlHeaders } from '@/image-response/cache'; export const runtime = 'edge'; @@ -22,7 +22,7 @@ export async function GET() { limit: MAX_PHOTOS_TO_SHOW_TEMPLATE_TIGHT, }), getIBMPlexMonoMedium(), - getImageCacheHeadersForAuth(await auth()), + getImageResponseCacheControlHeaders(), ]); const { width, height } = IMAGE_OG_DIMENSION; diff --git a/src/app/template-image/route.tsx b/src/app/template-image/route.tsx index 6fd1768c..c7e6f1ca 100644 --- a/src/app/template-image/route.tsx +++ b/src/app/template-image/route.tsx @@ -1,13 +1,13 @@ -import { auth } from '@/auth'; -import { getImageCacheHeadersForAuth, getPhotosCached } from '@/cache'; +import { getPhotosCached } from '@/photo/cache'; import { GRID_OG_DIMENSION, MAX_PHOTOS_TO_SHOW_TEMPLATE, -} from '@/photo/image-response'; +} from '@/image-response'; import TemplateImageResponse from - '@/photo/image-response/TemplateImageResponse'; + '@/image-response/TemplateImageResponse'; import { getIBMPlexMonoMedium } from '@/site/font'; import { ImageResponse } from 'next/og'; +import { getImageResponseCacheControlHeaders } from '@/image-response/cache'; export const runtime = 'edge'; @@ -19,7 +19,7 @@ export async function GET() { ] = await Promise.all([ getPhotosCached({ sortBy: 'priority', limit: MAX_PHOTOS_TO_SHOW_TEMPLATE }), getIBMPlexMonoMedium(), - getImageCacheHeadersForAuth(await auth()), + getImageResponseCacheControlHeaders(), ]); const { width, height } = GRID_OG_DIMENSION; diff --git a/src/auth/cache.ts b/src/auth/cache.ts new file mode 100644 index 00000000..c5ebeb47 --- /dev/null +++ b/src/auth/cache.ts @@ -0,0 +1,4 @@ +import { cache } from 'react'; +import { auth } from '@/auth'; + +export const authCached = cache(auth); diff --git a/src/camera/data.ts b/src/camera/data.ts index 07c795c2..27b31f79 100644 --- a/src/camera/data.ts +++ b/src/camera/data.ts @@ -7,7 +7,7 @@ import { getPhotosCached, getPhotosCameraCountCached, getPhotosCameraDateRangeCached, -} from '@/cache'; +} from '@/photo/cache'; import { pathForCamera } from '@/site/paths'; export const getPhotosCameraDataCached = ({ diff --git a/src/components/OGTile.tsx b/src/components/OGTile.tsx index 606eefde..8afa1603 100644 --- a/src/components/OGTile.tsx +++ b/src/components/OGTile.tsx @@ -5,7 +5,7 @@ import { clsx } from 'clsx/lite'; import Link from 'next/link'; import { BiError } from 'react-icons/bi'; import Spinner from '@/components/Spinner'; -import { IMAGE_OG_DIMENSION } from '../photo/image-response'; +import { IMAGE_OG_DIMENSION } from '../image-response'; export type OGLoadingState = 'unloaded' | 'loading' | 'loaded' | 'failed'; diff --git a/src/photo/image-response/CameraImageResponse.tsx b/src/image-response/CameraImageResponse.tsx similarity index 97% rename from src/photo/image-response/CameraImageResponse.tsx rename to src/image-response/CameraImageResponse.tsx index 526cb9c8..58eb316b 100644 --- a/src/photo/image-response/CameraImageResponse.tsx +++ b/src/image-response/CameraImageResponse.tsx @@ -1,4 +1,4 @@ -import { Photo } from '..'; +import { Photo } from '../photo'; import ImageCaption from './components/ImageCaption'; import ImagePhotoGrid from './components/ImagePhotoGrid'; import ImageContainer from './components/ImageContainer'; diff --git a/src/photo/image-response/FilmSimulationImageResponse.tsx b/src/image-response/FilmSimulationImageResponse.tsx similarity index 97% rename from src/photo/image-response/FilmSimulationImageResponse.tsx rename to src/image-response/FilmSimulationImageResponse.tsx index f01264e1..5c5c630c 100644 --- a/src/photo/image-response/FilmSimulationImageResponse.tsx +++ b/src/image-response/FilmSimulationImageResponse.tsx @@ -1,4 +1,4 @@ -import { Photo } from '..'; +import { Photo } from '../photo'; import ImageCaption from './components/ImageCaption'; import ImagePhotoGrid from './components/ImagePhotoGrid'; import ImageContainer from './components/ImageContainer'; diff --git a/src/photo/image-response/HomeImageResponse.tsx b/src/image-response/HomeImageResponse.tsx similarity index 95% rename from src/photo/image-response/HomeImageResponse.tsx rename to src/image-response/HomeImageResponse.tsx index 58f9a970..755d6708 100644 --- a/src/photo/image-response/HomeImageResponse.tsx +++ b/src/image-response/HomeImageResponse.tsx @@ -1,5 +1,5 @@ import { SITE_DOMAIN_OR_TITLE } from '@/site/config'; -import { Photo } from '..'; +import { Photo } from '../photo'; import ImageCaption from './components/ImageCaption'; import ImageContainer from './components/ImageContainer'; import ImagePhotoGrid from './components/ImagePhotoGrid'; diff --git a/src/photo/image-response/PhotoImageResponse.tsx b/src/image-response/PhotoImageResponse.tsx similarity index 96% rename from src/photo/image-response/PhotoImageResponse.tsx rename to src/image-response/PhotoImageResponse.tsx index fcc28897..be8e7796 100644 --- a/src/photo/image-response/PhotoImageResponse.tsx +++ b/src/image-response/PhotoImageResponse.tsx @@ -1,4 +1,4 @@ -import { Photo, shouldShowExifDataForPhoto } from '..'; +import { Photo, shouldShowExifDataForPhoto } from '../photo'; import { AiFillApple } from 'react-icons/ai'; import ImageCaption from './components/ImageCaption'; import ImagePhotoGrid from './components/ImagePhotoGrid'; diff --git a/src/photo/image-response/TagImageResponse.tsx b/src/image-response/TagImageResponse.tsx similarity index 97% rename from src/photo/image-response/TagImageResponse.tsx rename to src/image-response/TagImageResponse.tsx index 038d6fd0..bae151e2 100644 --- a/src/photo/image-response/TagImageResponse.tsx +++ b/src/image-response/TagImageResponse.tsx @@ -1,4 +1,4 @@ -import { Photo } from '..'; +import { Photo } from '../photo'; import { FaStar, FaTag } from 'react-icons/fa'; import ImageCaption from './components/ImageCaption'; import ImagePhotoGrid from './components/ImagePhotoGrid'; diff --git a/src/photo/image-response/TemplateImageResponse.tsx b/src/image-response/TemplateImageResponse.tsx similarity index 98% rename from src/photo/image-response/TemplateImageResponse.tsx rename to src/image-response/TemplateImageResponse.tsx index fc859a97..3982ff48 100644 --- a/src/photo/image-response/TemplateImageResponse.tsx +++ b/src/image-response/TemplateImageResponse.tsx @@ -1,4 +1,4 @@ -import { Photo } from '..'; +import { Photo } from '../photo'; import IconFullFrame from '@/site/IconFullFrame'; import IconGrid from '@/site/IconGrid'; import ImagePhotoGrid from './components/ImagePhotoGrid'; diff --git a/src/image-response/cache.ts b/src/image-response/cache.ts new file mode 100644 index 00000000..437ab360 --- /dev/null +++ b/src/image-response/cache.ts @@ -0,0 +1,9 @@ +export const getImageResponseCacheControlHeaders = ( + shouldCache = process.env.NEXT_PUBLIC_VERCEL_ENV === 'production', +) => { + return { + 'Cache-Control': shouldCache + ? 's-maxage=3600, stale-while-revalidate=59' + : 's-maxage=1, stale-while-revalidate=59', + }; +}; diff --git a/src/photo/image-response/components/ImageCaption.tsx b/src/image-response/components/ImageCaption.tsx similarity index 100% rename from src/photo/image-response/components/ImageCaption.tsx rename to src/image-response/components/ImageCaption.tsx diff --git a/src/photo/image-response/components/ImageContainer.tsx b/src/image-response/components/ImageContainer.tsx similarity index 100% rename from src/photo/image-response/components/ImageContainer.tsx rename to src/image-response/components/ImageContainer.tsx diff --git a/src/photo/image-response/components/ImagePhotoGrid.tsx b/src/image-response/components/ImagePhotoGrid.tsx similarity index 100% rename from src/photo/image-response/components/ImagePhotoGrid.tsx rename to src/image-response/components/ImagePhotoGrid.tsx diff --git a/src/photo/image-response/index.ts b/src/image-response/index.ts similarity index 100% rename from src/photo/image-response/index.ts rename to src/image-response/index.ts diff --git a/src/photo/actions.ts b/src/photo/actions.ts index bbbe1865..db8137ec 100644 --- a/src/photo/actions.ts +++ b/src/photo/actions.ts @@ -22,7 +22,7 @@ import { revalidateAdminPaths, revalidateAllKeysAndPaths, revalidatePhotosKey, -} from '@/cache'; +} from '@/photo/cache'; import { PATH_ADMIN_PHOTOS, PATH_ADMIN_TAGS } from '@/site/paths'; import { extractExifDataFromBlobPath } from './server'; import { TAG_FAVS, isTagFavs } from '@/tag'; diff --git a/src/cache/index.ts b/src/photo/cache.ts similarity index 86% rename from src/cache/index.ts rename to src/photo/cache.ts index 179bbbbb..80cde455 100644 --- a/src/cache/index.ts +++ b/src/photo/cache.ts @@ -24,12 +24,8 @@ import { getPhotosNearId, } from '@/services/vercel-postgres'; import { parseCachedPhotoDates, parseCachedPhotosDates } from '@/photo'; -import { getStoragePhotoUrls, getStorageUploadUrls } from '@/services/storage'; -import type { Session } from 'next-auth'; import { createCameraKey } from '@/camera'; import { PATHS_ADMIN } from '@/site/paths'; -import { cache } from 'react'; -import { auth } from '@/auth'; // Table key const KEY_PHOTOS = 'photos'; @@ -209,31 +205,9 @@ export const getUniqueFilmSimulationsCached = [KEY_PHOTOS, KEY_FILM_SIMULATIONS], ); -export const authCached = cache(auth); - -// No Store +// No store export const getPhotoNoStore = (...args: Parameters) => { unstable_noStore(); return getPhoto(...args); }; - -export const getStorageUploadUrlsNoStore: typeof getStorageUploadUrls = - (...args) => { - unstable_noStore(); - return getStorageUploadUrls(...args); - }; - -export const getStoragePhotoUrlsNoStore: typeof getStoragePhotoUrls = - (...args) => { - unstable_noStore(); - return getStoragePhotoUrls(...args); - }; - -export const getImageCacheHeadersForAuth = (session: Session | null) => { - return { - 'Cache-Control': !session?.user - ? 's-maxage=3600, stale-while-revalidate=59' - : 's-maxage=1, stale-while-revalidate=59', - }; -}; diff --git a/src/photo/data.ts b/src/photo/data.ts index b06b5790..9705f779 100644 --- a/src/photo/data.ts +++ b/src/photo/data.ts @@ -3,7 +3,7 @@ import { getUniqueCamerasCached, getUniqueFilmSimulationsCached, getUniqueTagsCached, -} from '@/cache'; +} from '@/photo/cache'; import { SHOW_FILM_SIMULATIONS } from '@/site/config'; import { TAG_FAVS } from '@/tag'; diff --git a/src/services/storage/cache.ts b/src/services/storage/cache.ts new file mode 100644 index 00000000..4bcaf57e --- /dev/null +++ b/src/services/storage/cache.ts @@ -0,0 +1,14 @@ +import { unstable_noStore } from 'next/cache'; +import { getStoragePhotoUrls, getStorageUploadUrls } from '@/services/storage'; + +export const getStorageUploadUrlsNoStore: typeof getStorageUploadUrls = + (...args) => { + unstable_noStore(); + return getStorageUploadUrls(...args); + }; + +export const getStoragePhotoUrlsNoStore: typeof getStoragePhotoUrls = + (...args) => { + unstable_noStore(); + return getStoragePhotoUrls(...args); + }; \ No newline at end of file diff --git a/src/simulation/data.ts b/src/simulation/data.ts index a672c24b..60b2407e 100644 --- a/src/simulation/data.ts +++ b/src/simulation/data.ts @@ -2,7 +2,7 @@ import { getPhotosCached, getPhotosFilmSimulationCountCached, getPhotosFilmSimulationDateRangeCached, -} from '@/cache'; +} from '@/photo/cache'; import { PaginationSearchParams, getPaginationForSearchParams, diff --git a/src/site/Footer.tsx b/src/site/Footer.tsx index 3ab5878f..bd91dfc1 100644 --- a/src/site/Footer.tsx +++ b/src/site/Footer.tsx @@ -1,4 +1,4 @@ -import { authCached } from '@/cache'; +import { authCached } from '@/auth/cache'; import FooterClient from './FooterClient'; export default async function Footer() { diff --git a/src/site/Nav.tsx b/src/site/Nav.tsx index 709bb834..c090f1ea 100644 --- a/src/site/Nav.tsx +++ b/src/site/Nav.tsx @@ -1,4 +1,4 @@ -import { authCached } from '@/cache'; +import { authCached } from '@/auth/cache'; import NavClient from './NavClient'; export default async function Nav() { diff --git a/src/tag/data.ts b/src/tag/data.ts index deb972bb..6396f9b2 100644 --- a/src/tag/data.ts +++ b/src/tag/data.ts @@ -2,7 +2,7 @@ import { getPhotosCached, getPhotosTagCountCached, getPhotosTagDateRangeCached, -} from '@/cache'; +} from '@/photo/cache'; import { PaginationSearchParams, getPaginationForSearchParams,