From bf065c0fedcb7aef814f547c82e8c7309d16b953 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Thu, 2 Nov 2023 19:20:55 -0500 Subject: [PATCH] Undo node server actions --- src/app/(auth-state)/admin/photos/page.tsx | 3 +- src/photo/PhotoEditPageClient.tsx | 2 +- src/photo/actions-node.ts | 46 ---------------------- src/photo/actions.ts | 35 ++++++++++++++++ 4 files changed, 37 insertions(+), 49 deletions(-) delete mode 100644 src/photo/actions-node.ts diff --git a/src/app/(auth-state)/admin/photos/page.tsx b/src/app/(auth-state)/admin/photos/page.tsx index 918201c8..4feb9165 100644 --- a/src/app/(auth-state)/admin/photos/page.tsx +++ b/src/app/(auth-state)/admin/photos/page.tsx @@ -5,7 +5,7 @@ import PhotoTiny from '@/photo/PhotoTiny'; import { cc } from '@/utility/css'; import FormWithConfirm from '@/components/FormWithConfirm'; import SiteGrid from '@/components/SiteGrid'; -import { deletePhotoAction } from '@/photo/actions'; +import { deletePhotoAction, syncPhotoExifDataAction } from '@/photo/actions'; import { pathForAdminPhotos, pathForPhoto, @@ -30,7 +30,6 @@ import BlobUrls from '@/admin/BlobUrls'; import { PRO_MODE_ENABLED } from '@/site/config'; import SubmitButtonWithStatus from '@/components/SubmitButtonWithStatus'; import IconGrSync from '@/site/IconGrSync'; -import { syncPhotoExifDataAction } from '@/photo/actions-node'; export const runtime = 'edge'; diff --git a/src/photo/PhotoEditPageClient.tsx b/src/photo/PhotoEditPageClient.tsx index 0327e656..9634a9db 100644 --- a/src/photo/PhotoEditPageClient.tsx +++ b/src/photo/PhotoEditPageClient.tsx @@ -9,7 +9,7 @@ import PhotoForm from './PhotoForm'; import { useFormState } from 'react-dom'; import { areSimpleObjectsEqual } from '@/utility/object'; import IconGrSync from '@/site/IconGrSync'; -import { getExifDataAction } from './actions-node'; +import { getExifDataAction } from './actions'; export default function PhotoEditPageClient({ photo, diff --git a/src/photo/actions-node.ts b/src/photo/actions-node.ts deleted file mode 100644 index 72fa1dfd..00000000 --- a/src/photo/actions-node.ts +++ /dev/null @@ -1,46 +0,0 @@ -'use server'; - -import { - sqlUpdatePhoto, - getPhoto, -} from '@/services/postgres'; -import { - PhotoFormData, - convertFormDataToPhotoDbInsert, - convertPhotoToFormData, -} from './form'; -import { revalidatePhotosKey } from '@/cache'; -import { extractExifDataFromBlobPath } from './server'; - -export const runtime = 'nodejs'; - -export async function getExifDataAction( - photoFormPrevious: Partial, -): Promise> { - const { url } = photoFormPrevious; - if (url) { - const { photoFormExif } = await extractExifDataFromBlobPath(url); - if (photoFormExif) { - return photoFormExif; - } - } - return {}; -} - -export async function syncPhotoExifDataAction(formData: FormData) { - const photoId = formData.get('id') as string; - if (photoId) { - const photo = await getPhoto(photoId); - if (photo) { - const { photoFormExif } = await extractExifDataFromBlobPath(photo.url); - if (photoFormExif) { - const photoFormDbInsert = convertFormDataToPhotoDbInsert({ - ...convertPhotoToFormData(photo), - ...photoFormExif, - }); - await sqlUpdatePhoto(photoFormDbInsert); - revalidatePhotosKey(); - } - } - } -} diff --git a/src/photo/actions.ts b/src/photo/actions.ts index 8d3e13d5..6d30cdce 100644 --- a/src/photo/actions.ts +++ b/src/photo/actions.ts @@ -6,9 +6,12 @@ import { sqlDeletePhotoTagGlobally, sqlUpdatePhoto, sqlRenamePhotoTagGlobally, + getPhoto, } from '@/services/postgres'; import { + PhotoFormData, convertFormDataToPhotoDbInsert, + convertPhotoToFormData, } from './form'; import { redirect } from 'next/navigation'; import { @@ -22,6 +25,7 @@ import { revalidatePhotosKey, } from '@/cache'; import { PATH_ADMIN_PHOTOS, PATH_ADMIN_TAGS } from '@/site/paths'; +import { extractExifDataFromBlobPath } from './server'; export async function createPhotoAction(formData: FormData) { const photo = convertFormDataToPhotoDbInsert(formData, true); @@ -88,6 +92,37 @@ export async function deleteBlobPhotoAction(formData: FormData) { } } +export async function getExifDataAction( + photoFormPrevious: Partial, +): Promise> { + const { url } = photoFormPrevious; + if (url) { + const { photoFormExif } = await extractExifDataFromBlobPath(url); + if (photoFormExif) { + return photoFormExif; + } + } + return {}; +} + +export async function syncPhotoExifDataAction(formData: FormData) { + const photoId = formData.get('id') as string; + if (photoId) { + const photo = await getPhoto(photoId); + if (photo) { + const { photoFormExif } = await extractExifDataFromBlobPath(photo.url); + if (photoFormExif) { + const photoFormDbInsert = convertFormDataToPhotoDbInsert({ + ...convertPhotoToFormData(photo), + ...photoFormExif, + }); + await sqlUpdatePhoto(photoFormDbInsert); + revalidatePhotosKey(); + } + } + } +} + export async function syncCacheAction() { revalidateAllKeysAndPaths(); }