Files
Zbrane-Reiner-Web/src/lib/format.ts
T
HonzaandClaude Opus 5 1c51034031
CI / test (push) Successful in 1m50s
CI / build-and-push (push) Successful in 2m27s
Opravit nezobrazování obrázků na webu
Payload skládá URL uploadů absolutně podle serverURL. next/image to
vyhodnotí jako externí zdroj a bez images.remotePatterns odmítne
s HTTP 400 "url parameter is not allowed" — samotný soubor se přitom
servíruje správně, takže se to projevilo až s nahraným obrázkem.

Do next/image proto posíláme jen cestu (helper cestaKSouboru). Soubor
leží na stejném originu jako web, takže je to korektní, a navíc na tom
nezávisí doména: remotePatterns se zapékají při buildu, ale tentýž image
běží na stagingu i v produkci pod jiným jménem.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-30 16:44:54 +02:00

34 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type { Product } from '@/payload-types'
/**
* Payload skládá URL obrázků absolutně podle `serverURL`
* (`https://…/api/media/file/x.png`). `next/image` by to bral jako cizí zdroj
* a bez `remotePatterns` ho odmítne s „url parameter is not allowed".
*
* Doménu proto zahazujeme — soubor leží na stejném originu jako web. Navíc
* je tím stejný image použitelný na stagingu i v produkci, kde se domény liší;
* `remotePatterns` se zapékají při buildu, takže by to jinak nešlo.
*/
export function cestaKSouboru(url: string): string {
try {
return new URL(url).pathname
} catch {
return url // už je relativní
}
}
/** `28900` → `28 900 Kč` (pevná mezera, ať se cena nezalomí). */
export function formatujCenu(cena: number): string {
return `${cena.toLocaleString('cs-CZ').replace(/\s/g, ' ')} Kč`
}
const STAVY: Record<Product['stav'], string> = {
skladem: 'Skladem',
'na-objednavku': 'Na objednávku',
prodano: 'Prodáno',
}
export function popisStavu(stav: Product['stav']): string {
return STAVY[stav]
}