fix: SAC version from /health in sidebar and dashboard (0.9.4)

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
PTah
2026-06-10 17:38:54 +10:00
parent 0a414a0904
commit 37bffe0e3f
5 changed files with 72 additions and 5 deletions
+57
View File
@@ -0,0 +1,57 @@
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<SacVersionInfo> | null = null;
async function fetchSacVersion(): Promise<SacVersionInfo> {
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 };
}