From 1d6660639a139fbeac4e4dd8a43fd34a110b3387 Mon Sep 17 00:00:00 2001 From: Babayaga Date: Wed, 8 Apr 2026 12:04:16 +0200 Subject: [PATCH] supabase --- packages/ui/src/components/ImageWizard/db.ts | 17 +++++++++++++++-- packages/ui/src/lib/uploadUtils.ts | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/ui/src/components/ImageWizard/db.ts b/packages/ui/src/components/ImageWizard/db.ts index a6cfe19c..e04eaa70 100644 --- a/packages/ui/src/components/ImageWizard/db.ts +++ b/packages/ui/src/components/ImageWizard/db.ts @@ -12,12 +12,20 @@ import { uploadFileToStorage, addCollectionPictures, } from "@/modules/posts/client-pictures"; +import { uploadImage } from "@/lib/uploadUtils"; import { getUserOpenAIKey } from "@/modules/user/client-user"; import { supabase } from "@/integrations/supabase/client"; // Re-export for backward compat export { getUserOpenAIKey }; +// Internal trial switch for wizard uploads. +// - "vfs": upload through /api/images (current trial path) +// - "supabase": legacy direct storage upload +const WIZARD_UPLOAD_BACKEND = (import.meta.env.VITE_IMAGE_WIZARD_UPLOAD_BACKEND || 'vfs').toLowerCase() === 'supabase' + ? 'supabase' + : 'vfs'; + /** * Load saved wizard model from user_secrets.settings.wizard_model */ @@ -76,6 +84,10 @@ export const uploadImageToStorage = async ( ): Promise<{ fileName: string; publicUrl: string } | null> => { const fileName = `${userId}/${Date.now()}-${suffix}.png`; const file = new File([blob], fileName, { type: 'image/png' }); + if (WIZARD_UPLOAD_BACKEND === 'vfs') { + const { publicUrl } = await uploadImage(file, userId); + return { fileName, publicUrl }; + } const publicUrl = await uploadFileToStorage(userId, file, fileName); return { fileName, publicUrl }; }; @@ -91,7 +103,7 @@ export const createPictureRecord = async (params: { parentId?: string | null; isSelected?: boolean; }): Promise<{ id: string } | null> => { - return createPicture({ + const created = await createPicture({ title: params.title?.trim() || null, description: params.description || null, image_url: params.imageUrl, @@ -99,6 +111,7 @@ export const createPictureRecord = async (params: { parent_id: params.parentId || null, is_selected: params.isSelected ?? false, } as any); + return (created as { id: string } | null) || null; }; /** @@ -266,7 +279,7 @@ export const publishImageToPost = async (params: { user_id: userId, post_id: postId, is_selected: true, - } as any); + } as any) as { id: string } | null; if (!pictureData) throw new Error('Failed to create picture record'); diff --git a/packages/ui/src/lib/uploadUtils.ts b/packages/ui/src/lib/uploadUtils.ts index 58b8ac25..a08f965c 100644 --- a/packages/ui/src/lib/uploadUtils.ts +++ b/packages/ui/src/lib/uploadUtils.ts @@ -57,7 +57,7 @@ export const createPictureRecord = async (userId: string, file: File, publicUrl: title: file.name.split('.')[0] || 'Uploaded Image', description: null, image_url: publicUrl, - type: IMAGE_UPLOAD_FORWARD_PRESET === 'vfs' ? 'vfs-image' : 'supabase-image', + type: 'supabase-image', meta: meta || {}, }) .select()