From 0d1ba31175e59dafb87b66ad058853fe313379a0 Mon Sep 17 00:00:00 2001 From: tech Date: Wed, 4 Mar 2026 01:58:52 +0800 Subject: [PATCH] feat: add /api/apks endpoint --- app/api/apks/route.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 app/api/apks/route.ts diff --git a/app/api/apks/route.ts b/app/api/apks/route.ts new file mode 100644 index 0000000..f004760 --- /dev/null +++ b/app/api/apks/route.ts @@ -0,0 +1,32 @@ +// app/api/apks/route.ts +import { NextResponse } from 'next/server'; +import { getApks, formatDateTime } from '@/lib/fs-utils'; + +export async function GET(request: Request) { + const { searchParams } = new URL(request.url); + const project = searchParams.get('project'); + const version = searchParams.get('version'); + const commitId = searchParams.get('commit') || undefined; + + if (!project || !version) { + return NextResponse.json( + { error: 'Project and version parameters are required' }, + { status: 400 } + ); + } + + try { + const apks = await getApks(project, version, commitId); + const apksWithUrls = apks.map(apk => ({ + ...apk, + modifiedAt: apk.modifiedAt.toISOString(), + downloadUrl: `/api/download?project=${project}&version=${version}&filename=${apk.name}`, + })); + return NextResponse.json(apksWithUrls); + } catch (error) { + return NextResponse.json( + { error: 'Failed to fetch APK files' }, + { status: 500 } + ); + } +}