fix(acr) : reuse live API
Build and Push Image / build-backend (push) Successful in 1m44s
Build and Push Image / build-frontend (push) Successful in 2m59s
Build and Push Image / push (push) Successful in 1m12s

This commit is contained in:
2026-07-13 20:03:58 +07:00 Unverified
parent 52beaaa418
commit cf722c4737
+17 -28
View File
@@ -1,45 +1,34 @@
import { NextResponse } from "next/server";
import type { YoutubeLiveInfo } from "../live/route";
type APISearchResponse = {
items?: {
id?: {
videoId?: string;
};
}[];
};
const channelId = "UCC80OcUEuutVW37MC190JJg";
export async function GET() {
const apiKey = process.env.YOUTUBE_API_KEY;
if (!apiKey) {
return new NextResponse("YOUTUBE_API_KEY is not configured.", {
status: 500,
});
}
const response = await fetch(
`https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=${channelId}&eventType=live&type=video&maxResults=1&key=${apiKey}`,
{ cache: "no-store" },
);
export async function GET(request: Request) {
const response = await fetch(new URL("/api/live", request.url), {
cache: "no-store",
});
if (!response.ok) {
return new NextResponse("Failed to search for live stream.", {
return new NextResponse("Failed to get live stream.", {
status: 502,
});
}
const data: APISearchResponse = await response.json();
const videoId = data.items?.[0]?.id?.videoId;
const liveInfo: YoutubeLiveInfo = await response.json();
if (!videoId) {
if (liveInfo === "none") {
return new NextResponse("No live stream found for this channel.", {
status: 404,
});
}
const videoId = new URL(liveInfo.url).searchParams.get("v");
if (!videoId) {
return new NextResponse("Live stream video id was not found.", {
status: 502,
});
}
return NextResponse.redirect(
`https://www.youtube.com/live_chat?is_popout=${videoId}`,
`https://studio.youtube.com/live_chat?is_popout=1&v=${videoId}`,
);
}