Link photo id to blob url

This commit is contained in:
Sam Becker 2023-09-18 15:48:15 -05:00
parent 2d0fb2f9e3
commit c51cd57365
4 changed files with 7 additions and 3 deletions

View File

@ -15,7 +15,7 @@ import {
import { revalidatePhotosTag } from '@/cache'; import { revalidatePhotosTag } from '@/cache';
export async function createPhotoAction(formData: FormData) { export async function createPhotoAction(formData: FormData) {
const photo = convertFormDataToPhoto(formData); const photo = convertFormDataToPhoto(formData, true);
const updatedUrl = await convertUploadToPhoto( const updatedUrl = await convertUploadToPhoto(
photo.url, photo.url,

View File

@ -98,7 +98,8 @@ export const convertExifToFormData = (
}); });
export const convertFormDataToPhoto = ( export const convertFormDataToPhoto = (
formData: FormData formData: FormData,
generateId?: boolean,
): PhotoDbInsert => { ): PhotoDbInsert => {
const photoForm = Object.fromEntries(formData) as PhotoFormData; const photoForm = Object.fromEntries(formData) as PhotoFormData;
@ -111,6 +112,7 @@ export const convertFormDataToPhoto = (
return { return {
...photoForm, ...photoForm,
...(generateId && !photoForm.id) && { id: crypto.randomUUID() },
// convert form strings to arrays // convert form strings to arrays
tags: convertStringToArray(photoForm.tags), tags: convertStringToArray(photoForm.tags),
// Convert form strings to numbers // Convert form strings to numbers

View File

@ -37,7 +37,6 @@ export interface PhotoExif {
// Raw db insert // Raw db insert
export interface PhotoDbInsert extends PhotoExif { export interface PhotoDbInsert extends PhotoExif {
id: string id: string
idShort: string
url: string url: string
extension: string extension: string
blurData: string blurData: string
@ -57,6 +56,7 @@ export interface PhotoDb extends Omit<PhotoDbInsert, 'takenAt' | 'tags'> {
// Parsed db response // Parsed db response
export interface Photo extends PhotoDb { export interface Photo extends PhotoDb {
idShort?: string
focalLengthFormatted?: string focalLengthFormatted?: string
focalLengthIn35MmFormatFormatted?: string focalLengthIn35MmFormatFormatted?: string
fNumberFormatted?: string fNumberFormatted?: string

View File

@ -47,6 +47,7 @@ const sqlCreatePhotosTable = () =>
export const sqlInsertPhotoIntoDb = (photo: PhotoDbInsert) => { export const sqlInsertPhotoIntoDb = (photo: PhotoDbInsert) => {
return sql` return sql`
INSERT INTO photos ( INSERT INTO photos (
id,
url, url,
extension, extension,
aspect_ratio, aspect_ratio,
@ -70,6 +71,7 @@ export const sqlInsertPhotoIntoDb = (photo: PhotoDbInsert) => {
taken_at_naive taken_at_naive
) )
VALUES ( VALUES (
${photo.id},
${photo.url}, ${photo.url},
${photo.extension}, ${photo.extension},
${photo.aspectRatio}, ${photo.aspectRatio},