mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
Add support for removal of cloud storage entries
This commit is contained in:
parent
db79672355
commit
f6d1c6402f
@ -1559,7 +1559,7 @@ vAPI.cloud = (( ) => {
|
|||||||
return chunkCount;
|
return chunkCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
const deleteChunks = function(datakey, start) {
|
const deleteChunks = async function(datakey, start) {
|
||||||
const keys = [];
|
const keys = [];
|
||||||
|
|
||||||
// No point in deleting more than:
|
// No point in deleting more than:
|
||||||
@ -1579,6 +1579,12 @@ vAPI.cloud = (( ) => {
|
|||||||
|
|
||||||
const push = async function(details) {
|
const push = async function(details) {
|
||||||
const { datakey, data, encode } = details;
|
const { datakey, data, encode } = details;
|
||||||
|
if (
|
||||||
|
data === undefined ||
|
||||||
|
typeof data === 'string' && data === ''
|
||||||
|
) {
|
||||||
|
return deleteChunks(datakey, 0);
|
||||||
|
}
|
||||||
const item = {
|
const item = {
|
||||||
source: options.deviceName || options.defaultDeviceName,
|
source: options.deviceName || options.defaultDeviceName,
|
||||||
tstamp: Date.now(),
|
tstamp: Date.now(),
|
||||||
@ -1602,14 +1608,20 @@ vAPI.cloud = (( ) => {
|
|||||||
}
|
}
|
||||||
bin[datakey + chunkCount.toString()] = ''; // Sentinel
|
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 {
|
try {
|
||||||
await webext.storage.sync.set(bin);
|
await webext.storage.sync.set(bin);
|
||||||
} catch (reason) {
|
} catch (reason) {
|
||||||
return String(reason);
|
return String(reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove potentially unused trailing chunks
|
|
||||||
deleteChunks(datakey, chunkCount);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const pull = async function(details) {
|
const pull = async function(details) {
|
||||||
|
@ -73,11 +73,20 @@ const fetchStorageUsed = async function() {
|
|||||||
/******************************************************************************/
|
/******************************************************************************/
|
||||||
|
|
||||||
const fetchCloudData = async function() {
|
const fetchCloudData = async function() {
|
||||||
|
const info = widget.querySelector('#cloudInfo');
|
||||||
|
|
||||||
const entry = await vAPI.messaging.send('cloudWidget', {
|
const entry = await vAPI.messaging.send('cloudWidget', {
|
||||||
what: 'cloudPull',
|
what: 'cloudPull',
|
||||||
datakey: self.cloud.datakey,
|
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;
|
self.cloud.data = entry.data;
|
||||||
|
|
||||||
@ -96,7 +105,7 @@ const fetchCloudData = async function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const time = new Date(entry.tstamp);
|
const time = new Date(entry.tstamp);
|
||||||
widget.querySelector('#cloudInfo').textContent =
|
info.textContent =
|
||||||
entry.source + '\n' +
|
entry.source + '\n' +
|
||||||
time.toLocaleString('fullwide', timeOptions);
|
time.toLocaleString('fullwide', timeOptions);
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user