Compare commits

...
5 Commits
Author SHA1 Message Date
abdullahalam123 98467f4809 Release v1.7.4 2025-11-18 20:31:24 +05:30
abdullahalam123 151060204d feat(attachments,security): migrate attachment processing to web worker and update CORS policy
- Add web worker for PDF attachment processing to improve performance and prevent UI blocking
- Create add-attachments.worker.js with TypeScript definitions for type safety
- Implement worker message handling with success and error responses
- Update nginx.conf to use Cross-Origin-Resource-Policy instead of Cross-Origin-Embedder-Policy for better cross-origin resource sharing
- Refactor add-attachments.ts to use worker-based processing with transferable objects
- Update main.ts to add home logo click handler for navigation
- Improve error handling with worker error event listener
- Add validation checks for PDF file availability before processing attachments
2025-11-18 20:31:13 +05:30
Alam 3019195fe5 Merge pull request #176 from ildoc/feat/centralized_version
Feat/centralized version
2025-11-18 20:10:00 +05:30
ildoc 3673b6e434 updated readme 2025-11-18 12:45:38 +01:00
ildoc ad915b7527 version fetched from package.json 2025-11-18 12:35:12 +01:00
18 changed files with 183 additions and 52 deletions
+1 -1
View File
@@ -180,7 +180,7 @@ The easiest way to self-host is to download the pre-built distribution file from
**Navigate to the extracted Folder:**
```bash
# Navigate to the extracted folder
cd dist-1.6.2 # Replace with your version
cd dist-1.7.3 # Replace with your version
```
**Serve with Python:**
+2 -2
View File
@@ -261,7 +261,7 @@
© 2025 BentoPDF. All rights reserved.
</p>
<p class="text-gray-500 text-xs mt-2">
Version <span id="app-version">1.7.3</span>
Version <span id="app-version"></span>
</p>
</div>
@@ -331,7 +331,7 @@
</footer>
<script type="module" src="src/js/utils/lucide-init.ts"></script>
<script type="module" src="src/version.ts"></script>
<script type="module" src="src/js/mobileMenu.ts"></script>
</body>
</html>
+2 -2
View File
@@ -133,7 +133,7 @@
&copy; 2025 BentoPDF. All rights reserved.
</p>
<p class="text-gray-500 text-xs mt-2">
Version <span id="app-version">1.7.3</span>
Version <span id="app-version"></span>
</p>
</div>
@@ -203,7 +203,7 @@
</footer>
<script type="module" src="src/js/utils/lucide-init.ts"></script>
<script type="module" src="src/version.ts"></script>
<script type="module" src="src/js/mobileMenu.ts"></script>
</body>
</html>
+2 -2
View File
@@ -319,7 +319,7 @@
&copy; 2025 BentoPDF. All rights reserved.
</p>
<p class="text-gray-500 text-xs mt-2">
Version <span id="app-version">1.7.3</span>
Version <span id="app-version"></span>
</p>
</div>
@@ -389,7 +389,7 @@
</footer>
<script type="module" src="src/js/utils/lucide-init.ts"></script>
<script type="module" src="src/version.ts"></script>
<script type="module" src="src/js/mobileMenu.ts"></script>
</body>
</html>
+3 -2
View File
@@ -594,7 +594,7 @@
&copy; 2025 BentoPDF. All rights reserved.
</p>
<p class="text-gray-500 text-xs mt-2">
Version <span id="app-version">1.7.3</span>
Version <span id="app-version"></span>
</p>
</div>
@@ -664,8 +664,9 @@
</footer>
<script type="module" src="src/js/utils/lucide-init.ts"></script>
<script type="module" src="src/version.ts"></script>
<script type="module" src="src/js/main.ts"></script>
<script type="module" src="src/js/mobileMenu.ts"></script>
</body>
</html>
</html>
+1 -1
View File
@@ -35,6 +35,6 @@ http {
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Cross-Origin-Opener-Policy "same-origin" always;
add_header Cross-Origin-Embedder-Policy "require-corp" always;
add_header Cross-Origin-Resource-Policy "cross-origin" always;
}
}
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "bento-pdf",
"version": "1.6.2",
"version": "1.7.3",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "bento-pdf",
"version": "1.6.2",
"version": "1.7.3",
"license": "Apache-2.0",
"dependencies": {
"@fontsource/cedarville-cursive": "^5.2.7",
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "bento-pdf",
"private": true,
"version": "1.7.3",
"version": "1.7.4",
"license": "Apache-2.0",
"type": "module",
"scripts": {
+2 -2
View File
@@ -244,7 +244,7 @@
&copy; 2025 BentoPDF. All rights reserved.
</p>
<p class="text-gray-500 text-xs mt-2">
Version <span id="app-version">1.7.3</span>
Version <span id="app-version"></span>
</p>
</div>
@@ -313,7 +313,7 @@
</div>
</footer>
<script type="module" src="src/js/utils/lucide-init.ts"></script>
<script type="module" src="src/version.ts"></script>
<script type="module" src="src/js/mobileMenu.ts"></script>
</body>
</html>
+20
View File
@@ -0,0 +1,20 @@
declare const coherentpdf: typeof import('../../src/types/coherentpdf.global').coherentpdf;
interface AddAttachmentsMessage {
command: 'add-attachments';
pdfBuffer: ArrayBuffer;
attachmentBuffers: ArrayBuffer[];
attachmentNames: string[];
}
interface AddAttachmentsSuccessResponse {
status: 'success';
modifiedPDF: ArrayBuffer;
}
interface AddAttachmentsErrorResponse {
status: 'error';
message: string;
}
type AddAttachmentsResponse = AddAttachmentsSuccessResponse | AddAttachmentsErrorResponse;
+69
View File
@@ -0,0 +1,69 @@
self.importScripts('/coherentpdf.browser.min.js');
function addAttachmentsToPDFInWorker(pdfBuffer, attachmentBuffers, attachmentNames) {
try {
const uint8Array = new Uint8Array(pdfBuffer);
let pdf;
try {
pdf = coherentpdf.fromMemory(uint8Array, '');
} catch (error) {
self.postMessage({
status: 'error',
message: `Failed to load PDF. Error: ${error.message || error}`
});
return;
}
// Add each attachment to the PDF
for (let i = 0; i < attachmentBuffers.length; i++) {
try {
const attachmentData = new Uint8Array(attachmentBuffers[i]);
const attachmentName = attachmentNames[i];
// Attach file at document level (page 0)
coherentpdf.attachFileFromMemory(attachmentData, attachmentName, pdf);
} catch (error) {
console.warn(`Failed to attach file ${attachmentNames[i]}:`, error);
self.postMessage({
status: 'error',
message: `Failed to attach file ${attachmentNames[i]}: ${error.message || error}`
});
coherentpdf.deletePdf(pdf);
return;
}
}
// Save the modified PDF
const modifiedBytes = coherentpdf.toMemory(pdf, false, false);
coherentpdf.deletePdf(pdf);
const buffer = modifiedBytes.buffer.slice(
modifiedBytes.byteOffset,
modifiedBytes.byteOffset + modifiedBytes.byteLength
);
self.postMessage({
status: 'success',
modifiedPDF: buffer
}, [buffer]);
} catch (error) {
self.postMessage({
status: 'error',
message: error instanceof Error
? error.message
: 'Unknown error occurred while adding attachments.'
});
}
}
self.onmessage = (e) => {
if (e.data.command === 'add-attachments') {
addAttachmentsToPDFInWorker(
e.data.pdfBuffer,
e.data.attachmentBuffers,
e.data.attachmentNames
);
}
};
+58 -23
View File
@@ -1,10 +1,40 @@
import { showLoader, hideLoader, showAlert } from '../ui';
import { readFileAsArrayBuffer, downloadFile } from '../utils/helpers';
import { state } from '../state';
const worker = new Worker('/workers/add-attachments.worker.js');
let attachments: File[] = [];
worker.onmessage = (e) => {
const data = e.data;
if (data.status === 'success' && data.modifiedPDF !== undefined) {
hideLoader();
downloadFile(
new Blob([new Uint8Array(data.modifiedPDF)], { type: 'application/pdf' }),
`attached-${state.files[0].name}`
);
showAlert('Success', `${attachments.length} file(s) attached successfully.`);
clearAttachments();
} else if (data.status === 'error') {
hideLoader();
showAlert('Error', data.message || 'Unknown error occurred.');
clearAttachments();
}
};
worker.onerror = (error) => {
hideLoader();
console.error('Worker error:', error);
showAlert('Error', 'Worker error occurred. Check console for details.');
clearAttachments();
};
export async function addAttachments() {
if (!state.pdfDoc) {
if (!state.files || state.files.length === 0) {
showAlert('Error', 'Main PDF is not loaded.');
return;
}
@@ -15,37 +45,37 @@ export async function addAttachments() {
showLoader('Embedding files into PDF...');
try {
const pdfDoc = state.pdfDoc;
const pdfFile = state.files[0];
const pdfBuffer = (await readFileAsArrayBuffer(pdfFile)) as ArrayBuffer;
const attachmentBuffers: ArrayBuffer[] = [];
const attachmentNames: string[] = [];
for (let i = 0; i < attachments.length; i++) {
const file = attachments[i];
showLoader(`Attaching ${file.name} (${i + 1}/${attachments.length})...`);
const fileBytes = await readFileAsArrayBuffer(file);
await pdfDoc.attach(fileBytes as ArrayBuffer, file.name, {
mimeType: file.type || 'application/octet-stream',
description: `Attached file: ${file.name}`,
creationDate: new Date(),
modificationDate: new Date(file.lastModified),
});
showLoader(`Reading ${file.name} (${i + 1}/${attachments.length})...`);
const fileBuffer = (await readFileAsArrayBuffer(file)) as ArrayBuffer;
attachmentBuffers.push(fileBuffer);
attachmentNames.push(file.name);
}
const pdfBytes = await pdfDoc.save();
downloadFile(
new Blob([pdfBytes], { type: 'application/pdf' }),
`attached-${state.files[0].name}`
);
showLoader('Attaching files to PDF...');
const message = {
command: 'add-attachments',
pdfBuffer: pdfBuffer,
attachmentBuffers: attachmentBuffers,
attachmentNames: attachmentNames
};
const transferables = [pdfBuffer, ...attachmentBuffers];
worker.postMessage(message, transferables);
showAlert(
'Success',
`${attachments.length} file(s) attached successfully.`
);
} catch (error: any) {
console.error('Error attaching files:', error);
showAlert('Error', `Failed to attach files: ${error.message}`);
} finally {
hideLoader();
showAlert('Error', `Failed to attach files: ${error.message}`);
clearAttachments();
}
}
@@ -88,6 +118,11 @@ export function setupAddAttachmentsTool() {
return;
}
if (!state.files || state.files.length === 0) {
console.error('No PDF file loaded for adding attachments.');
return;
}
optionsDiv.classList.remove('hidden');
attachmentInput.addEventListener('change', (e) => {
+6 -4
View File
@@ -5,7 +5,7 @@ import { createIcons, icons } from 'lucide';
import * as pdfjsLib from 'pdfjs-dist';
import '../css/styles.css';
import { formatStars } from './utils/helpers.js';
import '../version.js';
import { APP_VERSION, injectVersion } from '../version.js';
const init = () => {
pdfjsLib.GlobalWorkerOptions.workerSrc = new URL(
@@ -29,9 +29,11 @@ const init = () => {
simpleNav.innerHTML = `
<div class="container mx-auto px-4">
<div class="flex justify-start items-center h-16">
<div class="flex-shrink-0 flex items-center">
<div class="flex-shrink-0 flex items-center cursor-pointer" id="home-logo">
<img src="images/favicon.svg" alt="Bento PDF Logo" class="h-8 w-8">
<span class="text-white font-bold text-xl ml-2">BentoPDF</span>
<span class="text-white font-bold text-xl ml-2">
<a href="index.html">BentoPDF</a>
</span>
</div>
</div>
</div>
@@ -95,7 +97,7 @@ const init = () => {
&copy; 2025 BentoPDF. All rights reserved.
</p>
<p class="text-gray-500 text-xs mt-2">
Version <span id="app-version-simple">1.6.2</span>
Version <span id="app-version-simple">${APP_VERSION}</span>
</p>
</div>
`;
+3 -2
View File
@@ -117,7 +117,7 @@
&copy; 2025 BentoPDF. All rights reserved.
</p>
<p class="text-gray-500 text-xs mt-2">
Version <span id="app-version">1.7.3</span>
Version <span id="app-version"></span>
</p>
</div>
@@ -186,8 +186,9 @@
</div>
</footer>
<script type="module" src="../js/utils/lucide-init.ts"></script>
<script type="module" src="../version.ts"></script>
<script type="module" src="../js/logic/add-stamps.ts"></script>
<script type="module" src="../js/mobileMenu.ts"></script>
</body>
</html>
</html>
+3 -2
View File
@@ -420,7 +420,7 @@
&copy; 2025 BentoPDF. All rights reserved.
</p>
<p class="text-gray-500 text-xs mt-2">
Version <span id="app-version">1.7.3</span>
Version <span id="app-version"></span>
</p>
</div>
@@ -489,8 +489,9 @@
</div>
</footer>
<script type="module" src="../js/utils/lucide-init.ts"></script>
<script type="module" src="../version.ts"></script>
<script type="module" src="../js/logic/bookmark-pdf.ts"></script>
<script type="module" src="../js/mobileMenu.ts"></script>
</body>
</html>
</html>
+3 -2
View File
@@ -116,7 +116,7 @@
&copy; 2025 BentoPDF. All rights reserved.
</p>
<p class="text-gray-500 text-xs mt-2">
Version <span id="app-version">1.7.3</span>
Version <span id="app-version"></span>
</p>
</div>
@@ -186,7 +186,8 @@
</footer>
<script type="module" src="../js/logic/json-to-pdf.ts"></script>
<script type="module" src="../js/utils/lucide-init.ts"></script>
<script type="module" src="../version.ts"></script>
<script type="module" src="../js/mobileMenu.ts"></script>
</body>
</html>
</html>
+3 -2
View File
@@ -110,7 +110,7 @@
&copy; 2025 BentoPDF. All rights reserved.
</p>
<p class="text-gray-500 text-xs mt-2">
Version <span id="app-version">1.7.3</span>
Version <span id="app-version"></span>
</p>
</div>
@@ -180,7 +180,8 @@
</footer>
<script type="module" src="../js/logic/pdf-to-json.ts"></script>
<script type="module" src="../js/utils/lucide-init.ts"></script>
<script type="module" src="../version.ts"></script>
<script type="module" src="../js/mobileMenu.ts"></script>
</body>
</html>
</html>
+2 -2
View File
@@ -234,7 +234,7 @@
&copy; 2025 BentoPDF. All rights reserved.
</p>
<p class="text-gray-500 text-xs mt-2">
Version <span id="app-version">1.7.3</span>
Version <span id="app-version"></span>
</p>
</div>
@@ -303,7 +303,7 @@
</div>
</footer>
<script type="module" src="src/js/utils/lucide-init.ts"></script>
<script type="module" src="src/version.ts"></script>
<script type="module" src="src/js/mobileMenu.ts"></script>
</body>
</html>