@aion0/forge 0.2.13 → 0.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/app/api/version/route.ts +9 -8
- package/package.json +1 -1
package/app/api/version/route.ts
CHANGED
|
@@ -2,18 +2,19 @@ import { NextResponse } from 'next/server';
|
|
|
2
2
|
import { readFileSync } from 'node:fs';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
4
|
|
|
5
|
-
//
|
|
6
|
-
|
|
7
|
-
const CACHE_TTL = 60 * 60 * 1000; // 1 hour
|
|
8
|
-
|
|
9
|
-
function getCurrentVersion(): string {
|
|
5
|
+
// Read version once at module load (= server start), not on every request
|
|
6
|
+
const CURRENT_VERSION = (() => {
|
|
10
7
|
try {
|
|
11
8
|
const pkg = JSON.parse(readFileSync(join(process.cwd(), 'package.json'), 'utf-8'));
|
|
12
|
-
return pkg.version;
|
|
9
|
+
return pkg.version as string;
|
|
13
10
|
} catch {
|
|
14
11
|
return '0.0.0';
|
|
15
12
|
}
|
|
16
|
-
}
|
|
13
|
+
})();
|
|
14
|
+
|
|
15
|
+
// Cache npm version check for 1 hour
|
|
16
|
+
let cachedLatest: { version: string; checkedAt: number } | null = null;
|
|
17
|
+
const CACHE_TTL = 60 * 60 * 1000; // 1 hour
|
|
17
18
|
|
|
18
19
|
async function getLatestVersion(): Promise<string> {
|
|
19
20
|
if (cachedLatest && Date.now() - cachedLatest.checkedAt < CACHE_TTL) {
|
|
@@ -47,7 +48,7 @@ function compareVersions(a: string, b: string): number {
|
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
export async function GET() {
|
|
50
|
-
const current =
|
|
51
|
+
const current = CURRENT_VERSION;
|
|
51
52
|
const latest = await getLatestVersion();
|
|
52
53
|
const hasUpdate = latest && compareVersions(current, latest) < 0;
|
|
53
54
|
|
package/package.json
CHANGED