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;
|
||||
};
|
||||
|
||||
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) {
|
||||
|
@ -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);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user