Skip to content

Commit

Permalink
fix pdf uploader (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
Shyam-Raghuwanshi authored Apr 18, 2024
1 parent 25b8433 commit 874e60c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
19 changes: 15 additions & 4 deletions JS/edgechains/document-loader/src/lib/pdf-loader/pdfLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,29 @@ import pdf from "pdf-parse/lib/pdf-parse"

export class PdfLoader {
pdfBuffer: Buffer;

constructor(pdfBuffer: Buffer) {
constructor(pdfBuffer) {
this.pdfBuffer = pdfBuffer;
}

async loadPdf() {
try {
const pdfdata = await pdf(this.pdfBuffer)
return pdfdata.text;
// Convert Buffer to ArrayBuffer
const arrayBuffer = this.bufferToArrayBuffer(this.pdfBuffer);

// Parse PDF using pdf-parse library
const pdfData = await pdf(arrayBuffer);
return pdfData.text;
} catch (error) {
console.error("Error loading PDF:", error);
throw error;
}
}

bufferToArrayBuffer(buffer:Buffer) {
// Create a new Uint8Array based on the Buffer
const uint8Array = new Uint8Array(buffer);

// Create ArrayBuffer from Uint8Array
return uint8Array.buffer;
}
}
1 change: 0 additions & 1 deletion JS/edgechains/vector-db/src/lib/supabase/supabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ export class Supabase {
operation.attempt(async (currentAttempt) => {
try {
let res = await client.rpc(functionNameToCall, args);
console.log(res)
if (res.status == 200) {
resolve(res.data);
} else {
Expand Down

0 comments on commit 874e60c

Please sign in to comment.