import { routedExtract } from "./routed.js";
import { applyPostProcessing } from "../pipeline.js";
import { createLogger } from "../../logger.js";
const log = createLogger("extract");
class V1Extractor {
  name = "v1";
  async extract(html, url, options = {}) {
    if (options.contentType === "application/pdf") {
      const pdf = await handlePdf(html, url, options);
      return applyPostProcessing(pdf, url, html, options);
    }
    const base = await routedExtract({
      html,
      url,
      contentType: options.contentType
    });
    return applyPostProcessing(base, url, html, options);
  }
}
async function handlePdf(_html, url, options) {
  let pdfText = "";
  if (options.pdfBuffer) {
    try {
      const mod = await import("pdf-parse");
      const Ctor = mod.PDFParse;
      const parser = new Ctor({ data: options.pdfBuffer });
      const parsed = await parser.getText({});
      pdfText = parsed.text ?? "";
    } catch (err) {
      log.warn("pdf-parse failed", { url, error: String(err) });
    }
  }
  return {
    title: "",
    markdown: pdfText,
    metadata: {},
    links: [],
    images: [],
    extractor: "turndown"
  };
}
export {
  V1Extractor
};
//# sourceMappingURL=extract-provider.js.map