Mark exif server actions as node runtime
This commit is contained in:
parent
06eed08256
commit
22180e96cb
@ -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, syncPhotoExifDataAction } from '@/photo/actions';
|
||||
import { deletePhotoAction } from '@/photo/actions';
|
||||
import {
|
||||
pathForAdminPhotos,
|
||||
pathForPhoto,
|
||||
@ -30,6 +30,7 @@ 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';
|
||||
|
||||
|
||||
@ -7,9 +7,9 @@ import SubmitButtonWithStatus from '@/components/SubmitButtonWithStatus';
|
||||
import { PhotoFormData, convertPhotoToFormData } from './form';
|
||||
import PhotoForm from './PhotoForm';
|
||||
import { useFormState } from 'react-dom';
|
||||
import { getExifDataAction } from './actions';
|
||||
import { areSimpleObjectsEqual } from '@/utility/object';
|
||||
import IconGrSync from '@/site/IconGrSync';
|
||||
import { getExifDataAction } from './actions-node';
|
||||
|
||||
export default function PhotoEditPageClient({
|
||||
photo,
|
||||
|
||||
46
src/photo/actions-node.ts
Normal file
46
src/photo/actions-node.ts
Normal file
@ -0,0 +1,46 @@
|
||||
'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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -6,12 +6,9 @@ import {
|
||||
sqlDeletePhotoTagGlobally,
|
||||
sqlUpdatePhoto,
|
||||
sqlRenamePhotoTagGlobally,
|
||||
getPhoto,
|
||||
} from '@/services/postgres';
|
||||
import {
|
||||
PhotoFormData,
|
||||
convertFormDataToPhotoDbInsert,
|
||||
convertPhotoToFormData,
|
||||
} from './form';
|
||||
import { redirect } from 'next/navigation';
|
||||
import {
|
||||
@ -25,7 +22,6 @@ 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);
|
||||
@ -92,37 +88,6 @@ 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();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user