import { onMounted, ref } from "vue"; import { APP_NAME, APP_VERSION } from "../version"; export interface SacVersionInfo { name: string; version: string; } let cached: SacVersionInfo | null = null; let inflight: Promise | null = null; async function fetchSacVersion(): Promise { if (cached) { return cached; } if (inflight) { return inflight; } inflight = (async () => { const fallback: SacVersionInfo = { name: APP_NAME, version: APP_VERSION }; try { const response = await fetch("/health"); if (!response.ok) { return fallback; } const data = (await response.json()) as { name?: string; version?: string }; const info: SacVersionInfo = { name: (data.name || APP_NAME).trim() || APP_NAME, version: (data.version || APP_VERSION).trim() || APP_VERSION, }; cached = info; return info; } catch { return fallback; } finally { inflight = null; } })(); return inflight; } /** Версия SAC с бэкенда (/health); fallback — frontend/src/version.ts */ export function useSacVersion() { const appName = ref(APP_NAME); const appVersion = ref(APP_VERSION); onMounted(() => { void fetchSacVersion().then((info) => { appName.value = info.name; appVersion.value = info.version; }); }); return { appName, appVersion }; }