1
0
Fork 0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2025-07-04 20:46:39 +02:00

Improved storage of protected API features

This commit is contained in:
kkapsner 2019-11-11 15:30:11 +01:00
parent 1430b89d55
commit cc776b48de
6 changed files with 73 additions and 37 deletions

View file

@ -12,6 +12,9 @@
else {
scope = require.register("./settingsMigration", {});
}
const settingDefinitions = require("./settingDefinitions");
scope.validVersions = [undefined, 0.1, 0.2, 0.3, 0.4, 0.5];
scope.transitions = {
"": function(oldStorage){
@ -129,7 +132,31 @@
}
}
return newStorage;
}
},
0.5: function(oldStorage){
var newStorage = {
storageVersion: 0.6
};
if (oldStorage.hasOwnProperty("protectedAPIFeatures")){
const protectedAPIFeatures = {};
const protectedAPIFeaturesKeys = settingDefinitions.filter(function(definition){
return definition.name === "protectedAPIFeatures";
})[0].keys.filter(function(key){
return typeof key === "string";
});
Object.keys(oldStorage.protectedAPIFeatures).forEach(function(key){
const matchingKeys = protectedAPIFeaturesKeys.filter(function(definedKey){
return definedKey.startsWith(key);
});
if (matchingKeys.length){
protectedAPIFeatures[matchingKeys[0]] = oldStorage.protectedAPIFeatures[key];
}
});
newStorage.protectedAPIFeatures = protectedAPIFeatures;
}
return newStorage;
},
};
scope.check = function(storage, {settings, logging, changeValue, urlContainer}){