Add dynamic download redirect routes and update README links

This commit is contained in:
Jamie Pine
2026-03-15 23:22:03 -07:00
parent 3c30c5bec1
commit 82cd4bf2ef
2 changed files with 47 additions and 3 deletions
@@ -0,0 +1,42 @@
import { type NextRequest, NextResponse } from 'next/server';
import { getLatestRelease } from '@/lib/releases';
export const dynamic = 'force-dynamic';
const PLATFORM_MAP: Record<
string,
keyof Awaited<ReturnType<typeof getLatestRelease>>['downloadLinks']
> = {
'mac-arm': 'macArm',
'mac-intel': 'macIntel',
windows: 'windows',
linux: 'linux',
};
export async function GET(
_request: NextRequest,
{ params }: { params: Promise<{ platform: string }> },
) {
const { platform } = await params;
const key = PLATFORM_MAP[platform];
if (!key) {
return NextResponse.json(
{ error: `Unknown platform: ${platform}. Use: ${Object.keys(PLATFORM_MAP).join(', ')}` },
{ status: 404 },
);
}
try {
const release = await getLatestRelease();
const url = release.downloadLinks[key];
if (!url) {
return NextResponse.json({ error: `No download available for ${platform}` }, { status: 404 });
}
return NextResponse.redirect(url);
} catch {
return NextResponse.redirect(`https://github.com/jamiepine/voicebox/releases/latest`);
}
}