| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import { getMapLocalApi } from '@jeesite/core/api/sys/mapLocal';
- import { setServerOfflineMapDir } from './offlineMap';
- const normalizeText = (value: unknown) => String(value ?? '').trim();
- const isPlainObject = (value: unknown): value is Record<string, unknown> =>
- Object.prototype.toString.call(value) === '[object Object]';
- const extractMapPath = (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?.mapPath ?? data?.maplocal ?? data?.mapLocal ?? 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.mapPath ??
- candidate.maplocal ??
- candidate.mapLocal ??
- candidate.localPath ??
- candidate.filePath,
- );
- if (nestedPath) return nestedPath;
- }
- return '';
- };
- export async function initOfflineMapDirFromServer() {
- try {
- const res = await getMapLocalApi();
- const code = Number((res as any)?.code ?? 0);
- if (code !== 200) return '';
- const path = extractMapPath(res);
- setServerOfflineMapDir(path);
- return path;
- } catch {
- return '';
- }
- }
|