refactor(qpdf): move initialization logic to helpers module
Consolidate qpdf initialization code into helpers.ts to avoid duplication Improve error message for password protected PDFs Fortify encryption logic by auto-filling owner password when empty
This commit is contained in:
@@ -1,31 +1,6 @@
|
||||
import { showLoader, hideLoader, showAlert } from '../ui.js';
|
||||
import { downloadFile, readFileAsArrayBuffer } from '../utils/helpers.js';
|
||||
import { downloadFile, initializeQpdf, readFileAsArrayBuffer } from '../utils/helpers.js';
|
||||
import { state } from '../state.js';
|
||||
import createModule from '@neslinesli93/qpdf-wasm';
|
||||
|
||||
let qpdfInstance: any = null;
|
||||
|
||||
async function initializeQpdf() {
|
||||
if (qpdfInstance) {
|
||||
return qpdfInstance;
|
||||
}
|
||||
showLoader('Initializing decryption engine...');
|
||||
try {
|
||||
qpdfInstance = await createModule({
|
||||
locateFile: () => '/qpdf.wasm',
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Failed to initialize qpdf-wasm:', error);
|
||||
showAlert(
|
||||
'Initialization Error',
|
||||
'Could not load the decryption engine. Please refresh the page and try again.'
|
||||
);
|
||||
throw error;
|
||||
} finally {
|
||||
hideLoader();
|
||||
}
|
||||
return qpdfInstance;
|
||||
}
|
||||
|
||||
export async function decrypt() {
|
||||
const file = state.files[0];
|
||||
|
||||
Reference in New Issue
Block a user