1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-07-08 04:49:12 +02:00

Add support for removal of cloud storage entries

This commit is contained in:
Raymond Hill 2020-08-21 09:18:33 -04:00
parent db79672355
commit f6d1c6402f
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 27 additions and 6 deletions

View File

@ -1559,7 +1559,7 @@ vAPI.cloud = (( ) => {
return chunkCount;
};
const deleteChunks = function(datakey, start) {
const deleteChunks = async function(datakey, start) {
const keys = [];
// No point in deleting more than:
@ -1579,6 +1579,12 @@ vAPI.cloud = (( ) => {
const push = async function(details) {
const { datakey, data, encode } = details;
if (
data === undefined ||
typeof data === 'string' && data === ''
) {
return deleteChunks(datakey, 0);
}
const item = {
source: options.deviceName || options.defaultDeviceName,
tstamp: Date.now(),
@ -1602,14 +1608,20 @@ vAPI.cloud = (( ) => {
}
bin[datakey + chunkCount.toString()] = ''; // Sentinel
// Remove potentially unused trailing chunks before storing the data,
// this will free storage space which could otherwise cause the push
// operation to fail.
try {
await deleteChunks(datakey, chunkCount);
} catch (reason) {
}
// Push the data to browser-provided cloud storage.
try {
await webext.storage.sync.set(bin);
} catch (reason) {
return String(reason);
}
// Remove potentially unused trailing chunks
deleteChunks(datakey, chunkCount);
};
const pull = async function(details) {

View File

@ -73,11 +73,20 @@ const fetchStorageUsed = async function() {
/******************************************************************************/
const fetchCloudData = async function() {
const info = widget.querySelector('#cloudInfo');
const entry = await vAPI.messaging.send('cloudWidget', {
what: 'cloudPull',
datakey: self.cloud.datakey,
});
if ( entry instanceof Object === false ) { return entry; }
const hasData = entry instanceof Object;
if ( hasData === false ) {
uDom.nodeFromId('cloudPull').setAttribute('disabled', '');
uDom.nodeFromId('cloudPullAndMerge').setAttribute('disabled', '');
info.textContent = '...\n...';
return entry;
}
self.cloud.data = entry.data;
@ -96,7 +105,7 @@ const fetchCloudData = async function() {
};
const time = new Date(entry.tstamp);
widget.querySelector('#cloudInfo').textContent =
info.textContent =
entry.source + '\n' +
time.toLocaleString('fullwide', timeOptions);
};