diff --git a/server/package.json b/server/package.json index 9f661f00d..da689d1ad 100644 --- a/server/package.json +++ b/server/package.json @@ -74,7 +74,7 @@ "redis": "3.1.2", "rimraf": "3.0.2", "safe-json-stringify": "1.2.0", - "tachi-common": "0.2.25", + "tachi-common": "0.2.19", "typescript": "4.3.4", "winston": "3.3.3", "winston-transport": "^4.4.0" diff --git a/server/scripts/quick-insert/quick-insert.ts b/server/scripts/quick-insert/quick-insert.ts index ec6b7c994..93cdfc713 100644 --- a/server/scripts/quick-insert/quick-insert.ts +++ b/server/scripts/quick-insert/quick-insert.ts @@ -4,7 +4,7 @@ import { ChartDocument, IDStrings } from "tachi-common"; import { Random20Hex } from "utils/misc"; export async function QuickInsert( - base: ChartDocument, + base: Omit, "chartID">, content: Partial>[], coll: ICollection ) { diff --git a/server/scripts/single-use/convert-2dxtra-charts.ts b/server/scripts/single-use/convert-2dxtra-charts.ts new file mode 100644 index 000000000..ee9328382 --- /dev/null +++ b/server/scripts/single-use/convert-2dxtra-charts.ts @@ -0,0 +1,71 @@ +/* eslint-disable no-await-in-loop */ +import db from "external/mongo/db"; +import { rootLogger } from "lib/logger/logger"; +import { ChartDocument, Difficulties } from "tachi-common"; +import { FindIIDXChartOnInGameID } from "utils/queries/charts"; + +async function ConvertChart(chart: ChartDocument<"iidx:SP" | "iidx:DP">) { + // We need to get the related official song. The best way to do this is + // probably with song IDs. + + const originalChart = await FindIIDXChartOnInGameID( + chart.data.inGameID, + chart.playtype, + chart.difficulty + ); + + if (!originalChart) { + rootLogger.error(`Can't find original chart.`, { chart }); + throw new Error(`Can't find original chart.`); + } + + return { + difficulty: `${chart.data["2dxtraSet"]!} ${chart.difficulty}` as Difficulties[ + | "iidx:SP" + | "iidx:DP"], + songID: originalChart!.songID, + }; +} + +if (require.main === module) { + (async () => { + const modCharts = (await db.charts.iidx.find({ + "data.2dxtraSet": { $ne: null }, + difficulty: { $in: ["BEGINNER", "NORMAL", "HYPER", "ANOTHER", "LEGGENDARIA"] }, + })) as ChartDocument<"iidx:SP" | "iidx:DP">[]; + + rootLogger.info(`Modifying ${modCharts.length} charts.`); + + for (const chart of modCharts) { + const setDoc = await ConvertChart(chart); + + await db.charts.iidx.update( + { + chartID: chart.chartID, + }, + { $set: setDoc } + ); + + // We're also going to have to port over old scores. + + await db.scores.update( + { + chartID: chart.chartID, + }, + { + $set: { + songID: setDoc.songID, + }, + } + ); + } + + rootLogger.info(`Removing ${modCharts.length} songs.`); + + await db.songs.iidx.remove({ + songID: { $in: modCharts.map((e) => e.songID) }, + }); + + rootLogger.info(`Done.`); + })(); +}