Regular expressions added

This commit is contained in:
nobody 2020-08-23 07:30:58 +02:00
parent 15a08b2b5e
commit f2a1eddd85
No known key found for this signature in database
GPG Key ID: 8F6DE3D614FCFD7A
2 changed files with 17 additions and 8 deletions

View File

@ -165,6 +165,15 @@ const IconType = {
}
};
const Regex = {
'GOOGLE_FONTS': /fonts\.googleapis\.com\/(css|icons)(?!.*Material\+Icons).*/,
'GOOGLE_MATERIAL_ICONS': /fonts\.googleapis\.com\/(icon|css)\?family=Material\+Icons/,
'JSDELIVR_COMBINE': /cdn\.jsdelivr\.net.*\/combine.*jquery.*hogan.*algoliasearch.*autocomplete.*/,
'BOOTSTRAP_DATEPICKER_3': /\/bootstrap-datepicker3.*\.css/,
'BOOTSTRAP_DATEPICKER': /\/bootstrap-datepicker.*\.css/,
'FONT_AWESOME': /use\.fontawesome\.com\/fa-code\.css/,
'FONT_AWESOME_WITH_CODE': /use\.fontawesome\.com\/[a-z0-9]{10}\.js/
};
// Supported charsets for TextDecoder()
// https://developer.mozilla.org/en-US/docs/Web/API/TextDecoder/TextDecoder

View File

@ -95,15 +95,15 @@ shorthands.specialFiles = function (channelHost, channelPath, searchString) {
It's not possible to respond to a request with multiple redirections
https://gitlab.com/nobody42/localcdn/-/issues/45
*/
let regexJsDelivr = RegExp(/\/combine.*jquery.*hogan.*algoliasearch.*autocomplete.*/);
if (channelHost.includes('cdn.jsdelivr.net') && regexJsDelivr.test(channelPath)) {
if (Regex.JSDELIVR_COMBINE.test(channelHost + channelPath)) {
return {
'source': channelHost,
'version': 'beta',
'path': 'resources/jsdelivr-combine-jquery-hogan-algoliasearch-autocomplete.jsm',
'bundle': ''
};
} else if (channelHost.includes('cdn.jsdelivr.net') && channelPath.includes('algoliasearch@3(algoliasearchLite.min.js),algoliasearch.helper@2')) {
} else if ((channelHost + channelPath) === 'cdn.jsdelivr.net/g/algoliasearch@3(algoliasearchLite.min.js),algoliasearch.helper@2') {
// https://gitlab.com/nobody42/localcdn/-/issues/55
return {
'source': channelHost,
@ -111,28 +111,28 @@ shorthands.specialFiles = function (channelHost, channelPath, searchString) {
'path': 'resources/algoliasearch3.33.0_algoliasearchLite_algoliasearchHelper.jsm',
'bundle': ''
};
} else if (/fonts\.googleapis\.com\/(icon|css)\?family=Material\+Icons/.test(channelHost + channelPath + searchString)) {
} else if (Regex.GOOGLE_MATERIAL_ICONS.test(channelHost + channelPath + searchString)) {
return {
'source': channelHost,
'version': '3.0.1',
'path': 'resources/google-material-design-icons/google-material-design-icons.css',
'bundle': ''
};
} else if (/\/bootstrap-datepicker3.*\.css/.test(channelPath)) {
} else if (Regex.BOOTSTRAP_DATEPICKER_3.test(channelPath)) {
return {
'source': channelHost,
'version': '1.9.0',
'path': 'resources/bootstrap-datepicker/1.9.0/bootstrap-datepicker3.standalone.min.css',
'bundle': ''
};
} else if (/\/bootstrap-datepicker.*\.css/.test(channelPath)) {
} else if (Regex.BOOTSTRAP_DATEPICKER.test(channelPath)) {
return {
'source': channelHost,
'version': '1.9.0',
'path': 'resources/bootstrap-datepicker/1.9.0/bootstrap-datepicker.standalone.min.css',
'bundle': ''
};
} else if (channelHost + channelPath === 'use.fontawesome.com/fa-code.css') {
} else if (Regex.FONT_AWESOME.test(channelHost + channelPath)) {
return {
'source': channelHost,
'versionRequested': '4.6.3',
@ -140,7 +140,7 @@ shorthands.specialFiles = function (channelHost, channelPath, searchString) {
'path': 'resources/webfont/fa-loader.css',
'bundle': ''
};
} else if (/use\.fontawesome\.com\/[a-z0-9]{10}\.js/.test(channelHost + channelPath)) {
} else if (Regex.FONT_AWESOME_WITH_CODE.test(channelHost + channelPath)) {
return {
'source': channelHost,
'versionRequested': '4.6.3',