feat(FN-2663): add cached update-check setting, APIs, and banner
- Add global updateCheckEnabled setting to core schema/types and wire dashboard command to cache update checks in the CLI - Implement dashboard server update-check cache module plus REST routes for status and refresh behavior - Add dashboard client hook, legacy API helpers, and UpdateAvailableBanner UI to show cached CLI update notices - Cover update-check server routes, hook behavior, banner rendering, and route registration with focused tests - Document update-check configuration and API behavior in architecture and settings reference docs
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import { readFileSync } from "node:fs";
|
||||
import { dirname, join } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { resolveGlobalDir } from "@fusion/core";
|
||||
import { clearUpdateCheckCache, performUpdateCheck } from "../update-check.js";
|
||||
import type { ApiRouteRegistrar } from "./types.js";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
const CLI_PACKAGE_VERSION = (() => {
|
||||
try {
|
||||
const packageJsonPath = join(__dirname, "..", "..", "..", "cli", "package.json");
|
||||
const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8")) as {
|
||||
version?: unknown;
|
||||
};
|
||||
|
||||
if (typeof packageJson.version === "string" && packageJson.version.length > 0) {
|
||||
return packageJson.version;
|
||||
}
|
||||
} catch {
|
||||
// Fall through to env/default fallback.
|
||||
}
|
||||
|
||||
return process.env.npm_package_version ?? "0.0.0";
|
||||
})();
|
||||
|
||||
export const registerUpdateCheckRoutes: ApiRouteRegistrar = (ctx) => {
|
||||
const { router, store, rethrowAsApiError } = ctx;
|
||||
|
||||
router.get("/update-check", async (_req, res) => {
|
||||
try {
|
||||
const globalSettings = await store.getGlobalSettingsStore().getSettings();
|
||||
if (globalSettings.updateCheckEnabled === false) {
|
||||
res.json({
|
||||
updateAvailable: false,
|
||||
disabled: true,
|
||||
currentVersion: CLI_PACKAGE_VERSION,
|
||||
latestVersion: null,
|
||||
lastChecked: Date.now(),
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const result = await performUpdateCheck(resolveGlobalDir(), CLI_PACKAGE_VERSION);
|
||||
res.json(result);
|
||||
} catch (error) {
|
||||
rethrowAsApiError(error, "Failed to perform update check");
|
||||
}
|
||||
});
|
||||
|
||||
router.post("/update-check/refresh", async (_req, res) => {
|
||||
try {
|
||||
const fusionDir = resolveGlobalDir();
|
||||
await clearUpdateCheckCache(fusionDir);
|
||||
const result = await performUpdateCheck(fusionDir, CLI_PACKAGE_VERSION);
|
||||
res.json(result);
|
||||
} catch (error) {
|
||||
rethrowAsApiError(error, "Failed to refresh update check");
|
||||
}
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user