From 29cf802a9a5dab30261652ecfd992420b3825f20 Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Wed, 28 Jan 2026 14:07:29 +0100 Subject: [PATCH] fix(api): add github-versions endpoint and fix legacy versions route --- frontend/src/app/api/github-versions/route.ts | 36 +++++++++++++++++++ frontend/src/app/api/versions/route.ts | 10 ++++-- 2 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 frontend/src/app/api/github-versions/route.ts diff --git a/frontend/src/app/api/github-versions/route.ts b/frontend/src/app/api/github-versions/route.ts new file mode 100644 index 000000000..b24327607 --- /dev/null +++ b/frontend/src/app/api/github-versions/route.ts @@ -0,0 +1,36 @@ +import { NextResponse } from "next/server"; +import { promises as fs } from "node:fs"; +import path from "node:path"; + +import type { GitHubVersionsResponse } from "@/lib/types"; + +export const dynamic = "force-static"; + +const jsonDir = "public/json"; +const versionsFileName = "github-versions.json"; +const encoding = "utf-8"; + +async function getVersions(): Promise { + const filePath = path.resolve(jsonDir, versionsFileName); + const fileContent = await fs.readFile(filePath, encoding); + const data: GitHubVersionsResponse = JSON.parse(fileContent); + return data; +} + +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({ + generated: "", + versions: [], + error: err.message || "An unexpected error occurred", + }, { + status: 500, + }); + } +} diff --git a/frontend/src/app/api/versions/route.ts b/frontend/src/app/api/versions/route.ts index 1d2807a55..ca9e19758 100644 --- a/frontend/src/app/api/versions/route.ts +++ b/frontend/src/app/api/versions/route.ts @@ -3,18 +3,22 @@ import { NextResponse } from "next/server"; import { promises as fs } from "node:fs"; import path from "node:path"; -import type { AppVersion } from "@/lib/types"; - 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: AppVersion[] = JSON.parse(fileContent); + const versions: LegacyVersion[] = JSON.parse(fileContent); const modifiedVersions = versions.map((version) => { let newName = version.name;