add reygiri page

This commit is contained in:
2026-07-12 17:51:48 +02:00
parent b8bdf8228c
commit b2e59464a4
6 changed files with 410 additions and 5 deletions
+48
View File
@@ -0,0 +1,48 @@
import type { Const } from '@/model/const'
import type { CaptureSite } from '@/model/captureSite'
export const REYGIri_SITES_KEY = 'reygiri_sites'
export function normalizeReygiriSitesConst(response: Const | Const[] | null | undefined): {
constId: number | null
sites: CaptureSite[]
} {
const record = Array.isArray(response) ? response[0] : response
if (!record) {
return { constId: null, sites: [] }
}
return {
constId: record.id ?? record.const_id ?? null,
sites: parseReygiriSitesValue(record.value),
}
}
export function parseReygiriSitesValue(value: string | null | undefined): CaptureSite[] {
if (!value) return []
try {
const parsed = JSON.parse(value)
if (!Array.isArray(parsed)) return []
return parsed
.map((item, index) => ({
id: String(item?.id ?? `site-${index + 1}`),
name: String(item?.name ?? item?.title ?? item?.title_fa ?? item?.caption ?? '').trim(),
url: String(item?.url ?? item?.link ?? item?.value ?? '').trim(),
}))
.filter((item) => item.name && item.url)
} catch {
return []
}
}
export function serializeReygiriSites(sites: CaptureSite[]): string {
return JSON.stringify(
sites.map(({ id, name, url }) => ({
id,
name,
url,
}))
)
}