同步 sgs-frontend-mobile 源码
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
lyf
2026-07-27 11:26:01 +08:00
parent 575dca430f
commit 9ea1bfab71
181 changed files with 24395 additions and 5212 deletions

View File

@@ -0,0 +1,56 @@
interface PersistentCacheEntry<T> {
expiresAt: number
data: T
}
const MAX_ENTRY_BYTES = 320 * 1024
const storage = () => {
if (typeof window === 'undefined') return null
try {
return window.localStorage
} catch {
return null
}
}
export const readPersistentJsonCache = <T>(key: string, allowExpired = false): T | null => {
const target = storage()
if (!target) return null
try {
const raw = target.getItem(key)
if (!raw) return null
const entry = JSON.parse(raw) as PersistentCacheEntry<T>
if (!entry || typeof entry.expiresAt !== 'number') {
target.removeItem(key)
return null
}
if (!allowExpired && entry.expiresAt <= Date.now()) return null
return entry.data
} catch {
try {
target.removeItem(key)
} catch {
// Storage may be unavailable or full in an embedded browser.
}
return null
}
}
export const writePersistentJsonCache = <T>(key: string, data: T, ttlMs: number) => {
const target = storage()
if (!target || ttlMs <= 0) return false
try {
const payload = JSON.stringify({
expiresAt: Date.now() + ttlMs,
data
} satisfies PersistentCacheEntry<T>)
if (payload.length * 2 > MAX_ENTRY_BYTES) return false
target.setItem(key, payload)
return true
} catch {
return false
}
}

View File

@@ -22,8 +22,30 @@ const configuredLegacyAudioHosts = () => [
...defaultLegacyAudioHosts
].filter(Boolean)
const resolveSdkMinioProxyBaseUrl = () => {
const apiBaseUrl = dataSourceConfig.apiBaseUrl.trim().replace(/\/+$/, '')
const normalizedApiBaseUrl = apiBaseUrl.endsWith('/app-api')
? apiBaseUrl
: `${apiBaseUrl}/app-api`
return `${normalizedApiBaseUrl}/gis/sdk/minio`
}
const toSdkMinioProxyUrl = (assetPath: string) => `${resolveSdkMinioProxyBaseUrl()}${assetPath}`
export const normalizeSameOriginPublicUrl = (url: string | null | undefined) => {
const value = url?.trim()
// The SDK proxy is public and provides the same disk and HTTP cache used by
// the kiosk client. Guide images and audio should use it instead of bypassing
// the cache through the MinIO public endpoint.
if (value?.startsWith('/minio/museum-assets/')) {
return toSdkMinioProxyUrl(value.replace(/^\/minio/, ''))
}
if (value?.startsWith('/museum-assets/') || value?.startsWith('/tts-audio/')) {
return toSdkMinioProxyUrl(value)
}
if (!value || !isAbsoluteHttpUrl(value)) return value || ''
try {
@@ -38,7 +60,7 @@ export const normalizeSameOriginPublicUrl = (url: string | null | undefined) =>
|| parsed.pathname.startsWith('/tts-audio/')
)
) {
return `${parsed.pathname}${parsed.search}${parsed.hash}`
return toSdkMinioProxyUrl(`${parsed.pathname}${parsed.search}${parsed.hash}`)
}
if (