fix(netflow): пропустить загрузку флага неизвестной страны
This commit is contained in:
1 parent
cf211f7418
commit
5d181e7cb0
2 files changed
+28
-7
No files matched your search
+11
-5
@@ -59,10 +59,17 @@ function nearestCdnSize(px: number): number {
|
||||
return CDN_SIZES.find(s => s >= px) ?? CDN_SIZES[CDN_SIZES.length - 1]
|
||||
}
|
||||
|
||||
function flagCode(code: string): string | null {
|
||||
if (!code) return null
|
||||
const lower = code.toLowerCase()
|
||||
// The server catalogue uses UN when the country is unknown.
|
||||
return lower !== "un" && /^[a-z]{2}$/.test(lower) ? lower : null
|
||||
}
|
||||
|
||||
/** CDN URL for SVG `<image href>` (flagcdn widths only). */
|
||||
export function flagCdnUrl(code: string, size = 40): string | null {
|
||||
const lower = code.toLowerCase()
|
||||
if (!/^[a-z]{2}$/.test(lower)) return null
|
||||
const lower = flagCode(code)
|
||||
if (!lower) return null
|
||||
return `https://flagcdn.com/w${nearestCdnSize(size)}/${lower}.png`
|
||||
}
|
||||
|
||||
@@ -71,9 +78,8 @@ export function flagCdnUrl(code: string, size = 40): string | null {
|
||||
* Source: https://flagcdn.com — free CDN, no API key needed.
|
||||
*/
|
||||
export function Flag({ code, size = 20, className }: FlagProps) {
|
||||
if (!code) return null
|
||||
const lower = code.toLowerCase()
|
||||
if (!/^[a-z]{2}$/.test(lower)) return null
|
||||
const lower = flagCode(code)
|
||||
if (!lower) return null
|
||||
const name = countryName(code.toUpperCase())
|
||||
const cdnSrc = nearestCdnSize(size)
|
||||
const cdnSrc2x = nearestCdnSize(size * 2)
|
||||
|
||||
Reference in new issue
Block a user