"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.loadDocument = loadDocument;
const fs_1 = __importDefault(require("fs"));
const path_1 = __importDefault(require("path"));
const pdfLoader_1 = require("./pdfLoader");
async function loadDocument(filePath) {
const ext = path_1.default.extname(filePath).toLowerCase();
if (!fs_1.default.existsSync(filePath)) {
throw new Error(`File not found: ${filePath}`);
}
switch (ext) {
case ".pdf":
return await (0, pdfLoader_1.extractTextFromPdf)(filePath);
case ".txt":
case ".md":
case ".markdown":
const text = fs_1.default.readFileSync(filePath, "utf-8");
return [{ text, pageNumber: 1 }];
default:
throw new Error(`Unsupported file extension: ${ext}`);
}
}