feat: setup Supabase Storage bucket for restaurant assets and add mobile upload helper

This commit is contained in:
AyrisAI
2026-08-20 17:30:22 +03:00
parent 5122ec24fc
commit 5cbd80326f
3 changed files with 75 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
import { supabase } from "./supabase";
export const BUCKET_NAME = "restaurant-assets";
export type AssetFolder = "logos" | "covers" | "items";
/**
* Uploads an image file (logo, cover banner, item photo) to Supabase Storage
* and returns the public CDN URL.
*/
export async function uploadImageToSupabase(
fileUri: string,
folder: AssetFolder = "items"
): Promise<string> {
const response = await fetch(fileUri);
const blob = await response.blob();
const fileExt = fileUri.split(".").pop()?.toLowerCase() || "jpg";
const fileName = `${folder}/${Date.now()}-${Math.random().toString(36).substring(2, 9)}.${fileExt}`;
const { data, error } = await supabase.storage
.from(BUCKET_NAME)
.upload(fileName, blob, {
contentType: `image/${fileExt === "png" ? "png" : "jpeg"}`,
upsert: true,
});
if (error) {
throw new Error(`Resim yükleme hatası: ${error.message}`);
}
const { data: publicUrlData } = supabase.storage
.from(BUCKET_NAME)
.getPublicUrl(data.path);
return publicUrlData.publicUrl;
}