Support links to update lists which are differential update-friendly

If the `manual` parameter is assigned a date in the form of
`YYMMDD`, this will tell uBO to update lists from origin sources
when the current time is within the range of the specified date,
otherwise lists will be updated from CDNs. Updating from CDNs
is always strongly recommended since this enables differential
updates.

For the time being, `manual=1` will always cause to update lists
from origin, but this form will be deprecated once next stable
release is widespread. The idea is to not leave behind stale
and obsolete links which would be detrimental to differential
updates should someone click on one of these old links left
behind.
This commit is contained in:
Raymond Hill 2023-12-14 09:50:11 -05:00
parent bd7ce41224
commit 5e3f9695b4
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 20 additions and 3 deletions

View File

@ -2178,7 +2178,7 @@ const onMessage = function(request, sender, callback) {
url: 'dashboard.html#3p-filters.html',
select: true,
});
µb.scheduleAssetUpdater({ now: true, fetchDelay: 100, auto: request.manual !== true });
µb.scheduleAssetUpdater({ now: true, fetchDelay: 100, auto: request.auto });
break;
default:

View File

@ -51,11 +51,28 @@ function updateStockLists(target) {
if ( updateURL.hostname !== 'ublockorigin.github.io') { return; }
if ( updateURL.pathname !== '/uAssets/update-lists.html') { return; }
const listkeys = updateURL.searchParams.get('listkeys') || '';
if ( listkeys === '' ) { return true; }
if ( listkeys === '' ) { return; }
let auto = true;
const manual = updateURL.searchParams.get('manual');
if ( manual === '1' ) {
auto = false;
} else if ( /^\d{6}$/.test(`${manual}`) ) {
const year = parseInt(manual.slice(0,2)) || 0;
const month = parseInt(manual.slice(2,4)) || 0;
const day = parseInt(manual.slice(4,6)) || 0;
if ( year !== 0 && month !== 0 && day !== 0 ) {
const date = new Date();
date.setUTCFullYear(2000 + year, month - 1, day);
date.setUTCHours(0);
const then = date.getTime() / 1000 / 3600;
const now = Date.now() / 1000 / 3600;
auto = then < (now - 48) || then > (now + 48);
}
}
vAPI.messaging.send('scriptlets', {
what: 'updateLists',
listkeys,
manual: updateURL.searchParams.get('manual') && true || false,
auto,
});
return true;
} catch (_) {