Skip to content

Commit 146842a

Browse files
author
Andrei
committed
Valid versions only
1 parent 214d4d8 commit 146842a

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

app/api/versions/route.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@ import { NextRequest } from 'next/server'
22
import { tryCatch } from '@/lib/try-catch'
33
import { Platforms } from '@/lib/utils'
44

5+
interface Versions {
6+
[key: string]: {
7+
download_url: string
8+
}
9+
}
10+
511
const ENDPOINT = 'https://raw.githubusercontent.com/Bugazelle/chromium-all-old-stable-versions/master/chromium.stable.json'
612

713
export async function GET(request: NextRequest) {
@@ -25,8 +31,13 @@ export async function GET(request: NextRequest) {
2531
return new Response('An error occured.', { status: 500 })
2632
}
2733

28-
const versions = data[os]
34+
const versions = data[os] as Versions
2935
if (!versions) return new Response('Unsupported Operating System.', { status: 400 })
36+
37+
const validVersions = Object.fromEntries(
38+
Object.entries(versions)
39+
.filter(([, { download_url }]) => !download_url.toLowerCase().includes('error:'))
40+
)
3041

31-
return Response.json(versions, {status: 200})
42+
return Response.json(validVersions, {status: 200})
3243
}

0 commit comments

Comments
 (0)