diff --git a/src/admin/PhotoSyncButton.tsx b/src/admin/PhotoSyncButton.tsx index 6b25da1c..fd22065f 100644 --- a/src/admin/PhotoSyncButton.tsx +++ b/src/admin/PhotoSyncButton.tsx @@ -72,8 +72,8 @@ export default function PhotoSyncButton({ ) { setIsSyncing(true); (onlySyncColorData - ? storeColorDataForPhotoAction - : syncPhotoAction)(photo.id) + ? storeColorDataForPhotoAction(photo.id) + : syncPhotoAction(photo.id, { updateMode })) .then(() => { onSyncComplete?.(); if (shouldToast) { diff --git a/src/photo/actions.ts b/src/photo/actions.ts index 670033dc..72e00485 100644 --- a/src/photo/actions.ts +++ b/src/photo/actions.ts @@ -491,7 +491,15 @@ export const getExifDataAction = async ( // - strip GPS data if necessary // - update blur data (or destroy if blur is disabled) // - generate AI text data, if enabled, and auto-generated fields are empty -export const syncPhotoAction = async (photoId: string, isBatch?: boolean) => +export const syncPhotoAction = async ( + photoId: string, { + isBatch, + updateMode, + }: { + isBatch?: boolean, + updateMode?: boolean, + } = {}, +) => runAuthenticatedAdminServerAction(async () => { const photo = await getPhoto(photoId ?? '', true); @@ -505,6 +513,12 @@ export const syncPhotoAction = async (photoId: string, isBatch?: boolean) => includeInitialPhotoFields: false, generateBlurData: BLUR_ENABLED, generateResizedImage: AI_CONTENT_GENERATION_ENABLED, + // If in update mode, only update color fields if necessary + updateColorFields: !( + updateMode && + photo.colorData !== undefined && + photo.colorSort !== undefined + ), }); let urlToDelete: string | undefined; @@ -575,7 +589,7 @@ export const syncPhotosAction = async (photosToSync: { for (const { photoId, onlySyncColorData } of photosToSync) { await (onlySyncColorData ? storeColorDataForPhotoAction(photoId) - : syncPhotoAction(photoId, true)); + : syncPhotoAction(photoId, { isBatch: true })); } revalidateAllKeysAndPaths(); }); diff --git a/src/photo/server.ts b/src/photo/server.ts index 948196b3..7ab9b016 100644 --- a/src/photo/server.ts +++ b/src/photo/server.ts @@ -34,11 +34,16 @@ const IMAGE_WIDTH_DEFAULT = 200; const IMAGE_QUALITY_DEFAULT = 80; export const extractImageDataFromBlobPath = async ( - blobPath: string, - options: { + blobPath: string, { + includeInitialPhotoFields, + generateBlurData, + generateResizedImage, + updateColorFields = true, + }: { includeInitialPhotoFields?: boolean generateBlurData?: boolean generateResizedImage?: boolean + updateColorFields?: boolean } = {}, ): Promise<{ blobId?: string @@ -48,12 +53,6 @@ export const extractImageDataFromBlobPath = async ( fileBytes?: ArrayBuffer error?: string }> => { - const { - includeInitialPhotoFields, - generateBlurData, - generateResizedImage, - } = options; - const url = decodeURIComponent(blobPath); const { @@ -119,7 +118,9 @@ export const extractImageDataFromBlobPath = async ( if (error) { console.log(error); } - const colorFields = await getColorFieldsForPhotoForm(url); + const colorFields = updateColorFields + ? await getColorFieldsForPhotoForm(url) + : undefined; return { blobId,