mirror of
https://github.com/lucasrcsantana/story-generator.git
synced 2025-12-18 06:17:56 +00:00
- Adiciona verificação de URLs indefinidas - Implementa fallback para imagem padrão - Corrige tipagem em getOptimizedImageUrl - Padroniza otimização em edge functions - Previne erros de runtime
35 lines
792 B
TypeScript
35 lines
792 B
TypeScript
interface ImageOptions {
|
|
width?: number;
|
|
height?: number;
|
|
quality?: number;
|
|
}
|
|
|
|
export function getOptimizedImageUrl(url: string | undefined, options: ImageOptions = {}): string {
|
|
// Retorna uma imagem padrão ou vazia se a URL for undefined
|
|
if (!url) {
|
|
return '/placeholder-image.jpg'; // ou retorne uma imagem padrão apropriada
|
|
}
|
|
|
|
const {
|
|
width = 800,
|
|
height = undefined,
|
|
quality = 80
|
|
} = options;
|
|
|
|
// Se for URL do Supabase Storage
|
|
if (url.includes('storage.googleapis.com')) {
|
|
const params = new URLSearchParams({
|
|
width: width.toString(),
|
|
quality: quality.toString(),
|
|
format: 'webp'
|
|
});
|
|
|
|
if (height) {
|
|
params.append('height', height.toString());
|
|
}
|
|
|
|
return `${url}?${params.toString()}`;
|
|
}
|
|
|
|
return url;
|
|
}
|