2023-06-24 14:32:47 +00:00
|
|
|
import {type Migration} from "@holllo/migration-helper";
|
2023-06-26 10:10:08 +00:00
|
|
|
import {
|
|
|
|
Data,
|
|
|
|
Feature,
|
2023-06-28 16:46:27 +00:00
|
|
|
createValueUsernamecolor,
|
2023-06-26 10:10:08 +00:00
|
|
|
createValueUserLabel,
|
|
|
|
fromStorage,
|
2023-06-28 16:46:27 +00:00
|
|
|
saveUsernameColors,
|
2023-06-26 10:10:08 +00:00
|
|
|
saveUserLabels,
|
2023-06-27 11:51:04 +00:00
|
|
|
} from "../exports.js";
|
2023-06-28 16:46:27 +00:00
|
|
|
import {v112DeserializeData, type V112Settings} from "./v1-1-2.js";
|
2023-06-24 14:32:47 +00:00
|
|
|
|
|
|
|
export const migrations: Array<Migration<string>> = [
|
|
|
|
{
|
|
|
|
version: "2.0.0",
|
|
|
|
async migrate(data: V112Settings): Promise<void> {
|
|
|
|
const deserialized = v112DeserializeData(data);
|
|
|
|
data.data.userLabels = deserialized.userLabels;
|
|
|
|
data.data.usernameColors = deserialized.usernameColors;
|
2023-06-26 10:10:08 +00:00
|
|
|
|
2023-06-28 16:46:27 +00:00
|
|
|
const usernameColors = [];
|
2023-06-26 10:10:08 +00:00
|
|
|
const userLabels = [];
|
2023-06-28 16:46:27 +00:00
|
|
|
|
|
|
|
for (const usernameColor of data.data.usernameColors) {
|
|
|
|
usernameColors.push(await createValueUsernamecolor(usernameColor));
|
|
|
|
}
|
|
|
|
|
2023-06-26 10:10:08 +00:00
|
|
|
for (const userLabel of data.data.userLabels) {
|
|
|
|
userLabels.push(await createValueUserLabel(userLabel));
|
|
|
|
}
|
|
|
|
|
2023-06-28 16:46:27 +00:00
|
|
|
await saveUsernameColors(usernameColors);
|
2023-06-26 10:10:08 +00:00
|
|
|
await saveUserLabels(userLabels);
|
2023-06-24 14:32:47 +00:00
|
|
|
|
|
|
|
const hideVotes = await fromStorage(Feature.HideVotes);
|
|
|
|
hideVotes.value = {
|
|
|
|
otherComments: data.data.hideVotes.comments,
|
|
|
|
otherTopics: data.data.hideVotes.topics,
|
|
|
|
ownComments: data.data.hideVotes.ownComments,
|
|
|
|
ownTopics: data.data.hideVotes.ownTopics,
|
|
|
|
};
|
|
|
|
await hideVotes.save();
|
|
|
|
|
|
|
|
const knownGroups = await fromStorage(Data.KnownGroups);
|
|
|
|
knownGroups.value = new Set(data.data.knownGroups);
|
|
|
|
await knownGroups.save();
|
|
|
|
|
|
|
|
const version = await fromStorage(Data.Version);
|
|
|
|
version.value = "2.0.0";
|
|
|
|
await version.save();
|
|
|
|
|
|
|
|
const enabledFeatures = await fromStorage(Data.EnabledFeatures);
|
2023-07-04 17:09:20 +00:00
|
|
|
enabledFeatures.value.clear();
|
2023-06-24 14:32:47 +00:00
|
|
|
for (const [key, value] of Object.entries(data.features)) {
|
|
|
|
if (value) {
|
|
|
|
const snakeCasedKey = key.replace(/([A-Z])/g, "-$1").toLowerCase();
|
|
|
|
if (Object.values(Feature).includes(snakeCasedKey as Feature)) {
|
|
|
|
enabledFeatures.value.add(snakeCasedKey as Feature);
|
|
|
|
} else {
|
|
|
|
throw new Error(`Unknown key: ${key}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
await enabledFeatures.save();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
];
|