feat: add /api/apks endpoint
This commit is contained in:
32
app/api/apks/route.ts
Normal file
32
app/api/apks/route.ts
Normal file
@@ -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 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user