mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2025-09-12 18:29:45 +00:00
Update Frontedn (#3216)
This commit is contained in:
parent
9f2d44879f
commit
05d4064f03
4 changed files with 91 additions and 4 deletions
46
frontend/src/app/api/versions/route.ts
Normal file
46
frontend/src/app/api/versions/route.ts
Normal file
|
@ -0,0 +1,46 @@
|
|||
import { AppVersion } from "@/lib/types";
|
||||
import { error } from "console";
|
||||
import { promises as fs } from "fs";
|
||||
// import Error from "next/error";
|
||||
import { NextResponse } from "next/server";
|
||||
import path from "path";
|
||||
|
||||
export const dynamic = "force-static";
|
||||
|
||||
const jsonDir = "public/json";
|
||||
const versionsFileName = "versions.json";
|
||||
const encoding = "utf-8";
|
||||
|
||||
const getVersions = async () => {
|
||||
const filePath = path.resolve(jsonDir, versionsFileName);
|
||||
const fileContent = await fs.readFile(filePath, encoding);
|
||||
const versions: AppVersion[] = JSON.parse(fileContent);
|
||||
|
||||
const modifiedVersions = versions.map(version => {
|
||||
const nameParts = version.name.split('/');
|
||||
let newName = nameParts[nameParts.length - 1];
|
||||
newName = newName.toLowerCase().replace(/[^a-z0-9]/g, '');
|
||||
return { ...version, name: newName };
|
||||
});
|
||||
|
||||
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,
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue