import { getRepoImage } from "@/actions";
import { isServiceError } from "@/lib/utils";
import { NextRequest } from "next/server";

export async function GET(
    request: NextRequest,
    { params }: { params: { domain: string; repoId: string } }
) {
    const { domain, repoId } = params;
    const repoIdNum = parseInt(repoId);

    if (isNaN(repoIdNum)) {
        return new Response("Invalid repo ID", { status: 400 });
    }

    const result = await getRepoImage(repoIdNum, domain);
    if (isServiceError(result)) {
        return new Response(result.message, { status: result.statusCode });
    }

    return new Response(result, {
        headers: {
            'Content-Type': 'image/png',
            'Cache-Control': 'public, max-age=3600',
        },
    });
} 