Undo node server actions

This commit is contained in:
Sam Becker 2023-11-02 19:20:55 -05:00
parent 22180e96cb
commit bf065c0fed
4 changed files with 37 additions and 49 deletions

View File

@ -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';

View File

@ -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,

View File

@ -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<PhotoFormData>,
): Promise<Partial<PhotoFormData>> {
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();
}
}
}
}

View File

@ -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<PhotoFormData>,
): Promise<Partial<PhotoFormData>> {
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();
}