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:
46
src/app/api/version/route.js
Normal file
46
src/app/api/version/route.js
Normal 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 });
|
||||
}
|
||||
Reference in New Issue
Block a user