mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2024-11-23 15:21:25 +01:00
Posthog multitool (#2301)
* Posthog functionality * Posthog in multitool * check if anylitics enabled
This commit is contained in:
parent
543ad083a2
commit
547f23fe78
@ -122,12 +122,24 @@ class PdfContainer {
|
|||||||
async addFilesFromFiles(files, nextSiblingElement) {
|
async addFilesFromFiles(files, nextSiblingElement) {
|
||||||
this.fileName = files[0].name;
|
this.fileName = files[0].name;
|
||||||
for (var i = 0; i < files.length; i++) {
|
for (var i = 0; i < files.length; i++) {
|
||||||
|
const startTime = Date.now();
|
||||||
|
let processingTime, errorMessage = null, pageCount = 0;
|
||||||
|
try {
|
||||||
const file = files[i];
|
const file = files[i];
|
||||||
if (file.type === "application/pdf") {
|
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/")) {
|
} else if (file.type.startsWith("image/")) {
|
||||||
await this.addImageFile(file, nextSiblingElement);
|
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) => {
|
document.querySelectorAll(".enable-on-file").forEach((element) => {
|
||||||
@ -135,6 +147,23 @@ class PdfContainer {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
async addFilesBlank(nextSiblingElement) {
|
||||||
const pdfContent = `
|
const pdfContent = `
|
||||||
%PDF-1.4
|
%PDF-1.4
|
||||||
@ -188,9 +217,7 @@ class PdfContainer {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async addPdfFile(file, nextSiblingElement) {
|
async addPdfFile(renderer, pdfDocument, nextSiblingElement) {
|
||||||
const { renderer, pdfDocument } = await this.loadFile(file);
|
|
||||||
|
|
||||||
for (var i = 0; i < renderer.pageCount; i++) {
|
for (var i = 0; i < renderer.pageCount; i++) {
|
||||||
const div = document.createElement("div");
|
const div = document.createElement("div");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user