mirror of
https://github.com/ajayyy/SponsorBlock.git
synced 2025-12-10 21:47:06 +03:00
Fixed data old format migration.
This commit is contained in:
@@ -84,10 +84,6 @@ class SBMap<T, U> extends Map {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
toJSON() {
|
|
||||||
return Array.from(this.entries());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var Config: SBObject = {
|
var Config: SBObject = {
|
||||||
@@ -130,7 +126,7 @@ var Config: SBObject = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* A SBMap cannot be stored in the chrome storage.
|
* A SBMap cannot be stored in the chrome storage.
|
||||||
* This data will be encoded into an array instead as specified by the toJSON function.
|
* This data will be encoded into an array instead
|
||||||
*
|
*
|
||||||
* @param data
|
* @param data
|
||||||
*/
|
*/
|
||||||
@@ -151,26 +147,24 @@ function decodeStoredItem(id: string, data) {
|
|||||||
|
|
||||||
if (Config.defaults[id] instanceof SBMap) {
|
if (Config.defaults[id] instanceof SBMap) {
|
||||||
try {
|
try {
|
||||||
if (!Array.isArray(data)) return data;
|
let jsonData: any = data;
|
||||||
return new SBMap(id, data);
|
|
||||||
} catch(e) {
|
|
||||||
console.error("Failed to parse SBMap: "+ id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// This is the old format for SBMap (a JSON string)
|
// Check if data is stored in the old format for SBMap (a JSON string)
|
||||||
if (typeof data === "string") {
|
if (typeof data === "string") {
|
||||||
try {
|
try {
|
||||||
let str = JSON.parse(data);
|
jsonData = JSON.parse(data);
|
||||||
|
} catch(e) {
|
||||||
if (Array.isArray(data)) {
|
// Continue normally (out of this if statement)
|
||||||
return new SBMap(id, str);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!Array.isArray(jsonData)) return data;
|
||||||
|
return new SBMap(id, jsonData);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
// Continue normally (out of this if statement)
|
console.error("Failed to parse SBMap: " + id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If all else fails, return the data
|
// If all else fails, return the data
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user