fix: restore BottleGrid and apply storage URL normalization
This commit is contained in:
@@ -9,4 +9,32 @@ if (!supabaseUrl || !supabaseAnonKey) {
|
||||
|
||||
export const supabase = (supabaseUrl && supabaseAnonKey)
|
||||
? createClient(supabaseUrl, supabaseAnonKey)
|
||||
: null as any; // Fallback or handle null in services
|
||||
: null as any;
|
||||
|
||||
/**
|
||||
* Normalisiert eine Storage-URL oder einen Pfad.
|
||||
* Verhindert "Mixed Content"-Fehler in Self-Hosted Setups,
|
||||
* indem interne IPs durch die öffentliche URL ersetzt werden.
|
||||
*/
|
||||
export function getStorageUrl(path: string | null | undefined): string {
|
||||
if (!path) return '';
|
||||
|
||||
const baseUrl = process.env.NEXT_PUBLIC_SUPABASE_URL?.replace(/\/$/, '');
|
||||
if (!baseUrl) return path;
|
||||
|
||||
// Wenn es bereits eine URL ist
|
||||
if (path.startsWith('http')) {
|
||||
// Falls die URL eine interne IP enthält (z.B. 192.168.x.x oder localhost)
|
||||
// oder falls sie über http statt https kommt (obwohl die App https nutzt)
|
||||
if (path.includes('192.168.') || path.includes('localhost') || (baseUrl.startsWith('https') && path.startsWith('http:'))) {
|
||||
const storagePathMatch = path.match(/\/storage\/v1\/object\/public\/bottles\/(.+)$/);
|
||||
if (storagePathMatch) {
|
||||
return `${baseUrl}/storage/v1/object/public/bottles/${storagePathMatch[1]}`;
|
||||
}
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
// Wenn es nur ein Pfad ist, vervollständigen
|
||||
return `${baseUrl}/storage/v1/object/public/bottles/${path}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user