Skip to content

Commit

Permalink
Posthog multitool (#2301)
Browse files Browse the repository at this point in the history
* Posthog functionality

* Posthog in multitool

* check if anylitics enabled
  • Loading branch information
reecebrowne authored Nov 22, 2024
1 parent 543ad08 commit 547f23f
Showing 1 changed file with 31 additions and 4 deletions.
35 changes: 31 additions & 4 deletions src/main/resources/static/js/multitool/PdfContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,48 @@ class PdfContainer {
async addFilesFromFiles(files, nextSiblingElement) {
this.fileName = files[0].name;
for (var i = 0; i < files.length; i++) {
const startTime = Date.now();
let processingTime, errorMessage = null, pageCount = 0;
try {
const file = files[i];
if (file.type === "application/pdf") {
await this.addPdfFile(file, nextSiblingElement);
const { renderer, pdfDocument } = await this.loadFile(file);
pageCount = renderer.pageCount || 0;
await this.addPdfFile(renderer, pdfDocument, nextSiblingElement);
} else if (file.type.startsWith("image/")) {
await this.addImageFile(file, nextSiblingElement);
}
processingTime = Date.now() - startTime;
this.captureFileProcessingEvent(true, file, processingTime, null, pageCount);
} catch (error) {
processingTime = Date.now() - startTime;
errorMessage = error.message || "Unknown error";
this.captureFileProcessingEvent(false, files[i], processingTime, errorMessage, pageCount);
}
}

document.querySelectorAll(".enable-on-file").forEach((element) => {
element.disabled = false;
});
}

captureFileProcessingEvent(success, file, processingTime, errorMessage, pageCount) {
try{
if(analyticsEnabled){
posthog.capture('file_processing', {
success,
file_type: file?.type || 'unknown',
file_size: file?.size || 0,
processing_time: processingTime,
error_message: errorMessage,
pdf_pages: pageCount,
});
}
}catch{
}
}


async addFilesBlank(nextSiblingElement) {
const pdfContent = `
%PDF-1.4
Expand Down Expand Up @@ -188,9 +217,7 @@ class PdfContainer {

}

async addPdfFile(file, nextSiblingElement) {
const { renderer, pdfDocument } = await this.loadFile(file);

async addPdfFile(renderer, pdfDocument, nextSiblingElement) {
for (var i = 0; i < renderer.pageCount; i++) {
const div = document.createElement("div");

Expand Down

0 comments on commit 547f23f

Please sign in to comment.