Elffuss BraidHub

kikocis/osiris public

master · 1.3 KiBRawPermalink
1import { NextResponse } from 'next/server';
2import { safeFetch } from '@/lib/ssrf-guard';
3
4export const dynamic = 'force-dynamic';
5
6/** rtsp.me shows this when the camera owner's quota is exhausted */
7const RTSP_BLOCKED = /temporarily limited|Top up/i;
8
9export async function GET(req: Request) {
10 const url = new URL(req.url).searchParams.get('url');
11
12 if (!url || !/rtsp\.me\/embed/i.test(url)) {
13 return NextResponse.json({ available: false, blocked: false, reason: 'not_rtsp_me' });
14 }
15
16 try {
17 const res = await safeFetch(url, {
18 signal: AbortSignal.timeout(8000),
19 headers: {
20 'User-Agent': 'Mozilla/5.0 (compatible; OSIRIS/1.0; +https://github.com/simplifaisoul/osiris)',
21 Accept: 'text/html,application/xhtml+xml',
22 },
23 });
24
25 if (!res.ok) {
26 return NextResponse.json({ available: false, blocked: true, provider: 'rtsp.me' });
27 }
28
29 const html = await res.text();
30 const blocked = RTSP_BLOCKED.test(html);
31
32 return NextResponse.json({
33 available: !blocked,
34 blocked,
35 provider: 'rtsp.me',
36 }, {
37 headers: {
38 'Cache-Control': 'public, s-maxage=300, stale-while-revalidate=600',
39 },
40 });
41 } catch {
42 return NextResponse.json({ available: null, blocked: null, provider: 'rtsp.me' }, { status: 502 });
43 }
44}