mirror of
https://codeberg.org/nobody/LocalCDN.git
synced 2025-02-16 20:00:57 +01:00
Code style improved
This commit is contained in:
parent
05ea59029f
commit
3ae0eccc3d
@ -104,7 +104,8 @@ requestAnalyzer.getLocalTarget = function (requestDetails, initiator) {
|
|||||||
destinationHost,
|
destinationHost,
|
||||||
destinationPath,
|
destinationPath,
|
||||||
destinationSearchString,
|
destinationSearchString,
|
||||||
initiator);
|
initiator
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -124,7 +125,7 @@ requestAnalyzer._matchBasePath = function (hostMappings, channelPath) {
|
|||||||
|
|
||||||
// eslint-disable-next-line max-len
|
// eslint-disable-next-line max-len
|
||||||
requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channelHost, channelPath, destinationSearchString, initiator) {
|
requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channelHost, channelPath, destinationSearchString, initiator) {
|
||||||
let resourcePath, versionNumber, resourcePattern, filename, shorthandResource;
|
let resourcePath, versionNumber, resourcePattern, shorthandResource;
|
||||||
|
|
||||||
storageManager.type.get(Setting.LOGGING, function (items) {
|
storageManager.type.get(Setting.LOGGING, function (items) {
|
||||||
requestAnalyzer.logging = items.enableLogging;
|
requestAnalyzer.logging = items.enableLogging;
|
||||||
@ -158,48 +159,47 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (let resourceMold of Object.keys(resourceMappings)) {
|
for (let resourceMold of Object.keys(resourceMappings)) {
|
||||||
if (!resourcePattern.startsWith(resourceMold)) {
|
if (resourcePattern.startsWith(resourceMold)) {
|
||||||
continue;
|
let targetPath, versionDelivered, versionRequested, bundle;
|
||||||
}
|
targetPath = resourceMappings[resourceMold].path;
|
||||||
let targetPath, versionDelivered, versionRequested, bundle;
|
targetPath = targetPath.replace(Resource.VERSION_PLACEHOLDER, versionNumber);
|
||||||
targetPath = resourceMappings[resourceMold].path;
|
// Replace the requested version with the latest depending on major version
|
||||||
targetPath = targetPath.replace(Resource.VERSION_PLACEHOLDER, versionNumber);
|
versionDelivered = targets.setLastVersion(targetPath, versionNumber);
|
||||||
// Replace the requested version with the latest depending on major version
|
if (versionDelivered === false) {
|
||||||
versionDelivered = targets.setLastVersion(targetPath, versionNumber);
|
return false;
|
||||||
if (versionDelivered === false) {
|
}
|
||||||
return false;
|
versionDelivered = versionDelivered.toString();
|
||||||
}
|
targetPath = targetPath.replace(versionNumber, versionDelivered);
|
||||||
versionDelivered = versionDelivered.toString();
|
|
||||||
targetPath = targetPath.replace(versionNumber, versionDelivered);
|
|
||||||
|
|
||||||
if (versionNumber === null) {
|
if (versionNumber === null) {
|
||||||
versionDelivered = targetPath.match(Resource.VERSION_EXPRESSION).toString();
|
versionDelivered = targetPath.match(Resource.VERSION_EXPRESSION).toString();
|
||||||
versionRequested = 'latest';
|
versionRequested = 'latest';
|
||||||
} else {
|
} else {
|
||||||
versionRequested = versionNumber[0];
|
versionRequested = versionNumber[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get bundle name
|
// Get bundle name
|
||||||
bundle = targets.determineBundle(targetPath);
|
bundle = targets.determineBundle(targetPath);
|
||||||
if (bundle !== '') {
|
if (bundle !== '') {
|
||||||
targetPath = requestAnalyzer._getPathOfBundle(initiator, channelPath, targetPath, bundle);
|
targetPath = requestAnalyzer._getPathOfBundle(initiator, channelHost, channelPath, targetPath, bundle);
|
||||||
}
|
}
|
||||||
if (targetPath === false) {
|
if (targetPath === false) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requestAnalyzer.logging) {
|
if (requestAnalyzer.logging) {
|
||||||
console.log(`${LogString.PREFIX} ${LogString.REPLACED_RESOURCE} ${targetPath}`);
|
console.log(`${LogString.PREFIX} ${LogString.REPLACED_RESOURCE} ${targetPath}`);
|
||||||
log.append(initiator, channelHost + channelPath, targetPath, false);
|
log.append(initiator, channelHost + channelPath, targetPath, false);
|
||||||
|
}
|
||||||
|
// Prepare and return a local target.
|
||||||
|
return {
|
||||||
|
'source': channelHost,
|
||||||
|
'versionRequested': versionRequested,
|
||||||
|
'versionDelivered': versionDelivered,
|
||||||
|
'path': targetPath,
|
||||||
|
'bundle': bundle
|
||||||
|
};
|
||||||
}
|
}
|
||||||
// Prepare and return a local target.
|
|
||||||
return {
|
|
||||||
'source': channelHost,
|
|
||||||
'versionRequested': versionRequested,
|
|
||||||
'versionDelivered': versionDelivered,
|
|
||||||
'path': targetPath,
|
|
||||||
'bundle': bundle
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requestAnalyzer.logging && !IgnoredHost[channelHost]) {
|
if (requestAnalyzer.logging && !IgnoredHost[channelHost]) {
|
||||||
@ -209,7 +209,7 @@ requestAnalyzer._findLocalTarget = function (resourceMappings, basePath, channel
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
requestAnalyzer._getPathOfBundle = function (initiator, channelPath, targetPath, bundle) {
|
requestAnalyzer._getPathOfBundle = function (initiator, channelHost, channelPath, targetPath, bundle) {
|
||||||
let filename = channelPath.split('/').pop();
|
let filename = channelPath.split('/').pop();
|
||||||
if (bundle === 'MathJax (Bundle)' && filename !== 'MathJax.js') {
|
if (bundle === 'MathJax (Bundle)' && filename !== 'MathJax.js') {
|
||||||
filename = channelPath.replace(Resource.MATHJAX, '');
|
filename = channelPath.replace(Resource.MATHJAX, '');
|
||||||
@ -219,10 +219,9 @@ requestAnalyzer._getPathOfBundle = function (initiator, channelPath, targetPath,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return helpers.formatFilename(
|
return helpers.formatFilename(filename.endsWith('.js')
|
||||||
filename.endsWith('.js')
|
? `${targetPath + filename}m`
|
||||||
? `${targetPath + filename}m`
|
: targetPath + filename);
|
||||||
: targetPath + filename);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
requestAnalyzer._applyAllowlistedDomains = function () {
|
requestAnalyzer._applyAllowlistedDomains = function () {
|
||||||
|
@ -69,8 +69,8 @@ body {
|
|||||||
|
|
||||||
.div-selected-icon {
|
.div-selected-icon {
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
width: 100%;
|
|
||||||
padding-right: 25px;
|
padding-right: 25px;
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.div-selected-icon > label {
|
.div-selected-icon > label {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user