Update Frontedn (#3216)

This commit is contained in:
Michel Roegl-Brunner 2025-03-18 13:27:35 +01:00 committed by GitHub
parent 9f2d44879f
commit 05d4064f03
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 91 additions and 4 deletions

View 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,
});
}
}