1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-07 03:12:33 +01:00

Remove obsolete code related to assets storage refactoring in 1.11.0

The removed code was quite old, and was about how user filters were
persisted before/after uBO version 1.11, related to the following
issue:
- https://github.com/gorhill/uBlock/pull/2314

The assets storage refactoring was released in:
- https://github.com/gorhill/uBlock/releases/tag/1.11.0
This commit is contained in:
Raymond Hill 2019-03-06 08:59:13 -05:00
parent 4f43160699
commit 3a8b68ea76
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -643,63 +643,35 @@ const stringIsNotEmpty = function(s) {
**/ **/
/*******************************************************************************
User assets are NOT persisted in the cache storage. User assets are
recognized by the asset key which always starts with 'user-'.
**/
const readUserAsset = function(assetKey, callback) { const readUserAsset = function(assetKey, callback) {
const reportBack = function(content) { const reportBack = function(content) {
callback({ assetKey: assetKey, content: content }); callback({ assetKey, content });
}; };
vAPI.storage.get(assetKey, bin => {
const onLoaded = function(bin) { const content =
if ( !bin ) { return reportBack(''); } bin instanceof Object && typeof bin[assetKey] === 'string'
var content = ''; ? bin[assetKey]
if ( typeof bin['cached_asset_content://assets/user/filters.txt'] === 'string' ) { : '';
content = bin['cached_asset_content://assets/user/filters.txt'];
µBlock.cacheStorage.remove('cached_asset_content://assets/user/filters.txt');
}
if ( typeof bin['assets/user/filters.txt'] === 'string' ) {
content = bin['assets/user/filters.txt'];
// TODO(seamless migration):
// Uncomment once all moved to v1.11+.
//vAPI.storage.remove('assets/user/filters.txt');
}
if ( typeof bin[assetKey] === 'string' ) {
// TODO(seamless migration):
// Replace conditional with assignment once all moved to v1.11+
if ( content !== bin[assetKey] ) {
saveUserAsset(assetKey, content);
}
} else if ( content !== '' ) {
saveUserAsset(assetKey, content);
}
return reportBack(content); return reportBack(content);
}; });
let toRead = assetKey; // Remove obsolete entry
if ( assetKey === µBlock.userFiltersPath ) { // TODO: remove once everybody is well beyond 1.18.6
toRead = [ vAPI.storage.remove('assets/user/filters.txt');
assetKey,
'assets/user/filters.txt',
'cached_asset_content://assets/user/filters.txt'
];
}
vAPI.storage.get(toRead, onLoaded);
}; };
const saveUserAsset = function(assetKey, content, callback) { const saveUserAsset = function(assetKey, content, callback) {
var bin = {}; vAPI.storage.set({ [assetKey]: content }, ( ) => {
bin[assetKey] = content;
// TODO(seamless migration):
// This is for forward compatibility. Only for a limited time. Remove when
// everybody moved to 1.11.0 and beyond.
// >>>>>>>>
if ( assetKey === µBlock.userFiltersPath ) {
bin['assets/user/filters.txt'] = content;
}
// <<<<<<<<
var onSaved = function() {
if ( callback instanceof Function ) { if ( callback instanceof Function ) {
callback({ assetKey: assetKey, content: content }); callback({ assetKey, content });
} }
}; });
vAPI.storage.set(bin, onSaved);
}; };
/******************************************************************************/ /******************************************************************************/