Link photo id to blob url
This commit is contained in:
parent
2d0fb2f9e3
commit
c51cd57365
@ -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,
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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<PhotoDbInsert, 'takenAt' | 'tags'> {
|
||||
|
||||
// Parsed db response
|
||||
export interface Photo extends PhotoDb {
|
||||
idShort?: string
|
||||
focalLengthFormatted?: string
|
||||
focalLengthIn35MmFormatFormatted?: string
|
||||
fNumberFormatted?: string
|
||||
|
||||
@ -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},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user