Skip to content

Sync-in · Sovereign platform for file storage, sharing, synchronization, and collaboration.

build(frontend): use `zip.js` for PDF.js extraction

johavenac1eb0652d52
diff --git a/frontend/package.json b/frontend/package.json
index 02d0ef6c..23115f8f 100644
--- a/frontend/package.json
+++ b/frontend/package.json
@@ -65,12 +65,12 @@
"@angular/cli": "^21.2.14",
"@angular/compiler-cli": "^21.2.16",
"@types/codemirror": "^5.60.17",
+ "@zip.js/zip.js": "^2.8.26",
"angular-eslint": "^21.4.0",
"bootstrap": "^5.3.8",
"eslint": "^9.39.4",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-prettier": "^5.5.6",
- "extract-zip": "^2.0.1",
"typescript": "^5.9.2",
"typescript-eslint": "^8.60.1"
}
diff --git a/frontend/scripts/pdfjs.mjs b/frontend/scripts/pdfjs.mjs
index 04e0f947..3a1c6a29 100644
--- a/frontend/scripts/pdfjs.mjs
+++ b/frontend/scripts/pdfjs.mjs
@@ -4,7 +4,7 @@ import path from 'node:path'
import constants from 'node:constants'
import os from 'node:os'
import { Readable } from 'node:stream'
-import extract from 'extract-zip'
+import { Uint8ArrayReader, Uint8ArrayWriter, ZipReader } from '@zip.js/zip.js/index-native.js'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
@@ -26,6 +26,30 @@ async function checkPaths(paths) {
}
}
+async function extractZip(zipPath, destination) {
+ const zipData = await fs.readFile(zipPath)
+ const zipReader = new ZipReader(new Uint8ArrayReader(zipData))
+ const destinationPath = path.resolve(destination)
+
+ try {
+ const entries = await zipReader.getEntries()
+ for (const entry of entries) {
+ const entryPath = path.resolve(destinationPath, entry.filename)
+ if (entryPath !== destinationPath && !entryPath.startsWith(`${destinationPath}${path.sep}`)) {
+ throw new Error(`Invalid ZIP entry path: ${entry.filename}`)
+ }
+ if (entry.directory) {
+ await fs.mkdir(entryPath, { recursive: true })
+ continue
+ }
+ await fs.mkdir(path.dirname(entryPath), { recursive: true })
+ await fs.writeFile(entryPath, await entry.getData(new Uint8ArrayWriter()))
+ }
+ } finally {
+ await zipReader.close()
+ }
+}
+
async function updatePdfjs() {
console.log('pdfjs - update to the latest version:', latestDownloadURL)
const tmpZip = path.join(os.tmpdir(), 'pdfjs-latest.zip')
@@ -33,8 +57,8 @@ async function updatePdfjs() {
await fs.writeFile(tmpZip, Readable.fromWeb(response.body))
console.log('pdfjs - downloaded:', tmpZip)
await fs.rm(pdfjsAssetsDirectory, { recursive: true, force: true })
- await extract(tmpZip, { dir: pdfjsAssetsDirectory })
- console.log('pdfjs - unzipped:', pdfjsAssetsDirectory)
+ await extractZip(tmpZip, pdfjsAssetsDirectory)
+ console.log('pdfjs - extracted:', pdfjsAssetsDirectory)
const viewerHtml = path.join(pdfjsAssetsDirectory, 'web', 'viewer.html')
if (!(await checkPaths([viewerHtml]))) {
console.warn(`${viewerHtml} is missing`)
diff --git a/package-lock.json b/package-lock.json
index b9af3010..c7931d3c 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -188,12 +188,12 @@
"@angular/cli": "^21.2.14",
"@angular/compiler-cli": "^21.2.16",
"@types/codemirror": "^5.60.17",
+ "@zip.js/zip.js": "^2.8.26",
"angular-eslint": "^21.4.0",
"bootstrap": "^5.3.8",
"eslint": "^9.39.4",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-prettier": "^5.5.6",
- "extract-zip": "^2.0.1",
"typescript": "^5.9.2",
"typescript-eslint": "^8.60.1"
}
@@ -2301,9 +2301,9 @@
}
},
"node_modules/@codemirror/lint": {
- "version": "6.9.6",
- "resolved": "https://registry.npmjs.org/@codemirror/lint/-/lint-6.9.6.tgz",
- "integrity": "sha512-6Kp7r6XfCi/D/5sdXieMfg9pJU1bUEx96WITuLU6ESaKizCz0QHFMjY/TaFSbigDdEAIgi93itLBIUETP4oK+A==",
+ "version": "6.9.7",
+ "resolved": "https://registry.npmjs.org/@codemirror/lint/-/lint-6.9.7.tgz",
+ "integrity": "sha512-28/+iWLYxKxsvGYhSYL7zaCZqLz5+FFFDq9tVsvGv9kv8RY4fFAchJ5WX9M3YrrRlTIsECjsXPqeNgnSmNP2dg==",
"license": "MIT",
"dependencies": {
"@codemirror/state": "^6.0.0",
@@ -2312,9 +2312,9 @@
}
},
"node_modules/@codemirror/merge": {
- "version": "6.12.1",
- "resolved": "https://registry.npmjs.org/@codemirror/merge/-/merge-6.12.1.tgz",
- "integrity": "sha512-GA8hBq2T+IFM0sb5fk8CunTrqOulA3zurJmHtzcU15EMnL8aYpVINfJ5bkfd53M4ikwoew4Y1ydtSaAlk6+B1w==",
+ "version": "6.12.2",
+ "resolved": "https://registry.npmjs.org/@codemirror/merge/-/merge-6.12.2.tgz",
+ "integrity": "sha512-V8JvyAPjHbPupqP7BeMcsdsYCbyPij74jxIbaIJDORI+VZzW44zFmon8bF+oxGWvOKhcRmkiUMXd8MxHr3YA2w==",
"license": "MIT",
"dependencies": {
"@codemirror/language": "^6.0.0",
@@ -2357,9 +2357,9 @@
}
},
"node_modules/@codemirror/view": {
- "version": "6.43.0",
- "resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.43.0.tgz",
- "integrity": "sha512-V7ZCLQO3Jus9hzh2jVCCPW3mO4IBMr43O37PqSUYautJSnnJF41YlgLw21x0fLJTYvJ+Vkm6Gp+qKGH9pltgXA==",
+ "version": "6.43.1",
+ "resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.43.1.tgz",
+ "integrity": "sha512-+BIjw/AG3tDQ4pJgTLPYdAW25eDE66YsvM4LKyVPgGzVgZ4a9Wj1SRX8kPVKgBDdPt8oHtZ15F0qx7p0oOHdHw==",
"license": "MIT",
"dependencies": {
"@codemirror/state": "^6.6.0",
@@ -10259,17 +10259,6 @@
"@types/node": "*"
}
},
- "node_modules/@types/yauzl": {
- "version": "2.10.3",
- "resolved": "https://registry.npmjs.org/@types/yauzl/-/yauzl-2.10.3.tgz",
- "integrity": "sha512-oJoftv0LSuaDZE3Le4DbKX+KS9G36NzOeSap90UIK0yMA/NhKJhqlSGtNDORNRaIbQfzjXDrQa0ytJ6mNRGz/Q==",
- "dev": true,
- "license": "MIT",
- "optional": true,
- "dependencies": {
- "@types/node": "*"
- }
- },
"node_modules/@typescript-eslint/eslint-plugin": {
"version": "8.61.0",
"resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-8.61.0.tgz",
@@ -11428,6 +11417,18 @@
"dev": true,
"license": "MIT"
},
+ "node_modules/anynum": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/anynum/-/anynum-1.0.0.tgz",
+ "integrity": "sha512-xjR9/zBVnUOP6ztMIIgShjsxui80nQUQH+5xJnvrYLs+90bF25/KJqaAi8mk+B4RDtX1Nspi6fmp4YTEts8SfA==",
+ "funding": [
+ {
+ "type": "github",
+ "url": "https://github.com/sponsors/NaturalIntelligence"
+ }
+ ],
+ "license": "MIT"
+ },
"node_modules/app-module-path": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/app-module-path/-/app-module-path-2.2.0.tgz",
@@ -12051,16 +12052,6 @@
"ieee754": "^1.1.13"
}
},
- "node_modules/buffer-crc32": {
- "version": "0.2.13",
- "resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz",
- "integrity": "sha512-VO9Ht/+p3SN7SKWqcrgEzjGbRSJYTx+Q1pTQC0wrWqHx0vpJraQ6GtHx8tvcg1rlK1byhU5gccxgOgj7B0TDkQ==",
- "dev": true,
- "license": "MIT",
- "engines": {
- "node": "*"
- }
- },
"node_modules/buffer-equal-constant-time": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz",
@@ -14357,9 +14348,9 @@
"license": "MIT"
},
"node_modules/electron-to-chromium": {
- "version": "1.5.369",
- "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.369.tgz",
- "integrity": "sha512-XM22K9FNaaCOvMMrBn1caIc8v0g6+pKt660ZbfQqUZvfil0hEzr8ZoiY7VcSLGM3L/x3rz5PqZrk+bKOOmVM9w==",
+ "version": "1.5.370",
+ "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.370.tgz",
+ "integrity": "sha512-D5tSHJReAb/Kf3Hu9F/GO4lJuSWzEWHwvQ/kKSUP7pimNgvxkSKj+gUQhHpKKACwrin7rS3byU7IxreF56rl5g==",
"dev": true,
"license": "ISC"
},
@@ -15318,54 +15309,6 @@
"node": ">=4"
}
},
- "node_modules/extract-zip": {
- "version": "2.0.1",
- "resolved": "https://registry.npmjs.org/extract-zip/-/extract-zip-2.0.1.tgz",
- "integrity": "sha512-GDhU9ntwuKyGXdZBUgTIe+vXnWj0fppUEtMDL0+idd5Sta8TGpHssn/eusA9mrPr9qNDym6SxAYZjNvCn/9RBg==",
- "dev": true,
- "license": "BSD-2-Clause",
- "dependencies": {
- "debug": "^4.1.1",
- "get-stream": "^5.1.0",
- "yauzl": "^2.10.0"
- },
- "bin": {
- "extract-zip": "cli.js"
- },
- "engines": {
- "node": ">= 10.17.0"
- },
- "optionalDependencies": {
- "@types/yauzl": "^2.9.1"
- }
- },
- "node_modules/extract-zip/node_modules/get-stream": {
- "version": "5.2.0",
- "resolved": "https://registry.npmjs.org/get-stream/-/get-stream-5.2.0.tgz",
- "integrity": "sha512-nBF+F1rAZVCu/p7rjzgA+Yb4lfYXrpl7a6VmJrU8wF9I1CKvP/QwPNZHnOlwbTkY6dvtFIzFMSyQXbLoTQPRpA==",
- "dev": true,
- "license": "MIT",
- "dependencies": {
- "pump": "^3.0.0"
- },
- "engines": {
- "node": ">=8"
- },
- "funding": {
- "url": "https://github.com/sponsors/sindresorhus"
- }
- },
- "node_modules/extract-zip/node_modules/yauzl": {
- "version": "2.10.0",
- "resolved": "https://registry.npmjs.org/yauzl/-/yauzl-2.10.0.tgz",
- "integrity": "sha512-p4a9I6X6nu6IhoGmBqAcbJy1mlC4j27vEPZX9F4L4/vZT3Lyq1VkFHw/V/PUcB9Buo+DG3iHkT0x3Qya58zc3g==",
- "dev": true,
- "license": "MIT",
- "dependencies": {
- "buffer-crc32": "~0.2.3",
- "fd-slicer": "~1.1.0"
- }
- },
"node_modules/fast-copy": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/fast-copy/-/fast-copy-4.0.3.tgz",
@@ -15563,16 +15506,6 @@
"reusify": "^1.0.4"
}
},
- "node_modules/fd-slicer": {
- "version": "1.1.0",
- "resolved": "https://registry.npmjs.org/fd-slicer/-/fd-slicer-1.1.0.tgz",
- "integrity": "sha512-cE1qsB/VwyQozZ+q1dGxR8LBYNZeofhEdUNGSMbQD3Gw2lAzX9Zb3uIU6Ebc/Fmyjo9AWWfnn0AUCHqtevs/8g==",
- "dev": true,
- "license": "MIT",
- "dependencies": {
- "pend": "~1.2.0"
- }
- },
"node_modules/fdir": {
"version": "6.5.0",
"resolved": "https://registry.npmjs.org/fdir/-/fdir-6.5.0.tgz",
@@ -20886,9 +20819,9 @@
}
},
"node_modules/prettier": {
- "version": "3.8.3",
- "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.8.3.tgz",
- "integrity": "sha512-7igPTM53cGHMW8xWuVTydi2KO233VFiTNyF5hLJqpilHfmn8C8gPf+PS7dUT64YcXFbiMGZxS9pCSxL/Dxm/Jw==",
+ "version": "3.8.4",
+ "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.8.4.tgz",
+ "integrity": "sha512-N2MylSdi48+5N/6S5j+maeHbUSIzzZ5uOcX5Hm4QpV8Dkb1HFjfAKTKX6yNPJQD9AhcT3ifHNB66tWTTJDi11Q==",
"dev": true,
"license": "MIT",
"bin": {
@@ -22848,16 +22781,19 @@
}
},
"node_modules/strnum": {
- "version": "2.3.0",
- "resolved": "https://registry.npmjs.org/strnum/-/strnum-2.3.0.tgz",
- "integrity": "sha512-ums3KNd42PGyx5xaoVTO1mjU1bH3NpY4vsrVlnv9PNGqQj8wd7rJ6nEypLrJ7z5vxK5RP0yMLo6J/Gsm62DI5Q==",
+ "version": "2.4.0",
+ "resolved": "https://registry.npmjs.org/strnum/-/strnum-2.4.0.tgz",
+ "integrity": "sha512-sHrVyWWdq28RbhjuJdZsA1SnGRJV6NiXbk6AXBxDOsgAcA+lmpUZCYjOdLBxkXMwis6RRe7dlZt4VlIWFVzkmg==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/NaturalIntelligence"
}
],
- "license": "MIT"
+ "license": "MIT",
+ "dependencies": {
+ "anynum": "^1.0.0"
+ }
},
"node_modules/strtok3": {
"version": "10.3.5",