import { getCellLocalApi } from '@jeesite/core/api/sys/cellLocal'; import { setServerCellLocalPath } from './cellLocal'; const normalizeText = (value: unknown) => String(value ?? '').trim(); const isPlainObject = (value: unknown): value is Record => Object.prototype.toString.call(value) === '[object Object]'; const extractCellLocalPath = (payload: any) => { const data = payload?.data ?? payload?.result ?? payload?.obj ?? payload; if (typeof data === 'string') return normalizeText(data); if (!isPlainObject(data)) return ''; const directPath = normalizeText( data?.path ?? data?.cellPath ?? data?.cellLocal ?? data?.cellLocalPath ?? data?.baseStationPath ?? data?.localPath ?? data?.filePath, ); if (directPath) return directPath; const nestedCandidates = [data?.data, data?.result, data?.obj, data?.record, data?.row]; for (const candidate of nestedCandidates) { if (!isPlainObject(candidate)) continue; const nestedPath = normalizeText( candidate.path ?? candidate.cellPath ?? candidate.cellLocal ?? candidate.cellLocalPath ?? candidate.baseStationPath ?? candidate.localPath ?? candidate.filePath, ); if (nestedPath) return nestedPath; } return ''; }; export async function initCellLocalPathFromServer() { try { const res = await getCellLocalApi(); const code = Number((res as any)?.code ?? 0); if (code !== 200) return ''; const path = extractCellLocalPath(res); setServerCellLocalPath(path); return path; } catch { return ''; } }