fix: rewrite nerkh logo URLs to the SuperAdmin host
App logos now follow get_user.user.avatar instead of leftover nerkh.gold paths. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
+37
-7
@@ -220,6 +220,36 @@
|
|||||||
|
|
||||||
var BOOT_LOGO_KEY = 'BOOT_LOGO_URL'
|
var BOOT_LOGO_KEY = 'BOOT_LOGO_URL'
|
||||||
var BOOT_LOGO_VERSION_KEY = 'BOOT_LOGO_VERSION'
|
var BOOT_LOGO_VERSION_KEY = 'BOOT_LOGO_VERSION'
|
||||||
|
var LEGACY_LOGO_HOSTS = {
|
||||||
|
'nerkh.gold': 1,
|
||||||
|
'www.nerkh.gold': 1,
|
||||||
|
'tablo.talasevin.ir': 1,
|
||||||
|
'ah.aygingold.ir': 1,
|
||||||
|
'abshode-service.montgit.ir': 1
|
||||||
|
}
|
||||||
|
|
||||||
|
function rewriteLegacyBootLogoUrl(url) {
|
||||||
|
var value = String(url || '').trim()
|
||||||
|
if (!value || !/^https?:\/\//i.test(value)) return value
|
||||||
|
try {
|
||||||
|
var parsed = new URL(value)
|
||||||
|
var host = String(parsed.hostname || '').toLowerCase()
|
||||||
|
if (!LEGACY_LOGO_HOSTS[host]) return value
|
||||||
|
if (!/\/uploads\//i.test(parsed.pathname || '')) return value
|
||||||
|
var base = 'https://adm.montzar.ir'
|
||||||
|
try {
|
||||||
|
var last = localStorage.getItem('CONFIG_Success_URL')
|
||||||
|
if (last) {
|
||||||
|
var sa = new URL(last)
|
||||||
|
var path = sa.pathname.replace(/\/get_user\/?$/i, '').replace(/\/+$/, '')
|
||||||
|
base = path && path !== '/' ? sa.origin + path : sa.origin
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
return base + parsed.pathname
|
||||||
|
} catch (e) {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function pickAvatarRaw(value) {
|
function pickAvatarRaw(value) {
|
||||||
if (value == null) return ''
|
if (value == null) return ''
|
||||||
@@ -253,21 +283,21 @@
|
|||||||
function resolveAbsoluteLogoUrl(raw) {
|
function resolveAbsoluteLogoUrl(raw) {
|
||||||
if (!raw) return ''
|
if (!raw) return ''
|
||||||
if (/^(https?:\/\/|data:|blob:)/i.test(raw)) {
|
if (/^(https?:\/\/|data:|blob:)/i.test(raw)) {
|
||||||
return window.location.protocol === 'https:' ? raw.replace(/^http:\/\//i, 'https://') : raw
|
var abs = window.location.protocol === 'https:' ? raw.replace(/^http:\/\//i, 'https://') : raw
|
||||||
|
return rewriteLegacyBootLogoUrl(abs)
|
||||||
}
|
}
|
||||||
var path = raw.replace(/^\/+/, '')
|
var path = raw.replace(/^\/+/, '')
|
||||||
return window.location.origin + '/server/' + path
|
return window.location.origin + '/server/' + path
|
||||||
}
|
}
|
||||||
|
|
||||||
function resolveBootLogoUrl(config) {
|
function resolveBootLogoUrl(config) {
|
||||||
|
var nested = config && config.user && typeof config.user === 'object' ? config.user : {}
|
||||||
|
var fromUser = rewriteLegacyBootLogoUrl(pickAvatarRaw(nested.avatar))
|
||||||
|
if (fromUser) return resolveAbsoluteLogoUrl(fromUser)
|
||||||
|
|
||||||
var cached = readCachedLogoUrl()
|
var cached = readCachedLogoUrl()
|
||||||
if (cached && /^(data:|blob:)/i.test(cached)) return cached
|
if (cached && /^(data:|blob:)/i.test(cached)) return cached
|
||||||
if (cached && /^(https?:\/\/)/i.test(cached)) return resolveAbsoluteLogoUrl(cached)
|
return resolveAbsoluteLogoUrl(cached)
|
||||||
|
|
||||||
var nested = config && config.user && typeof config.user === 'object' ? config.user : {}
|
|
||||||
var root = config && typeof config === 'object' ? config : {}
|
|
||||||
var raw = pickAvatarRaw(nested.avatar) || pickAvatarRaw(root.avatar) || cached
|
|
||||||
return resolveAbsoluteLogoUrl(raw)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function persistLogoCache(logoUrl) {
|
function persistLogoCache(logoUrl) {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { AppConfig } from './types'
|
import type { AppConfig } from './types'
|
||||||
|
import { rewriteLegacyUploadUrl } from './rewrite-legacy-upload-url'
|
||||||
|
|
||||||
type RawAppConfig = AppConfig & {
|
type RawAppConfig = AppConfig & {
|
||||||
user?: Record<string, any>
|
user?: Record<string, any>
|
||||||
@@ -32,6 +33,10 @@ function normalizeUserConfig(user?: Record<string, any>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (typeof normalized.avatar === 'string') {
|
||||||
|
normalized.avatar = rewriteLegacyUploadUrl(normalized.avatar)
|
||||||
|
}
|
||||||
|
|
||||||
return normalized
|
return normalized
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,14 +45,17 @@ export function normalizeAppConfig(config: RawAppConfig): RawAppConfig {
|
|||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!config.user || typeof config.user !== 'object') {
|
const next: RawAppConfig = { ...config }
|
||||||
return config
|
|
||||||
|
if (typeof next.avatar === 'string') {
|
||||||
|
next.avatar = rewriteLegacyUploadUrl(next.avatar)
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
if (next.user && typeof next.user === 'object') {
|
||||||
...config,
|
next.user = normalizeUserConfig(next.user)
|
||||||
user: normalizeUserConfig(config.user),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return next
|
||||||
}
|
}
|
||||||
|
|
||||||
let appConfig: RawAppConfig | null = null
|
let appConfig: RawAppConfig | null = null
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { getConfig } from '@/config/app-config'
|
import { getConfig } from '@/config/app-config'
|
||||||
|
import { rewriteLegacyUploadUrl } from '@/config/rewrite-legacy-upload-url'
|
||||||
import { isPwaManifestReady } from '@/modules/pwa/manifest'
|
import { isPwaManifestReady } from '@/modules/pwa/manifest'
|
||||||
|
|
||||||
export function applyAppConfig() {
|
export function applyAppConfig() {
|
||||||
@@ -14,7 +15,7 @@ function setTitle() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getLogoUrl() {
|
function getLogoUrl() {
|
||||||
return getConfig<string>('avatar') || '/favicon.png'
|
return rewriteLegacyUploadUrl(getConfig<string>('avatar') || '/favicon.png')
|
||||||
}
|
}
|
||||||
|
|
||||||
function setFavicon() {
|
function setFavicon() {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import type { AppConfig } from '@/config/types'
|
import type { AppConfig } from '@/config/types'
|
||||||
|
import { rewriteLegacyUploadUrl } from '@/config/rewrite-legacy-upload-url'
|
||||||
import { resetVersionCheckCache } from '@/config/load-version'
|
import { resetVersionCheckCache } from '@/config/load-version'
|
||||||
import { clearCachedPwaManifest } from '@/modules/pwa/manifest-cache'
|
import { clearCachedPwaManifest } from '@/modules/pwa/manifest-cache'
|
||||||
import { tokenName } from '@/themeConfig'
|
import { tokenName } from '@/themeConfig'
|
||||||
@@ -65,13 +66,12 @@ export function readCachedAppConfig(): AppConfig | null {
|
|||||||
function persistBootLogo(config: AppConfig) {
|
function persistBootLogo(config: AppConfig) {
|
||||||
try {
|
try {
|
||||||
const nested = (config as {user?: Record<string, unknown>})?.user
|
const nested = (config as {user?: Record<string, unknown>})?.user
|
||||||
const root = (config || {}) as Record<string, unknown>
|
const avatar = rewriteLegacyUploadUrl(String(nested?.avatar || '').trim())
|
||||||
const avatar = String(nested?.avatar || root.avatar || '').trim()
|
|
||||||
const version = String(localStorage.getItem(VERSION_STORAGE_KEY) || '').trim()
|
const version = String(localStorage.getItem(VERSION_STORAGE_KEY) || '').trim()
|
||||||
const cachedUrl = localStorage.getItem('BOOT_LOGO_URL') || ''
|
const cachedUrl = localStorage.getItem('BOOT_LOGO_URL') || ''
|
||||||
const cachedVer = localStorage.getItem('BOOT_LOGO_VERSION') || ''
|
const cachedVer = localStorage.getItem('BOOT_LOGO_VERSION') || ''
|
||||||
const cacheFresh = !!(cachedUrl && version && cachedVer && version === cachedVer)
|
const cacheFresh = !!(cachedUrl && version && cachedVer && version === cachedVer)
|
||||||
if (!cacheFresh && avatar) localStorage.setItem('BOOT_LOGO_URL', avatar)
|
if (avatar && (!cacheFresh || cachedUrl !== avatar)) localStorage.setItem('BOOT_LOGO_URL', avatar)
|
||||||
if (version) localStorage.setItem('BOOT_LOGO_VERSION', version)
|
if (version) localStorage.setItem('BOOT_LOGO_VERSION', version)
|
||||||
const apply = (window as Window & {__APPLY_BOOT_BRANDING__?: (c: unknown) => void})
|
const apply = (window as Window & {__APPLY_BOOT_BRANDING__?: (c: unknown) => void})
|
||||||
.__APPLY_BOOT_BRANDING__
|
.__APPLY_BOOT_BRANDING__
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
/** هاستهای رجیستری قدیمی که دیگر نباید برای لوگو استفاده شوند */
|
||||||
|
const LEGACY_UPLOAD_HOSTS = new Set([
|
||||||
|
'nerkh.gold',
|
||||||
|
'www.nerkh.gold',
|
||||||
|
'tablo.talasevin.ir',
|
||||||
|
'ah.aygingold.ir',
|
||||||
|
'abshode-service.montgit.ir',
|
||||||
|
])
|
||||||
|
|
||||||
|
function resolveSaBase(): string {
|
||||||
|
try {
|
||||||
|
const last = localStorage.getItem('CONFIG_Success_URL')
|
||||||
|
if (last) {
|
||||||
|
const parsed = new URL(last)
|
||||||
|
const path = parsed.pathname.replace(/\/get_user\/?$/i, '').replace(/\/+$/, '')
|
||||||
|
return path && path !== '/' ? `${parsed.origin}${path}` : parsed.origin
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
/* ignore */
|
||||||
|
}
|
||||||
|
return 'https://adm.montzar.ir'
|
||||||
|
}
|
||||||
|
|
||||||
|
/** https://nerkh.gold/uploads/... → https://adm..../uploads/... */
|
||||||
|
export function rewriteLegacyUploadUrl(raw: unknown): string {
|
||||||
|
const value = String(raw || '').trim()
|
||||||
|
if (!value || !/^https?:\/\//i.test(value)) return value
|
||||||
|
|
||||||
|
try {
|
||||||
|
const parsed = new URL(value)
|
||||||
|
const host = parsed.hostname.toLowerCase()
|
||||||
|
if (!LEGACY_UPLOAD_HOSTS.has(host)) return value
|
||||||
|
if (!/\/uploads\//i.test(parsed.pathname)) return value
|
||||||
|
return `${resolveSaBase()}${parsed.pathname}`
|
||||||
|
} catch {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
-3
@@ -1,10 +1,14 @@
|
|||||||
|
import { rewriteLegacyUploadUrl } from '@/config/rewrite-legacy-upload-url'
|
||||||
|
|
||||||
export function getConfigApp(key: string) {
|
export function getConfigApp(key: string) {
|
||||||
const config = window.__APP_CONFIG__ ? window.__APP_CONFIG__.user : {}
|
const config = window.__APP_CONFIG__ ? window.__APP_CONFIG__.user : {}
|
||||||
|
|
||||||
if (config) {
|
if (!config) return null
|
||||||
return config[key]
|
const value = config[key]
|
||||||
|
if (key === 'avatar') {
|
||||||
|
return rewriteLegacyUploadUrl(value) || value || null
|
||||||
}
|
}
|
||||||
return null
|
return value ?? null
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isBoursecuProject() {
|
export function isBoursecuProject() {
|
||||||
|
|||||||
Reference in New Issue
Block a user