Bundle handling refactored

This commit is contained in:
nobody 2022-07-30 06:06:12 +02:00
parent b4ba5b9f4e
commit f1cc7736d7
No known key found for this signature in database
GPG Key ID: 8F6DE3D614FCFD7A
1 changed files with 45 additions and 28 deletions

View File

@ -232,7 +232,27 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel
requestAnalyzer._getPathOfBundle = function (initiator, channelHost, channelPath, targetPath, bundle) {
let filename = channelPath.split('/').pop();
if (bundle === 'MathJax (Bundle)' && filename !== 'MathJax.js') {
filename = requestAnalyzer._handleMathJax(filename, channelPath, channelHost, initiator);
} else if (bundle === 'TinyMCE (Bundle)' && filename !== 'tinymce.min.js') {
filename = requestAnalyzer._handleTinyMCE(filename, channelPath, channelHost, initiator);
} else if (bundle === 'DataTables (Bundle)') {
filename = requestAnalyzer._handleDataTables(filename);
}
if (filename === false) {
return {
'result': false,
};
}
return helpers.formatFilename(filename.endsWith('.js')
? `${targetPath + filename}m`
: targetPath + filename);
};
requestAnalyzer._handleMathJax = function (filename, channelPath, channelHost, initiator) {
filename = channelPath.replace(Resource.MATHJAX, '');
if (filename.startsWith('/npm/mathjax@3')) {
filename = filename.replace('/npm/mathjax@3/', '');
@ -243,29 +263,26 @@ requestAnalyzer._getPathOfBundle = function (initiator, channelHost, channelPath
if (!MathJaxFiles[filename] && !MathJax3Files[filename]) {
console.warn(`${LogString.PREFIX} ${LogString.MISSING_RESOURCE} ${channelHost + channelPath}`);
log.append(initiator, channelHost + channelPath, '-', true);
return {
'result': false,
return false;
}
return filename;
};
requestAnalyzer._handleDataTables = function (filename) {
if (!filename.endsWith('.min.js') && filename.endsWith('.js')) {
return filename.replace('.js', '.min.js');
}
}
if (bundle === 'TinyMCE (Bundle)' && filename !== 'tinymce.min.js') {
return filename;
};
requestAnalyzer._handleTinyMCE = function (filename, channelPath, channelHost, initiator) {
filename = channelPath.replace(Resource.TINYMCE, '');
if (filename.startsWith('plugins/')) {
console.warn(`${LogString.PREFIX} ${LogString.MISSING_RESOURCE} ${channelHost + channelPath}`);
log.append(initiator, channelHost + channelPath, '-', true);
return {
'result': false,
};
return false;
}
}
if (bundle === 'DataTables (Bundle)') {
if (!filename.endsWith('.min.js') && filename.endsWith('.js')) {
filename = filename.replace('.js', '.min.js');
}
}
return helpers.formatFilename(filename.endsWith('.js')
? `${targetPath + filename}m`
: targetPath + filename);
return filename;
};
requestAnalyzer._applyAllowlistedDomains = function () {