mirror of
https://github.com/zkldi/Tachi.git
synced 2026-10-01 19:38:13 +03:00
Co-authored-by: Olivia Simmons <38598881+justOkapi@users.noreply.github.com> Co-authored-by: tachi-seeds <107944937+tachi-seeds@users.noreply.github.com> Co-authored-by: beerpiss <lacvtg.a1.2023@gmail.com>
46 lines
1.1 KiB
JavaScript
46 lines
1.1 KiB
JavaScript
const logger = require("../logger");
|
|
const { MutateCollection, CreateFolderID, ReadCollection, WriteCollection } = require("../util");
|
|
|
|
const translateMap = new Map();
|
|
|
|
const origFolders = ReadCollection("folders.json", true);
|
|
|
|
MutateCollection("folders.json", (folders) => {
|
|
logger.info("Updating Folders.");
|
|
|
|
for (const folder of folders) {
|
|
const newFolderID = CreateFolderID(folder.data, folder.game, folder.playtype);
|
|
|
|
translateMap.set(folder.folderID, newFolderID);
|
|
|
|
folder.folderID = newFolderID;
|
|
}
|
|
|
|
return folders;
|
|
});
|
|
|
|
try {
|
|
MutateCollection("tables.json", (tables) => {
|
|
logger.info("Updating Tables.");
|
|
|
|
for (const table of tables) {
|
|
table.folders = table.folders.map((e) => {
|
|
const newFolderID = translateMap.get(e);
|
|
|
|
if (!newFolderID) {
|
|
throw new Error(`${e} doesn't exist as a folderID? Can't autofix.`);
|
|
}
|
|
|
|
return newFolderID;
|
|
});
|
|
}
|
|
|
|
logger.info("Done.");
|
|
|
|
return tables;
|
|
});
|
|
} catch (err) {
|
|
logger.error("Failed to update tables.json, reverting all auto-folder fixes.", { err });
|
|
WriteCollection("folders.json", origFolders);
|
|
}
|