Merge branch 'feat/pdfunlock' into chore/all-my-stuffs

# Conflicts:
#	components.d.ts
#	package.json
#	pnpm-lock.yaml
#	src/composable/downloadBase64.ts
#	src/tools/index.ts
This commit is contained in:
ShareVB committed 2024-11-03 21:17:57 +01:00
commit 27ef1c6973
5 files changed
+553 -268

No files matched your search

+6
View File
@@ -74,6 +74,10 @@
"@types/arr-diff": "^4.0.3",
"@types/markdown-it": "^13.0.7",
"@types/pdfjs-dist": "^2.10.378",
"@tiptap/core": "2.1.12",
"@tiptap/pm": "2.1.6",
"@tiptap/starter-kit": "2.1.6",
"@tiptap/vue-3": "2.0.3",
"@types/emscripten": "^1.39.10",
"@types/figlet": "^1.5.8",
"@types/markdown-it": "^13.0.7",
@@ -142,6 +146,7 @@
"json-editor-vue": "^0.16.0",
"json-analyzer": "^1.2.2",
"json2csharp": "^1.0.3",
"js-base64": "^3.7.7",
"json5": "^2.2.3",
"jsonpath": "^1.1.1",
"jsonar-mod": "^1.9.0",
@@ -180,6 +185,7 @@
"regex": "^4.3.3",
"shiki": "^1.22.0",
"postal-mime": "^2.2.7",
"qpdf-wasm-esm-embedded": "^1.1.1",
"qrcode": "^1.5.1",
"rtf-stream-parser": "^3.8.0",
"sql-formatter": "^13.0.0",
+444 -268
View File
File diff suppressed because it is too large. Load diff
+4
View File
@@ -151,6 +151,7 @@ import { tool as yamlViewer } from './yaml-viewer';
import { tool as barcodeReader } from './barcode-reader';
import { tool as barcodeGenerator } from './barcode-generator';
import { tool as htmlToMarkdown } from './html-to-markdown';
import { tool as pdfUnlock } from './pdf-unlock';
export const toolsByCategory: ToolCategory[] = [
{
@@ -178,6 +179,9 @@ export const toolsByCategory: ToolCategory[] = [
passwordStrengthAnalyser,
pdfSignatureChecker,
pdfLinearize,
passwordStrengthAnalyser,
pdfSignatureChecker,
pdfUnlock,
],
},
{
+12
View File
@@ -0,0 +1,12 @@
import { LockOff } from '@vicons/tabler';
import { defineTool } from '../tool';
export const tool = defineTool({
name: 'Pdf Decrypt and Unlock',
path: '/pdf-unlock',
description: 'Decrypt a PDF and unlock (remove security permissions)',
keywords: ['pdf', 'unlock', 'decrypt'],
component: () => import('./pdf-unlock.vue'),
icon: LockOff,
createdAt: new Date('2024-01-09'),
});
+87
View File
@@ -0,0 +1,87 @@
<script setup lang="ts">
import { Base64 } from 'js-base64';
import createQPDFModule from 'qpdf-wasm-esm-embedded';
import { useDownloadFileFromBase64Refs } from '@/composable/downloadBase64';
const status = ref<'idle' | 'done' | 'error' | 'processing'>('idle');
const file = ref<File | null>(null);
const base64OutputPDF = ref('');
const fileName = ref('');
const logs = ref<string[]>([]);
const fileExtension = ref('pdf');
const { download } = useDownloadFileFromBase64Refs(
{
source: base64OutputPDF,
filename: fileName,
extension: fileExtension,
});
async function onPDFFileUploaded(uploadedFile: File) {
file.value = uploadedFile;
const fileBuffer = await uploadedFile.arrayBuffer();
fileName.value = `decrypted_${uploadedFile.name}`;
status.value = 'processing';
try {
const outPdfBuffer = await callMainWithInOutPdf(fileBuffer,
[
'--decrypt',
'--warning-exit-0',
'--verbose',
'in.pdf',
'out.pdf',
],
0);
base64OutputPDF.value = `data:application/pdf;base64,${Base64.fromUint8Array(outPdfBuffer)}`;
status.value = 'done';
download();
}
catch (e) {
status.value = 'error';
}
}
async function callMainWithInOutPdf(data: ArrayBuffer, args: string[], expected_exitcode: number) {
logs.value = [];
const mod = await createQPDFModule({
print(text: string) {
logs.value.push(text);
},
printErr(text: string) {
logs.value.push(text);
},
});
mod.FS.writeFile('in.pdf', new Uint8Array(data));
const ret = mod.callMain(args);
if (expected_exitcode !== ret) {
throw new Error('Process run failed');
}
return mod.FS.readFile('out.pdf');
}
</script>
<template>
<div>
<div style="flex: 0 0 100%">
<div mx-auto max-w-600px>
<c-file-upload title="Drag and drop a PDF file here, or click to select a file" accept=".pdf" @file-upload="onPDFFileUploaded" />
</div>
</div>
<div mt-3 flex justify-center>
<c-alert v-if="status === 'error'" type="error">
An error occured processing {{ fileName }}
</c-alert>
<n-spin
v-if="status === 'processing'"
size="small"
/>
</div>
<c-card title="Logs">
<pre>{{ logs.join('\n') }}</pre>
</c-card>
</div>
</template>