diff --git a/src/photo/actions.ts b/src/photo/actions.ts index 9fcb94ce..0d433596 100644 --- a/src/photo/actions.ts +++ b/src/photo/actions.ts @@ -15,7 +15,7 @@ import { import { revalidatePhotosTag } from '@/cache'; export async function createPhotoAction(formData: FormData) { - const photo = convertFormDataToPhoto(formData); + const photo = convertFormDataToPhoto(formData, true); const updatedUrl = await convertUploadToPhoto( photo.url, diff --git a/src/photo/form.ts b/src/photo/form.ts index 3ca7d40e..21326a49 100644 --- a/src/photo/form.ts +++ b/src/photo/form.ts @@ -98,7 +98,8 @@ export const convertExifToFormData = ( }); export const convertFormDataToPhoto = ( - formData: FormData + formData: FormData, + generateId?: boolean, ): PhotoDbInsert => { const photoForm = Object.fromEntries(formData) as PhotoFormData; @@ -111,6 +112,7 @@ export const convertFormDataToPhoto = ( return { ...photoForm, + ...(generateId && !photoForm.id) && { id: crypto.randomUUID() }, // convert form strings to arrays tags: convertStringToArray(photoForm.tags), // Convert form strings to numbers diff --git a/src/photo/index.ts b/src/photo/index.ts index 8ec39e49..362afa11 100644 --- a/src/photo/index.ts +++ b/src/photo/index.ts @@ -37,7 +37,6 @@ export interface PhotoExif { // Raw db insert export interface PhotoDbInsert extends PhotoExif { id: string - idShort: string url: string extension: string blurData: string @@ -57,6 +56,7 @@ export interface PhotoDb extends Omit { // Parsed db response export interface Photo extends PhotoDb { + idShort?: string focalLengthFormatted?: string focalLengthIn35MmFormatFormatted?: string fNumberFormatted?: string diff --git a/src/services/postgres.ts b/src/services/postgres.ts index 5c288faf..09f19f7b 100644 --- a/src/services/postgres.ts +++ b/src/services/postgres.ts @@ -47,6 +47,7 @@ const sqlCreatePhotosTable = () => export const sqlInsertPhotoIntoDb = (photo: PhotoDbInsert) => { return sql` INSERT INTO photos ( + id, url, extension, aspect_ratio, @@ -70,6 +71,7 @@ export const sqlInsertPhotoIntoDb = (photo: PhotoDbInsert) => { taken_at_naive ) VALUES ( + ${photo.id}, ${photo.url}, ${photo.extension}, ${photo.aspectRatio},