Download src/app/api/version/route.js from heyeyydss/api9nin: direct link, hf CLI and curl.
- Browser
- Download file 1.27 kB
-
https://huggingface.co/spaces/heyeyydss/api9nin/resolve/main/src/app/api/version/route.js
- Command line
-
hf download hf://spaces/heyeyydss/api9nin/src/app/api/version/route.js
-
curl -L -o route.js https://huggingface.co/spaces/heyeyydss/api9nin/resolve/main/src/app/api/version/route.js
1.27 kB
| 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(); | |
| const currentVersion = pkg.version; | |
| const hasUpdate = latestVersion ? compareVersions(latestVersion, currentVersion) > 0 : false; | |
| return Response.json({ currentVersion, latestVersion, hasUpdate }); | |
| } | |