Files
ftdl/app/api/apks/route.ts
2026-03-04 01:58:52 +08:00

33 lines
989 B
TypeScript

// 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 }
);
}
}