pdf upload checkpoint1

This commit is contained in:
2025-06-13 22:59:53 +05:30
parent dd814b902d
commit 56ef5ab65d
9 changed files with 226 additions and 16 deletions

View File

@@ -6,7 +6,6 @@ import { ClaimUncheckedCreateInputObjectSchema } from "@repo/db/usedSchemas";
import multer from "multer";
import { forwardToSeleniumAgent, forwardToSeleniumAgent2 } from "../services/seleniumClient";
import path from "path";
import fs from "fs";
import axios from "axios";
const router = Router();
@@ -96,6 +95,14 @@ router.post(
}
try{
const { patientId, claimId } = req.body; // ✅ Extract patientId from the body
if (!patientId || !claimId) {
return res.status(400).json({ error: "Missing patientId or claimId" });
}
const parsedPatientId = parseInt(patientId);
const parsedClaimId = parseInt(claimId);
const result = await forwardToSeleniumAgent2();
if (result.status !== "success") {
@@ -104,17 +111,14 @@ router.post(
const pdfUrl = result.pdf_url;
const filename = path.basename(new URL(pdfUrl).pathname);
const tempDir = path.join(__dirname, "..", "..", "temp");
if (!fs.existsSync(tempDir)) {
fs.mkdirSync(tempDir, { recursive: true });
}
const filePath = path.join(tempDir, filename);
// Download the PDF directly using axios
const pdfResponse = await axios.get(pdfUrl, { responseType: "arraybuffer" });
fs.writeFileSync(filePath, pdfResponse.data);
await storage.createClaimPdf(
parsedPatientId,
parsedClaimId,
filename,
pdfResponse.data
);
return res.json({
success: true,