Files
ProxmoxVE/frontend/src/app/api/versions/route.ts
CanbiZ (MickLesk) c7669c39c3 Frontend: use github-versions.json for version display (#11281)
* fix(frontend): use github-versions.json for version display

- Update AppVersion type to match new format with slug field
- Switch from versions.json to github-versions.json API
- Simplify version matching by direct slug comparison
- Remove 'Loading versions...' text - show nothing if no version found

* feat(frontend): show tooltip for pinned versions

* fix(api): add github-versions endpoint and fix legacy versions route
2026-01-28 14:29:26 +01:00

49 lines
1.2 KiB
TypeScript

// import Error from "next/error";
import { NextResponse } from "next/server";
import { promises as fs } from "node:fs";
import path from "node:path";
export const dynamic = "force-static";
const jsonDir = "public/json";
const versionsFileName = "versions.json";
const encoding = "utf-8";
interface LegacyVersion {
name: string;
version: string;
date: string;
}
async function getVersions() {
const filePath = path.resolve(jsonDir, versionsFileName);
const fileContent = await fs.readFile(filePath, encoding);
const versions: LegacyVersion[] = JSON.parse(fileContent);
const modifiedVersions = versions.map((version) => {
let newName = version.name;
newName = newName.toLowerCase().replace(/[^a-z0-9/]/g, "");
return { ...version, name: newName, date: new Date(version.date) };
});
return modifiedVersions;
}
export async function GET() {
try {
const versions = await getVersions();
return NextResponse.json(versions);
}
catch (error) {
console.error(error);
const err = error as globalThis.Error;
return NextResponse.json({
name: err.name,
message: err.message || "An unexpected error occurred",
version: "No version found - Error",
}, {
status: 500,
});
}
}