better theme for tv
This commit is contained in:
@@ -1,6 +1,11 @@
|
||||
import type { AppConfig } from '@/config/types'
|
||||
import { getConfig, getRawAppConfig } from '@/config/app-config'
|
||||
import { getConfigUrls, sortConfigUrls } from '@/config/load-config'
|
||||
import {
|
||||
getSuperAdminBase,
|
||||
isSuperAdminUrl,
|
||||
resolveTenantDomain,
|
||||
} from '@/config/superadmin'
|
||||
import {
|
||||
clearCachedPwaManifest,
|
||||
readCachedPwaManifest,
|
||||
@@ -23,7 +28,24 @@ function sleep(ms: number) {
|
||||
}
|
||||
|
||||
function normalizeBaseUrl(url: string) {
|
||||
return url.replace(/\/get_user\/?$/i, '').replace(/\/+$/, '')
|
||||
try {
|
||||
const parsed = new URL(url)
|
||||
parsed.search = ''
|
||||
parsed.hash = ''
|
||||
parsed.pathname = parsed.pathname
|
||||
.replace(/\/get_user\/?$/i, '')
|
||||
.replace(/\/manifest\.json$/i, '')
|
||||
if (!parsed.pathname || parsed.pathname === '/') {
|
||||
return parsed.origin
|
||||
}
|
||||
return `${parsed.origin}${parsed.pathname.replace(/\/+$/, '')}`
|
||||
} catch {
|
||||
return url
|
||||
.replace(/[?#].*$/, '')
|
||||
.replace(/\/get_user\/?$/i, '')
|
||||
.replace(/\/manifest\.json$/i, '')
|
||||
.replace(/\/+$/, '')
|
||||
}
|
||||
}
|
||||
|
||||
/** همان baseای که get_user از آن لود شده (کش شده در localStorage) */
|
||||
@@ -33,15 +55,28 @@ export function getConfigBaseFromStorage() {
|
||||
return normalizeBaseUrl(lastSuccess)
|
||||
}
|
||||
|
||||
function getSuperAdminManifestUrl(): string | null {
|
||||
const saBase = getSuperAdminBase()
|
||||
if (!saBase) return null
|
||||
return `${saBase}/manifest.json?domain=${encodeURIComponent(resolveTenantDomain())}`
|
||||
}
|
||||
|
||||
function configUrlToManifestUrl(configUrl: string) {
|
||||
return `${configUrl.replace(/\/+$/, '')}/manifest.json`
|
||||
if (isSuperAdminUrl(configUrl)) {
|
||||
return getSuperAdminManifestUrl() || `${normalizeBaseUrl(configUrl)}/manifest.json`
|
||||
}
|
||||
return `${normalizeBaseUrl(configUrl)}/manifest.json`
|
||||
}
|
||||
|
||||
/** همان ۵ URL پایهٔ get_user — اولویت با CONFIG_Success_URL */
|
||||
export function resolveManifestUrls(config?: AppConfig | null): string[] {
|
||||
const explicit = getConfig<string>('manifest_url')
|
||||
if (explicit) return [explicit]
|
||||
|
||||
const saManifest = getSuperAdminManifestUrl()
|
||||
if (saManifest) {
|
||||
return [saManifest]
|
||||
}
|
||||
|
||||
return sortConfigUrls(getConfigUrls()).map(configUrlToManifestUrl)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user