Skip to content

Commit

Permalink
Fix pdf.js bundling
Browse files Browse the repository at this point in the history
  • Loading branch information
thornbill committed Sep 12, 2024
1 parent 4f6586f commit 0bff493
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .escheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"modules": "false",
"files": "./dist/**/*.js",
"not": [
"./dist/libraries/pdf.worker.js",
"./dist/libraries/pdf.worker.mjs",
"./dist/node_modules.pdfjs-dist.*",
"./dist/libraries/worker-bundle.js",
"./dist/serviceworker.js"
]
Expand Down
71 changes: 71 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
"stylelint-no-browser-hacks": "1.3.0",
"stylelint-order": "6.0.4",
"stylelint-scss": "5.3.2",
"transform-async-modules-webpack-plugin": "1.1.1",
"ts-loader": "9.5.1",
"typescript": "5.5.4",
"vitest": "2.0.5",
Expand Down
7 changes: 2 additions & 5 deletions src/plugins/pdfPlayer/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,10 @@ export class PdfPlayer {
const downloadHref = apiClient.getItemDownloadUrl(item.Id);

this.bindEvents();
GlobalWorkerOptions.workerSrc = appRouter.baseUrl() + '/libraries/pdf.worker.js';
GlobalWorkerOptions.workerSrc = appRouter.baseUrl() + '/libraries/pdf.worker.min.mjs';

const downloadTask = getDocument({
url: downloadHref,
// Disable for PDF.js XSS vulnerability
// https://github.com/mozilla/pdf.js/security/advisories/GHSA-wgrm-67xf-hhpq
isEvalSupported: false
url: downloadHref
});
return downloadTask.promise.then(book => {
if (this.cancellationToken) return;
Expand Down
9 changes: 6 additions & 3 deletions webpack.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const CopyPlugin = require('copy-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { TransformAsyncModulesPlugin } = require('transform-async-modules-webpack-plugin');
const { DefinePlugin, IgnorePlugin } = require('webpack');
const packageJson = require('./package.json');

Expand All @@ -15,7 +16,7 @@ const Assets = [
'@jellyfin/libass-wasm/dist/js/subtitles-octopus-worker.js',
'@jellyfin/libass-wasm/dist/js/subtitles-octopus-worker.wasm',
'@jellyfin/libass-wasm/dist/js/subtitles-octopus-worker-legacy.js',
'pdfjs-dist/build/pdf.worker.js'
'pdfjs-dist/build/pdf.worker.min.mjs'
];

const DEV_MODE = process.env.NODE_ENV !== 'production';
Expand Down Expand Up @@ -109,7 +110,9 @@ const config = {
typescript: {
configFile: path.resolve(__dirname, 'tsconfig.json')
}
})
}),
// Transform any modules using top-level await (pdf.js)
new TransformAsyncModulesPlugin()
],
output: {
filename: pathData => (
Expand Down Expand Up @@ -205,6 +208,7 @@ const config = {
path.resolve(__dirname, 'node_modules/markdown-it'),
path.resolve(__dirname, 'node_modules/material-react-table'),
path.resolve(__dirname, 'node_modules/mdurl'),
path.resolve(__dirname, 'node_modules/pdfjs-dist'),
path.resolve(__dirname, 'node_modules/punycode'),
path.resolve(__dirname, 'node_modules/react-blurhash'),
path.resolve(__dirname, 'node_modules/react-lazy-load-image-component'),
Expand Down Expand Up @@ -268,7 +272,6 @@ const config = {
{
test: /\.js$/,
include: [
path.resolve(__dirname, 'node_modules/pdfjs-dist'),
path.resolve(__dirname, 'node_modules/xmldom')
],
use: [{
Expand Down

0 comments on commit 0bff493

Please sign in to comment.