This commit is contained in:
lovebird 2026-04-08 12:04:16 +02:00
parent 27bf61cea8
commit 1d6660639a
2 changed files with 16 additions and 3 deletions

View File

@ -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');

View File

@ -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()