mirror of
https://github.com/daydreamer-json/ak-endfield-api-archive.git
synced 2026-03-26 17:22:22 +01:00
refactor: optimize raw file fetching logic
This commit is contained in:
@@ -407,8 +407,7 @@ async function fetchAndSaveAllGameResRawData(gameTargets: GameTarget[]) {
|
|||||||
),
|
),
|
||||||
].map((e) => JSON.parse(e)) as { region: 'os' | 'cn'; appCode: string; channel: number }[];
|
].map((e) => JSON.parse(e)) as { region: 'os' | 'cn'; appCode: string; channel: number }[];
|
||||||
const queue = new PQueue({ concurrency: appConfig.threadCount.network });
|
const queue = new PQueue({ concurrency: appConfig.threadCount.network });
|
||||||
const needDlRawFileBase: string[] = [];
|
const needDlRawFileBase: { name: string; version: string; path: string }[] = [];
|
||||||
const fileNameList = ['index_initial.json', 'index_main.json', 'pref_initial.json', 'pref_main.json', 'patch.json'];
|
|
||||||
|
|
||||||
for (const target of sanitizedGameTargets) {
|
for (const target of sanitizedGameTargets) {
|
||||||
for (const platform of platforms) {
|
for (const platform of platforms) {
|
||||||
@@ -423,14 +422,19 @@ async function fetchAndSaveAllGameResRawData(gameTargets: GameTarget[]) {
|
|||||||
);
|
);
|
||||||
const resAllJson = (await Bun.file(resAllJsonPath).json()) as StoredData<LatestGameResourcesResponse>[];
|
const resAllJson = (await Bun.file(resAllJsonPath).json()) as StoredData<LatestGameResourcesResponse>[];
|
||||||
for (const resEntry of resAllJson) {
|
for (const resEntry of resAllJson) {
|
||||||
needDlRawFileBase.push(...resEntry.rsp.resources.map((e) => e.path));
|
needDlRawFileBase.push(...resEntry.rsp.resources);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const wroteFiles: string[] = [];
|
const wroteFiles: string[] = [];
|
||||||
for (const rawFileBaseEntry of [...new Set(needDlRawFileBase)]) {
|
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) {
|
for (const fileNameEntry of fileNameList) {
|
||||||
const urlObj = new URL(rawFileBaseEntry + '/' + fileNameEntry);
|
const urlObj = new URL(rawFileBaseEntry.path + '/' + fileNameEntry);
|
||||||
urlObj.search = '';
|
urlObj.search = '';
|
||||||
const localFilePath = path.join(
|
const localFilePath = path.join(
|
||||||
argvUtils.getArgv()['outputDir'],
|
argvUtils.getArgv()['outputDir'],
|
||||||
|
|||||||
Reference in New Issue
Block a user