From 4423d2a51cf7a4b75ed386ff1b4e387ff8055665 Mon Sep 17 00:00:00 2001 From: daydreamer-json Date: Sun, 1 Mar 2026 14:30:46 +0900 Subject: [PATCH] refactor: optimize raw file fetching logic --- src/cmds/archive.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/cmds/archive.ts b/src/cmds/archive.ts index e0a5af7..867d7cd 100644 --- a/src/cmds/archive.ts +++ b/src/cmds/archive.ts @@ -407,8 +407,7 @@ async function fetchAndSaveAllGameResRawData(gameTargets: GameTarget[]) { ), ].map((e) => JSON.parse(e)) as { region: 'os' | 'cn'; appCode: string; channel: number }[]; const queue = new PQueue({ concurrency: appConfig.threadCount.network }); - const needDlRawFileBase: string[] = []; - const fileNameList = ['index_initial.json', 'index_main.json', 'pref_initial.json', 'pref_main.json', 'patch.json']; + const needDlRawFileBase: { name: string; version: string; path: string }[] = []; for (const target of sanitizedGameTargets) { for (const platform of platforms) { @@ -423,14 +422,19 @@ async function fetchAndSaveAllGameResRawData(gameTargets: GameTarget[]) { ); const resAllJson = (await Bun.file(resAllJsonPath).json()) as StoredData[]; for (const resEntry of resAllJson) { - needDlRawFileBase.push(...resEntry.rsp.resources.map((e) => e.path)); + needDlRawFileBase.push(...resEntry.rsp.resources); } } } const wroteFiles: string[] = []; for (const rawFileBaseEntry of [...new Set(needDlRawFileBase)]) { + const fileNameList = (() => { + if (rawFileBaseEntry.name.includes('main')) return ['index_main.json', 'patch.json']; + if (rawFileBaseEntry.name.includes('initial')) return ['index_initial.json', 'patch.json']; + return ['index_main.json', 'index_initial.json', 'patch.json']; + })(); for (const fileNameEntry of fileNameList) { - const urlObj = new URL(rawFileBaseEntry + '/' + fileNameEntry); + const urlObj = new URL(rawFileBaseEntry.path + '/' + fileNameEntry); urlObj.search = ''; const localFilePath = path.join( argvUtils.getArgv()['outputDir'],