import { NextResponse } from "next/server"; import { webFetch } from "yt-dlp-transcript-common/lib/web/fetchPage"; import { ops, optPositiveInt, reqString } from "../_lib"; import { webFailure } from "../_web"; export const dynamic = "force-dynamic"; // POST { url, maxChars? } -> { ok: true, page: { url, finalUrl, status, // contentType, title?, text, truncated } } // // One web page as readable text (release 27 D7), read only, through the // process's web pacer (common/lib/web): http(s) only, never a private or // loopback host (by name, address or what the name resolves to, every // redirect hop checked), text pages only, the text cut at `maxChars` // (default 12,000, at most 60,000). Nothing is written. A generation run's // agent tool `web_fetch` is the same read. export async function POST(request: Request) { return ops(request, ["url", "maxChars"], async (body) => { const url = reqString(body, "url"); const maxChars = optPositiveInt(body, "maxChars"); try { const page = await webFetch(url, maxChars !== undefined ? { maxChars } : {}); return NextResponse.json({ ok: true, page }); } catch (e) { return webFailure(e); } }); }