import { supabase } from '@/lib/supabase';
async function uploadToolLogo(file: File): Promise<string> {
// 1. Valider le fichier
if (file.size > 2 * 1024 * 1024) {
throw new Error('Fichier trop volumineux (max 2MB)');
}
const allowedTypes = ['image/png', 'image/jpeg', 'image/jpg', 'image/svg+xml', 'image/webp'];
if (!allowedTypes.includes(file.type)) {
throw new Error('Format non supporté. Utilisez PNG, JPG, SVG ou WebP');
}
// 2. Générer un nom unique
const fileExt = file.name.split('.').pop();
const fileName = `${Math.random().toString(36).substring(7)}_${Date.now()}.${fileExt}`;
const filePath = `tool_logos/${fileName}`;
// 3. Upload vers Supabase Storage
const { error: uploadError } = await supabase.storage
.from('tool_logos')
.upload(filePath, file, {
cacheControl: '3600',
upsert: false
});
if (uploadError) {
throw new Error(`Erreur upload: ${uploadError.message}`);
}
// 4. Récupérer l'URL publique
const { data } = supabase.storage
.from('tool_logos')
.getPublicUrl(filePath);
return data.publicUrl;
}