Port modular price, product, and PWA fixes into boursecu
Sync live quote handling, SSE product images, store hours, file URL normalization, PWA icon cache, TV monitor, about software, SuperAdmin menu gates, price alerts, and related UX from modular while preserving boursecu branding and config constraints. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import type { AppConfig } from '@/config/types'
|
||||
import { resetVersionCheckCache } from '@/config/load-version'
|
||||
import { clearCachedPwaManifest } from '@/modules/pwa/manifest-cache'
|
||||
import { resolveTenantDomain } from '@/config/superadmin'
|
||||
import { collectAuthTokensForPreserve } from '@/utils/authToken'
|
||||
|
||||
const CONFIG_COOKIE_NAME = 'APP_CONFIG_CACHE'
|
||||
const APP_CONFIG_LS_KEY = 'APP_CONFIG_LS_CACHE'
|
||||
const CONFIG_SUCCESS_URL_KEY = 'CONFIG_Success_URL'
|
||||
const VERSION_SUCCESS_URL_KEY = 'VERSION_Success_URL'
|
||||
const CONFIG_COOKIE_MAX_AGE_SECONDS = 60 * 60 * 24 * 7
|
||||
@@ -18,6 +20,13 @@ type CachedConfigPayload = {
|
||||
config: AppConfig
|
||||
}
|
||||
|
||||
export type VersionedAppConfigCache = {
|
||||
version: string
|
||||
domain: string
|
||||
cached_at: number
|
||||
config: AppConfig
|
||||
}
|
||||
|
||||
type VersionUpdateLock = {
|
||||
version: string
|
||||
started_at: number
|
||||
@@ -62,6 +71,54 @@ export function readCachedAppConfig(): AppConfig | null {
|
||||
}
|
||||
}
|
||||
|
||||
/** کش بزرگ get_user در localStorage — با version باطل میشود */
|
||||
export function readVersionedAppConfigCache(domain?: string): VersionedAppConfigCache | null {
|
||||
try {
|
||||
const raw = localStorage.getItem(APP_CONFIG_LS_KEY)
|
||||
if (!raw) return null
|
||||
|
||||
const payload = JSON.parse(raw) as VersionedAppConfigCache
|
||||
if (!payload?.config || !payload.version) return null
|
||||
|
||||
if (domain && payload.domain && payload.domain !== domain) {
|
||||
return null
|
||||
}
|
||||
|
||||
return payload
|
||||
} catch (error) {
|
||||
console.warn('Failed to read versioned app config cache:', error)
|
||||
clearVersionedAppConfigCache()
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export function writeVersionedAppConfigCache(
|
||||
config: AppConfig,
|
||||
version: string,
|
||||
domain: string,
|
||||
) {
|
||||
const normalizedVersion = String(version || '').trim()
|
||||
if (!normalizedVersion) return
|
||||
|
||||
try {
|
||||
const payload: VersionedAppConfigCache = {
|
||||
version: normalizedVersion,
|
||||
domain: String(domain || '').trim(),
|
||||
cached_at: Date.now(),
|
||||
config,
|
||||
}
|
||||
localStorage.setItem(APP_CONFIG_LS_KEY, JSON.stringify(payload))
|
||||
} catch (error) {
|
||||
console.warn('Failed to write versioned app config cache:', error)
|
||||
}
|
||||
|
||||
writeCachedAppConfig(config)
|
||||
}
|
||||
|
||||
export function clearVersionedAppConfigCache() {
|
||||
localStorage.removeItem(APP_CONFIG_LS_KEY)
|
||||
}
|
||||
|
||||
export function writeCachedAppConfig(config: AppConfig) {
|
||||
try {
|
||||
const payload: CachedConfigPayload = {
|
||||
@@ -84,6 +141,7 @@ export function writeCachedAppConfig(config: AppConfig) {
|
||||
|
||||
export function clearCachedAppConfig() {
|
||||
document.cookie = `${CONFIG_COOKIE_NAME}=; Path=/; Max-Age=0; SameSite=Lax`
|
||||
clearVersionedAppConfigCache()
|
||||
clearCachedPwaManifest()
|
||||
}
|
||||
|
||||
@@ -223,6 +281,7 @@ export function clearAppStorageExceptToken() {
|
||||
export function clearAllBootstrapFetchCaches() {
|
||||
localStorage.removeItem(CONFIG_SUCCESS_URL_KEY)
|
||||
localStorage.removeItem(VERSION_SUCCESS_URL_KEY)
|
||||
clearVersionedAppConfigCache()
|
||||
clearCachedPwaManifest()
|
||||
resetVersionCheckCache()
|
||||
window.__APP_CONFIG__ = undefined
|
||||
@@ -253,6 +312,7 @@ export async function refreshConfigCacheForVersion(
|
||||
await clearBrowserRuntimeCaches()
|
||||
|
||||
writeCachedAppConfig(freshConfig)
|
||||
writeVersionedAppConfigCache(freshConfig, normalizedVersion, resolveTenantDomain())
|
||||
finishVersionUpdateBeforeReload(normalizedVersion)
|
||||
|
||||
return freshConfig
|
||||
@@ -275,6 +335,7 @@ export async function resetAppAndRefreshConfig(
|
||||
|
||||
if (normalizedVersion) {
|
||||
writeStoredAppVersion(normalizedVersion)
|
||||
writeVersionedAppConfigCache(freshConfig, normalizedVersion, resolveTenantDomain())
|
||||
}
|
||||
|
||||
return freshConfig
|
||||
|
||||
Reference in New Issue
Block a user