fix: bms-table-sync should just update levels, not add new folders/tables

This commit is contained in:
zkldi
2022-10-27 20:28:40 +01:00
parent d5d4a46dae
commit 1635bc7574
-106
View File
@@ -64,112 +64,6 @@ async function ImportTableLevels(tableJSON: Array<BMSTableEntry>, prefix: string
export async function UpdateTable(tableInfo: BMSTableInfo) {
const table = await LoadBMSTable(tableInfo.url);
const tableID = `bms-${tableInfo.playtype}-${tableInfo.asciiPrefix}`;
const folderIDs = [];
const levels = table.getLevelOrder();
for (const level of levels) {
const query = {
"data¬tableFolders": {
"~elemMatch": {
table: tableInfo.prefix,
// just incase some dude tries numbers
level: level.toString(),
},
},
};
const folderID = CreateFolderID(query, "bms", tableInfo.playtype);
folderIDs.push(folderID);
const exists = await db.folders.findOne({
folderID,
});
if (exists) {
continue;
}
await db.folders.insert({
title: `${tableInfo.prefix}${level}`,
inactive: false,
folderID,
game: "bms",
playtype: tableInfo.playtype,
type: "charts",
data: query,
searchTerms: [`${tableInfo.name} ${level}`],
});
logger.info(`Inserted new folder ${tableInfo.prefix}${level}.`);
}
await db.tables.update(
{ tableID },
{
$set: {
tableID,
game: "bms",
playtype: tableInfo.playtype,
folders: folderIDs,
title: tableInfo.name,
description: tableInfo.description,
inactive: false,
},
$setOnInsert: {
default: false,
},
},
{
upsert: true,
}
);
logger.info(`Bumped table ${tableInfo.name}.`);
logger.info(`Checking meta-folder...`);
const metaQuery = {
"data¬tableFolders¬table": tableInfo.prefix,
};
const folderID = CreateFolderID(metaQuery, "bms", tableInfo.playtype);
folderIDs.push(folderID);
const exists = await db.folders.findOne({
folderID,
});
if (!exists) {
await db.folders.insert({
title: `${tableInfo.name}`,
inactive: false,
folderID,
game: "bms",
playtype: tableInfo.playtype,
type: "charts",
data: metaQuery,
searchTerms: [tableInfo.asciiPrefix],
});
await db.tables.update(
{
tableID: `bms-${tableInfo.playtype}-meta`,
},
{
$push: {
folders: folderID,
},
}
);
logger.info(`Inserted meta folder for ${tableInfo.name}.`);
}
logger.info(`Bumping levels...`);
await ImportTableLevels(table.body, tableInfo.prefix);
logger.info(`Levels bumped.`);