1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-10-04 08:37:11 +02:00

Use CDN URLs as fall back URLs

Related feedback:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1566#issuecomment-826473517

Additionally, add more CDN URLs to default filter lists.
This commit is contained in:
Raymond Hill 2021-04-27 08:56:07 -04:00
parent 0f580ec204
commit 2a5e67e3f5
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 42 additions and 9 deletions

View File

@ -22,6 +22,11 @@
"contentURL": [ "contentURL": [
"https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/badlists.txt", "https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/badlists.txt",
"assets/ublock/badlists.txt" "assets/ublock/badlists.txt"
],
"cdnURLs": [
"https://gitcdn.xyz/repo/uBlockOrigin/uAssets/master/filters/badlists.txt",
"https://cdn.jsdelivr.net/gh/uBlockOrigin/uAssets@master/filters/badlists.txt",
"https://cdn.statically.io/gh/uBlockOrigin/uAssets/master/filters/badlists.txt"
] ]
}, },
"ublock-filters": { "ublock-filters": {
@ -47,6 +52,11 @@
"https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/badware.txt", "https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/badware.txt",
"assets/ublock/badware.txt" "assets/ublock/badware.txt"
], ],
"cdnURLs": [
"https://gitcdn.xyz/repo/uBlockOrigin/uAssets/master/filters/badware.txt",
"https://cdn.jsdelivr.net/gh/uBlockOrigin/uAssets@master/filters/badware.txt",
"https://cdn.statically.io/gh/uBlockOrigin/uAssets/master/filters/badware.txt"
],
"supportURL": "https://github.com/gorhill/uBlock/wiki/Badware-risks", "supportURL": "https://github.com/gorhill/uBlock/wiki/Badware-risks",
"instructionURL": "https://github.com/gorhill/uBlock/wiki/Badware-risks" "instructionURL": "https://github.com/gorhill/uBlock/wiki/Badware-risks"
}, },
@ -57,6 +67,11 @@
"contentURL": [ "contentURL": [
"https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/privacy.txt", "https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/privacy.txt",
"assets/ublock/privacy.txt" "assets/ublock/privacy.txt"
],
"cdnURLs": [
"https://gitcdn.xyz/repo/uBlockOrigin/uAssets/master/filters/privacy.txt",
"https://cdn.jsdelivr.net/gh/uBlockOrigin/uAssets@master/filters/privacy.txt",
"https://cdn.statically.io/gh/uBlockOrigin/uAssets/master/filters/privacy.txt"
] ]
}, },
"ublock-abuse": { "ublock-abuse": {
@ -66,6 +81,11 @@
"contentURL": [ "contentURL": [
"https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/resource-abuse.txt", "https://raw.githubusercontent.com/uBlockOrigin/uAssets/master/filters/resource-abuse.txt",
"assets/ublock/resource-abuse.txt" "assets/ublock/resource-abuse.txt"
],
"cdnURLs": [
"https://gitcdn.xyz/repo/uBlockOrigin/uAssets/master/filters/resource-abuse.txt",
"https://cdn.jsdelivr.net/gh/uBlockOrigin/uAssets@master/filters/resource-abuse.txt",
"https://cdn.statically.io/gh/uBlockOrigin/uAssets/master/filters/resource-abuse.txt"
] ]
}, },
"ublock-unbreak": { "ublock-unbreak": {

View File

@ -730,14 +730,20 @@ api.get = async function(assetKey, options = {}) {
const assetRegistry = await getAssetSourceRegistry(); const assetRegistry = await getAssetSourceRegistry();
assetDetails = assetRegistry[assetKey] || {}; assetDetails = assetRegistry[assetKey] || {};
let contentURLs = []; const contentURLs = [];
if ( typeof assetDetails.contentURL === 'string' ) { if ( typeof assetDetails.contentURL === 'string' ) {
contentURLs = [ assetDetails.contentURL ]; contentURLs.push(assetDetails.contentURL);
} else if ( Array.isArray(assetDetails.contentURL) ) { } else if ( Array.isArray(assetDetails.contentURL) ) {
contentURLs = assetDetails.contentURL.slice(0); contentURLs.push(...assetDetails.contentURL);
} else if ( reIsExternalPath.test(assetKey) ) { } else if ( reIsExternalPath.test(assetKey) ) {
assetDetails.content = 'filters'; assetDetails.content = 'filters';
contentURLs = [ assetKey ]; contentURLs.push(assetKey);
}
// https://github.com/uBlockOrigin/uBlock-issues/issues/1566#issuecomment-826473517
// Use CDN URLs as fall back URLs.
if ( Array.isArray(assetDetails.cdnURLs) ) {
contentURLs.push(...assetDetails.cdnURLs);
} }
for ( const contentURL of contentURLs ) { for ( const contentURL of contentURLs ) {
@ -776,24 +782,31 @@ const getRemote = async function(assetKey) {
return details; return details;
}; };
let contentURLs = []; const contentURLs = [];
if ( typeof assetDetails.contentURL === 'string' ) { if ( typeof assetDetails.contentURL === 'string' ) {
contentURLs = [ assetDetails.contentURL ]; contentURLs.push(assetDetails.contentURL);
} else if ( Array.isArray(assetDetails.contentURL) ) { } else if ( Array.isArray(assetDetails.contentURL) ) {
contentURLs = assetDetails.contentURL.slice(0); contentURLs.push(...assetDetails.contentURL);
} }
// If asked to be gentle on remote servers, favour using dedicated CDN // If asked to be gentle on remote servers, favour using dedicated CDN
// servers. If more than one CDN server is present, randomly shuffle the // servers. If more than one CDN server is present, randomly shuffle the
// set of servers so as to spread the bandwidth burden. // set of servers so as to spread the bandwidth burden.
if ( remoteServerFriendly && Array.isArray(assetDetails.cdnURLs) ) { //
// https://github.com/uBlockOrigin/uBlock-issues/issues/1566#issuecomment-826473517
// In case of manual update, use CDNs URLs as fall back URLs.
if ( Array.isArray(assetDetails.cdnURLs) ) {
const cdnURLs = assetDetails.cdnURLs.slice(); const cdnURLs = assetDetails.cdnURLs.slice();
for ( let i = 0, n = cdnURLs.length; i < n; i++ ) { for ( let i = 0, n = cdnURLs.length; i < n; i++ ) {
const j = Math.floor(Math.random() * n); const j = Math.floor(Math.random() * n);
if ( j === i ) { continue; } if ( j === i ) { continue; }
[ cdnURLs[j], cdnURLs[i] ] = [ cdnURLs[i], cdnURLs[j] ]; [ cdnURLs[j], cdnURLs[i] ] = [ cdnURLs[i], cdnURLs[j] ];
} }
contentURLs.unshift(...cdnURLs); if ( remoteServerFriendly ) {
contentURLs.unshift(...cdnURLs);
} else {
contentURLs.push(...cdnURLs);
}
} }
for ( const contentURL of contentURLs ) { for ( const contentURL of contentURLs ) {