chore: update version and enhance dashboard components

- Add a warning message for Windows users in AntigravityToolCard to run the terminal as Administrator for MITM functionality.
- Refactor model testing logic in ProviderDetailPage to improve state management and user experience.
- Introduce new version notification in Sidebar for available updates.
This commit is contained in:
decolua
2026-02-28 16:33:18 +07:00
parent 2f4b813c5b
commit a84477e815
5 changed files with 104 additions and 30 deletions

View File

@@ -0,0 +1,46 @@
import https from "https";
import pkg from "../../../../package.json" with { type: "json" };
const NPM_PACKAGE_NAME = "9router";
// Fetch latest version from npm registry
function fetchLatestVersion() {
return new Promise((resolve) => {
const req = https.get(
`https://registry.npmjs.org/${NPM_PACKAGE_NAME}/latest`,
{ timeout: 4000 },
(res) => {
let data = "";
res.on("data", (chunk) => (data += chunk));
res.on("end", () => {
try {
resolve(JSON.parse(data).version || null);
} catch {
resolve(null);
}
});
}
);
req.on("error", () => resolve(null));
req.on("timeout", () => { req.destroy(); resolve(null); });
});
}
function compareVersions(a, b) {
const pa = a.split(".").map(Number);
const pb = b.split(".").map(Number);
for (let i = 0; i < 3; i++) {
if (pa[i] > pb[i]) return 1;
if (pa[i] < pb[i]) return -1;
}
return 0;
}
export async function GET() {
const latestVersion = await fetchLatestVersion();
console.log("🚀 ~ GET ~ latestVersion:", latestVersion)
const currentVersion = pkg.version;
const hasUpdate = latestVersion ? compareVersions(latestVersion, currentVersion) > 0 : false;
return Response.json({ currentVersion, latestVersion, hasUpdate });
}