Commit 464e88db authored by Pedro Eduardo Trujillo's avatar Pedro Eduardo Trujillo
Browse files

Actualiza pdfjs y permite más orígenes

Migra hacia pdfjs oficial, pudiendo cambiar opciones antes de compilarlo
para permitir su uso desde más dominios de origen. Además, supone un
salto de versión de pdfjs desde v3 hacia v5.

Actualiza proceso de construcción de dependencia y de copiado de
ficheros para distribuir.
parent 5dbf1d6b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
../../node_modules/pdfjs-dist-viewer-min/build/minified
 No newline at end of file
../../node_modules/pdfjs-dist
 No newline at end of file
+2 −1
Original line number Diff line number Diff line
@@ -101,7 +101,8 @@ define([
				this.lastPDF = url;

				var useBuilt = (/true/i).test(redmicConfig.getEnvVariableValue('envUseBuilt')),
					path = '/' + (useBuilt ? 'dist/js' : 'dep') + '/pdfjs/web/viewer.html?file=' + url;
					pdfViewerPath = '/pdfjs/build/generic/web/viewer.html',
					path = '/' + (useBuilt ? 'dist/js' : 'dep') + pdfViewerPath + '?file=' + url;

				if (!this.roleGuestActive) {
					path += '?access_token%3D' + Credentials.get("accessToken");
+21 −1
Original line number Diff line number Diff line
module.exports = function(grunt) {

	var preBuildCmds = ['npm install'];
	let preBuildCmds = ['npm install'];

	const pdfjsAllowedOrigins = [
		'http://localhost',
		'https://ecomarcan.org',
		'https://en.ecomarcan.org',
		'https://ecomarcan.grafcan.es',
		'https://en.ecomarcan.grafcan.es'
	];

	const pdfjsAllowedOriginsConcat = '"' + pdfjsAllowedOrigins.join('", "') + '",',
		pdfjsAppFilepath = 'web/app.js';

	grunt.config('redmicConfig.buildModules', {
		'client-app/dep/pruneCluster': preBuildCmds.concat([
@@ -9,6 +20,15 @@ module.exports = function(grunt) {
		'client-app/dep/wicket': preBuildCmds.concat([
			'npm run build'
		]),
		'client-app/dep/pdfjs': preBuildCmds.concat([
			'! grep -q \'' + pdfjsAllowedOriginsConcat + '\' ' + pdfjsAppFilepath + ' && ' +
			'sed -Ei \'s/(const HOSTED_VIEWER_ORIGINS = new Set\\(\\[)/\\1\\n    ' +
				pdfjsAllowedOriginsConcat.replaceAll('/', '\\/') + '/g\' ' + pdfjsAppFilepath,
			'npx gulp minified',
			'npx gulp generic',
			'cp build/minified/build/pdf.worker.min.mjs build/generic/build/pdf.worker.mjs',
			'cp build/minified/build/pdf.min.mjs build/generic/build/pdf.mjs'
		]),
		'client-app/dep/templates': preBuildCmds,
		'client-app/style': preBuildCmds
	});
+6 −3
Original line number Diff line number Diff line
@@ -16,7 +16,7 @@ module.exports = function(grunt) {
		srcLeafletPath = path.join(depPath, leafletPath),
		distLeafletPath = path.join(distPath, destDir, leafletPath),

		pdfjsPath = 'pdfjs',
		pdfjsPath = 'pdfjs/build/generic',
		srcPdfjsPath = path.join(depPath, pdfjsPath),
		distPdfjsPath = path.join(distPath, destDir, pdfjsPath),
		pdfjsWebName = 'web',
@@ -42,12 +42,15 @@ module.exports = function(grunt) {
		pdfjs: {
			files: [{
				cwd: path.join(srcPdfjsPath, pdfjsWebName),
				src: ['v*[^.map]', 'pdf.viewer.js', 'images/*', 'locale/es-ES/*', 'locale/en-GB/*'],
				src: [
					'viewer*[^.map]', 'images/*', 'locale/locale.json',
					'locale/es-ES/*', 'locale/en-GB/*', 'locale/en-US/*'
				],
				dest: path.join(distPdfjsPath, pdfjsWebName),
				expand: true
			},{
				cwd: path.join(srcPdfjsPath, pdfjsBuildName),
				src: 'pdf.worker.js',
				src: ['pdf.mjs', 'pdf.worker.mjs'],
				dest: path.join(distPdfjsPath, pdfjsBuildName),
				expand: true
			}]
+8 −6
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@
        "moment": "2.30.1",
        "nib": "1.2.0",
        "packery": "2.1.2",
        "pdfjs-dist-viewer-min": "3.11.174",
        "pdfjs-dist": "https://github.com/mozilla/pdf.js.git#v5.3.31",
        "proj4": "2.15.0",
        "prunecluster": "https://github.com/pedroetb/PruneCluster.git",
        "put-selector": "0.3.6",
@@ -5793,12 +5793,14 @@
        "node": "*"
      }
    },
    "node_modules/pdfjs-dist-viewer-min": {
      "version": "3.11.174",
      "resolved": "https://registry.npmjs.org/pdfjs-dist-viewer-min/-/pdfjs-dist-viewer-min-3.11.174.tgz",
      "integrity": "sha512-kqbAoDchc87zyTe/XLoKyLHh3Aa3KSbiRd0eHyRoJFgUIYSB3uaMZ1Hvqqf4/y6hbV8K5f7slnmLVauVLzF/iw==",
    "node_modules/pdfjs-dist": {
      "name": "pdf.js",
      "resolved": "git+ssh://git@github.com/mozilla/pdf.js.git#250cc7d299e889aa1c01236cbcebd92571550049",
      "dev": true,
      "license": "Apache-2.0"
      "license": "Apache-2.0",
      "engines": {
        "node": ">=20.16.0 || >=22.3.0"
      }
    },
    "node_modules/pend": {
      "version": "1.2.0",
Loading