mirror of
https://github.com/daydreamer-json/ak-endfield-api-archive.git
synced 2026-03-21 23:02:20 +01:00
refactor: restructure main script for better command handling
This commit is contained in:
@@ -265,7 +265,7 @@ async function mainCmdHandler() {
|
|||||||
['Pool ID', 'Pool Name', 'Pulls', '*6', '*5', '*4', 'Pity *6', '*5', 'Latest'].map((e) => chalk.dim(e)),
|
['Pool ID', 'Pool Name', 'Pulls', '*6', '*5', '*4', 'Pity *6', '*5', 'Latest'].map((e) => chalk.dim(e)),
|
||||||
...gachaPoolInfoList.map((e) => [
|
...gachaPoolInfoList.map((e) => [
|
||||||
e.poolId,
|
e.poolId,
|
||||||
e.pool_name,
|
e.pool_name ?? gachaRecordRsp.find((f) => f.poolId === e.poolId)!.poolName,
|
||||||
...[
|
...[
|
||||||
gachaRecordRsp.filter((f) => f.poolId === e.poolId).length,
|
gachaRecordRsp.filter((f) => f.poolId === e.poolId).length,
|
||||||
gachaRecordRsp.filter((f) => f.poolId === e.poolId && f.rarity === 6).length,
|
gachaRecordRsp.filter((f) => f.poolId === e.poolId && f.rarity === 6).length,
|
||||||
@@ -311,15 +311,17 @@ async function mainCmdHandler() {
|
|||||||
pityR6++;
|
pityR6++;
|
||||||
pityR5++;
|
pityR5++;
|
||||||
if (record.rarity >= 5) {
|
if (record.rarity >= 5) {
|
||||||
|
if (record.rarity === 6) {
|
||||||
tableSubData.push([
|
tableSubData.push([
|
||||||
gachaPoolInfoEntry.poolId,
|
gachaPoolInfoEntry.poolId,
|
||||||
gachaPoolInfoEntry.pool_name,
|
gachaPoolInfoEntry.pool_name ?? records[0]!.poolName,
|
||||||
DateTime.fromMillis(parseInt(record.gachaTs)).toFormat('yyyy/MM/dd hh:mm:ss'),
|
DateTime.fromMillis(parseInt(record.gachaTs)).toFormat('yyyy/MM/dd hh:mm:ss'),
|
||||||
record.rarity === 6 ? pityR6 : pityR5,
|
record.rarity === 6 ? pityR6 : pityR5,
|
||||||
record.rarity === 6
|
record.rarity === 6
|
||||||
? chalk.yellow(`*${record.rarity} ${record.charName}`)
|
? chalk.yellow(`*${record.rarity} ${record.charName}`)
|
||||||
: chalk.magenta(`*${record.rarity} ${record.charName}`),
|
: chalk.magenta(`*${record.rarity} ${record.charName}`),
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
if (record.rarity === 6) pityR6 = 0;
|
if (record.rarity === 6) pityR6 = 0;
|
||||||
pityR5 = 0;
|
pityR5 = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
459
src/cmds/test.ts
459
src/cmds/test.ts
@@ -75,36 +75,208 @@ async function saveResult(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function mainCmdHandler() {
|
async function generateGameListMd(target: { name: string; dirName: string }) {
|
||||||
const cfg = appConfig.network.api.akEndfield;
|
const outputDir = argvUtils.getArgv()['outputDir'];
|
||||||
const channelStr = String(cfg.channel.osWinRel);
|
const gameAllJsonPath = path.join(outputDir, 'akEndfield', 'launcher', 'game', target.dirName, 'all.json');
|
||||||
|
|
||||||
const gameTargets = [
|
if (!(await Bun.file(gameAllJsonPath).exists())) return;
|
||||||
{
|
|
||||||
name: 'Official',
|
|
||||||
launcherAppCode: cfg.appCode.launcher.osWinRel,
|
|
||||||
subChannel: cfg.channel.osWinRel,
|
|
||||||
launcherSubChannel: cfg.channel.osWinRel,
|
|
||||||
dirName: String(cfg.channel.osWinRel),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'Epic',
|
|
||||||
launcherAppCode: cfg.appCode.launcher.osWinRelEpic,
|
|
||||||
subChannel: cfg.subChannel.osWinRelEpic,
|
|
||||||
launcherSubChannel: cfg.subChannel.osWinRelEpic,
|
|
||||||
dirName: String(cfg.subChannel.osWinRelEpic),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'GooglePlay',
|
|
||||||
launcherAppCode: cfg.appCode.launcher.osWinRelEpic,
|
|
||||||
subChannel: cfg.subChannel.osWinRelGooglePlay,
|
|
||||||
launcherSubChannel: cfg.subChannel.osWinRelGooglePlay,
|
|
||||||
dirName: String(cfg.subChannel.osWinRelGooglePlay),
|
|
||||||
},
|
|
||||||
];
|
|
||||||
|
|
||||||
|
const gameAllJson = await Bun.file(gameAllJsonPath).json();
|
||||||
|
const mdTexts: string[] = [];
|
||||||
|
|
||||||
|
const formatSize = (size: number) =>
|
||||||
|
mathUtils.formatFileSize(size, {
|
||||||
|
decimals: 2,
|
||||||
|
decimalPadding: true,
|
||||||
|
unitVisible: true,
|
||||||
|
useBinaryUnit: true,
|
||||||
|
useBitUnit: false,
|
||||||
|
unit: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
mdTexts.push(`# Game Packages (${target.name})\n`);
|
||||||
|
|
||||||
|
// TOC
|
||||||
|
for (const e of gameAllJson) {
|
||||||
|
const version = e.rsp.version;
|
||||||
|
const date = DateTime.fromISO(e.updatedAt, { setZone: true }).setZone('UTC+8');
|
||||||
|
const dateStr = date.toFormat('yyyy/MM/dd HH:mm:ss');
|
||||||
|
const anchorId = `ver-${version}-${Math.ceil(date.toSeconds())}`;
|
||||||
|
mdTexts.push(`- [${version} (${dateStr})](#${anchorId})`);
|
||||||
|
}
|
||||||
|
mdTexts.push('');
|
||||||
|
|
||||||
|
// Content
|
||||||
|
for (const e of gameAllJson) {
|
||||||
|
const version = e.rsp.version;
|
||||||
|
const date = DateTime.fromISO(e.updatedAt, { setZone: true }).setZone('UTC+8');
|
||||||
|
const dateStr = date.toFormat('yyyy/MM/dd HH:mm:ss');
|
||||||
|
const anchorId = `ver-${version}-${Math.ceil(date.toSeconds())}`;
|
||||||
|
|
||||||
|
const packedSize = mathUtils.arrayTotal(e.rsp.pkg.packs.map((f: any) => parseInt(f.package_size)));
|
||||||
|
const unpackedSize = parseInt(e.rsp.pkg.total_size) - packedSize;
|
||||||
|
|
||||||
|
mdTexts.push(
|
||||||
|
`<h2 id="${anchorId}">${version} (${dateStr})</h2>\n`,
|
||||||
|
`<table>`,
|
||||||
|
` <tr><td>Unpacked Size</td><td style="text-align: right;"><b>${formatSize(unpackedSize)}</b></td></tr>`,
|
||||||
|
` <tr><td>Packed Size</td><td style="text-align: right;"><b>${formatSize(packedSize)}</b></td></tr>`,
|
||||||
|
`</table>\n`,
|
||||||
|
`|File|MD5 Checksum|Size|`,
|
||||||
|
`|:--|:--|--:|`,
|
||||||
|
);
|
||||||
|
|
||||||
|
for (const f of e.rsp.pkg.packs) {
|
||||||
|
const fileName = new URL(f.url).pathname.split('/').pop() ?? '';
|
||||||
|
mdTexts.push(`|[${fileName}](${f.url})|\`${f.md5}\`|${formatSize(parseInt(f.package_size))}|`);
|
||||||
|
}
|
||||||
|
mdTexts.push('');
|
||||||
|
}
|
||||||
|
|
||||||
|
await Bun.write(
|
||||||
|
path.join(outputDir, 'akEndfield', 'launcher', 'game', target.dirName, 'list.md'),
|
||||||
|
mdTexts.join('\n'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function generatePatchListMd(target: { name: string; dirName: string }) {
|
||||||
|
const outputDir = argvUtils.getArgv()['outputDir'];
|
||||||
|
const patchAllJsonPath = path.join(outputDir, 'akEndfield', 'launcher', 'game', target.dirName, 'all_patch.json');
|
||||||
|
|
||||||
|
if (!(await Bun.file(patchAllJsonPath).exists())) return;
|
||||||
|
|
||||||
|
const patchAllJson = await Bun.file(patchAllJsonPath).json();
|
||||||
|
const mdTexts: string[] = [];
|
||||||
|
|
||||||
|
const formatSize = (size: number) =>
|
||||||
|
mathUtils.formatFileSize(size, {
|
||||||
|
decimals: 2,
|
||||||
|
decimalPadding: true,
|
||||||
|
unitVisible: true,
|
||||||
|
useBinaryUnit: true,
|
||||||
|
useBitUnit: false,
|
||||||
|
unit: null,
|
||||||
|
});
|
||||||
|
|
||||||
|
mdTexts.push(`# Game Patch Packages (${target.name})\n`);
|
||||||
|
|
||||||
|
// TOC
|
||||||
|
for (const e of patchAllJson) {
|
||||||
|
const version = e.rsp.version;
|
||||||
|
const reqVersion = e.rsp.request_version;
|
||||||
|
const date = DateTime.fromISO(e.updatedAt, { setZone: true }).setZone('UTC+8');
|
||||||
|
const dateStr = date.toFormat('yyyy/MM/dd HH:mm:ss');
|
||||||
|
const anchorId = `ver-${reqVersion}-${version}-${Math.ceil(date.toSeconds())}`;
|
||||||
|
mdTexts.push(`- [${reqVersion} → ${version} (${dateStr})](#${anchorId})`);
|
||||||
|
}
|
||||||
|
mdTexts.push('');
|
||||||
|
|
||||||
|
// Content
|
||||||
|
for (const e of patchAllJson) {
|
||||||
|
const version = e.rsp.version;
|
||||||
|
const reqVersion = e.rsp.request_version;
|
||||||
|
const date = DateTime.fromISO(e.updatedAt, { setZone: true }).setZone('UTC+8');
|
||||||
|
const dateStr = date.toFormat('yyyy/MM/dd HH:mm:ss');
|
||||||
|
const anchorId = `ver-${reqVersion}-${version}-${Math.ceil(date.toSeconds())}`;
|
||||||
|
|
||||||
|
const packedSize = mathUtils.arrayTotal(e.rsp.patch.patches.map((f: any) => parseInt(f.package_size)));
|
||||||
|
const unpackedSize = parseInt(e.rsp.patch.total_size) - packedSize;
|
||||||
|
|
||||||
|
mdTexts.push(
|
||||||
|
`<h2 id="${anchorId}">${reqVersion} → ${version} (${dateStr})</h2>\n`,
|
||||||
|
`<table>`,
|
||||||
|
` <tr><td>Unpacked Size</td><td style="text-align: right;"><b>${formatSize(unpackedSize)}</b></td></tr>`,
|
||||||
|
` <tr><td>Packed Size</td><td style="text-align: right;"><b>${formatSize(packedSize)}</b></td></tr>`,
|
||||||
|
`</table>\n`,
|
||||||
|
`|File|MD5 Checksum|Size|`,
|
||||||
|
`|:--|:--|--:|`,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (e.rsp.patch.url) {
|
||||||
|
const fileName = new URL(e.rsp.patch.url).pathname.split('/').pop() ?? '';
|
||||||
|
mdTexts.push(
|
||||||
|
`|[${fileName}](${e.rsp.patch.url})|\`${e.rsp.patch.md5}\`|${formatSize(parseInt(e.rsp.patch.package_size))}|`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const f of e.rsp.patch.patches) {
|
||||||
|
const fileName = new URL(f.url).pathname.split('/').pop() ?? '';
|
||||||
|
mdTexts.push(`|[${fileName}](${f.url})|\`${f.md5}\`|${formatSize(parseInt(f.package_size))}|`);
|
||||||
|
}
|
||||||
|
mdTexts.push('');
|
||||||
|
}
|
||||||
|
|
||||||
|
await Bun.write(
|
||||||
|
path.join(outputDir, 'akEndfield', 'launcher', 'game', target.dirName, 'list_patch.md'),
|
||||||
|
mdTexts.join('\n'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function generateResourceListMd(channelStr: string) {
|
||||||
|
const outputDir = argvUtils.getArgv()['outputDir'];
|
||||||
|
const mdTexts: string[] = [];
|
||||||
|
mdTexts.push(
|
||||||
|
'# Game Resources\n',
|
||||||
|
'- [Windows](#res-Windows)',
|
||||||
|
'- [Android](#res-Android)',
|
||||||
|
'- [iOS](#res-iOS)',
|
||||||
|
'- [PlayStation](#res-PlayStation)\n',
|
||||||
|
);
|
||||||
|
|
||||||
|
const platforms = ['Windows', 'Android', 'iOS', 'PlayStation'] as const;
|
||||||
|
|
||||||
|
for (const platform of platforms) {
|
||||||
|
const resourceAllJsonPath = path.join(
|
||||||
|
outputDir,
|
||||||
|
'akEndfield',
|
||||||
|
'launcher',
|
||||||
|
'game_resources',
|
||||||
|
channelStr,
|
||||||
|
platform,
|
||||||
|
'all.json',
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!(await Bun.file(resourceAllJsonPath).exists())) continue;
|
||||||
|
|
||||||
|
const gameAllJson = await Bun.file(resourceAllJsonPath).json();
|
||||||
|
const resVersionSet: {
|
||||||
|
resVersion: string;
|
||||||
|
rsp: { rsp: Awaited<ReturnType<typeof apiUtils.akEndfield.launcher.latestGameResources>> };
|
||||||
|
versions: string[];
|
||||||
|
}[] = (() => {
|
||||||
|
const resVersions: string[] = [...new Set(gameAllJson.map((e: any) => e.rsp.res_version))] as string[];
|
||||||
|
const arr: { resVersion: string; rsp: any; versions: string[] }[] = [];
|
||||||
|
for (const resVersion of resVersions) {
|
||||||
|
arr.push({
|
||||||
|
resVersion,
|
||||||
|
rsp: gameAllJson.find((e: any) => e.rsp.res_version === resVersion),
|
||||||
|
versions: [
|
||||||
|
...new Set(gameAllJson.filter((e: any) => e.rsp.res_version === resVersion).map((e: any) => e.req.version)),
|
||||||
|
] as string[],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
})();
|
||||||
|
mdTexts.push(
|
||||||
|
`<h2 id="res-${platform}">${platform}</h2>\n`,
|
||||||
|
'|Res version|Initial|Main|Game version|',
|
||||||
|
'|--|--|--|--|',
|
||||||
|
...resVersionSet.map(
|
||||||
|
(resVerObj) =>
|
||||||
|
`|\`${resVerObj.rsp.rsp.res_version}\`|[${resVerObj.rsp.rsp.resources.find((e) => e.name === 'initial')!.version}](${resVerObj.rsp.rsp.resources.find((e) => e.name === 'initial')!.path})|[${resVerObj.rsp.rsp.resources.find((e) => e.name === 'main')!.version}](${resVerObj.rsp.rsp.resources.find((e) => e.name === 'main')!.path})|${resVerObj.versions.sort((a, b) => semver.compare(b, a)).join(', ')}|`,
|
||||||
|
),
|
||||||
|
'',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
await Bun.write(
|
||||||
|
path.join(outputDir, 'akEndfield', 'launcher', 'game_resources', channelStr, 'list.md'),
|
||||||
|
mdTexts.join('\n'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchAndSaveLatestGames(cfg: any, gameTargets: any[]) {
|
||||||
for (const target of gameTargets) {
|
for (const target of gameTargets) {
|
||||||
await (async () => {
|
|
||||||
logger.debug(`Fetching latestGame (${target.name}) ...`);
|
logger.debug(`Fetching latestGame (${target.name}) ...`);
|
||||||
const rsp = await apiUtils.akEndfield.launcher.latestGame(
|
const rsp = await apiUtils.akEndfield.launcher.latestGame(
|
||||||
cfg.appCode.game.osWinRel,
|
cfg.appCode.game.osWinRel,
|
||||||
@@ -139,11 +311,11 @@ async function mainCmdHandler() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
await saveResult(['akEndfield', 'launcher', 'game', target.dirName], rsp.version, prettyRsp);
|
await saveResult(['akEndfield', 'launcher', 'game', target.dirName], rsp.version, prettyRsp);
|
||||||
})();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function fetchAndSaveLatestGamePatches(cfg: any, gameTargets: any[]) {
|
||||||
for (const target of gameTargets) {
|
for (const target of gameTargets) {
|
||||||
await (async () => {
|
|
||||||
logger.debug(`Fetching latestGame (patch) (${target.name}) ...`);
|
logger.debug(`Fetching latestGame (patch) (${target.name}) ...`);
|
||||||
const gameAllJsonPath = path.join(
|
const gameAllJsonPath = path.join(
|
||||||
argvUtils.getArgv()['outputDir'],
|
argvUtils.getArgv()['outputDir'],
|
||||||
@@ -162,7 +334,7 @@ async function mainCmdHandler() {
|
|||||||
'all_patch.json',
|
'all_patch.json',
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!(await Bun.file(gameAllJsonPath).exists())) return;
|
if (!(await Bun.file(gameAllJsonPath).exists())) continue;
|
||||||
|
|
||||||
const gameAllJson = await Bun.file(gameAllJsonPath).json();
|
const gameAllJson = await Bun.file(gameAllJsonPath).json();
|
||||||
let patchAllJson: any[] = [];
|
let patchAllJson: any[] = [];
|
||||||
@@ -227,10 +399,10 @@ async function mainCmdHandler() {
|
|||||||
if (needWrite) {
|
if (needWrite) {
|
||||||
await Bun.write(patchAllJsonPath, JSON.stringify(patchAllJson, null, 2));
|
await Bun.write(patchAllJsonPath, JSON.stringify(patchAllJson, null, 2));
|
||||||
}
|
}
|
||||||
})();
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await (async () => {
|
async function fetchAndSaveLatestGameResources(cfg: any, channelStr: string) {
|
||||||
logger.debug('Fetching latestGameRes ...');
|
logger.debug('Fetching latestGameRes ...');
|
||||||
|
|
||||||
const platforms = ['Windows', 'Android', 'iOS', 'PlayStation'] as const;
|
const platforms = ['Windows', 'Android', 'iOS', 'PlayStation'] as const;
|
||||||
@@ -293,9 +465,9 @@ async function mainCmdHandler() {
|
|||||||
isLatestWrote = true;
|
isLatestWrote = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})();
|
}
|
||||||
|
|
||||||
await (async () => {
|
async function fetchAndSaveLatestLauncher(cfg: any, channelStr: string) {
|
||||||
logger.debug('Fetching latestLauncher ...');
|
logger.debug('Fetching latestLauncher ...');
|
||||||
const launcherTargetAppList = ['EndField', 'official'] as const;
|
const launcherTargetAppList = ['EndField', 'official'] as const;
|
||||||
for (const launcherTargetAppEntry of launcherTargetAppList) {
|
for (const launcherTargetAppEntry of launcherTargetAppList) {
|
||||||
@@ -323,193 +495,48 @@ async function mainCmdHandler() {
|
|||||||
prettyRsp,
|
prettyRsp,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
})();
|
}
|
||||||
|
|
||||||
|
async function mainCmdHandler() {
|
||||||
|
const cfg = appConfig.network.api.akEndfield;
|
||||||
|
const channelStr = String(cfg.channel.osWinRel);
|
||||||
|
|
||||||
|
const gameTargets = [
|
||||||
|
{
|
||||||
|
name: 'Official',
|
||||||
|
launcherAppCode: cfg.appCode.launcher.osWinRel,
|
||||||
|
subChannel: cfg.channel.osWinRel,
|
||||||
|
launcherSubChannel: cfg.channel.osWinRel,
|
||||||
|
dirName: String(cfg.channel.osWinRel),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Epic',
|
||||||
|
launcherAppCode: cfg.appCode.launcher.osWinRelEpic,
|
||||||
|
subChannel: cfg.subChannel.osWinRelEpic,
|
||||||
|
launcherSubChannel: cfg.subChannel.osWinRelEpic,
|
||||||
|
dirName: String(cfg.subChannel.osWinRelEpic),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'GooglePlay',
|
||||||
|
launcherAppCode: cfg.appCode.launcher.osWinRelEpic,
|
||||||
|
subChannel: cfg.subChannel.osWinRelGooglePlay,
|
||||||
|
launcherSubChannel: cfg.subChannel.osWinRelGooglePlay,
|
||||||
|
dirName: String(cfg.subChannel.osWinRelGooglePlay),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
await fetchAndSaveLatestGames(cfg, gameTargets);
|
||||||
|
await fetchAndSaveLatestGamePatches(cfg, gameTargets);
|
||||||
|
await fetchAndSaveLatestGameResources(cfg, channelStr);
|
||||||
|
await fetchAndSaveLatestLauncher(cfg, channelStr);
|
||||||
|
|
||||||
await (async () => {
|
await (async () => {
|
||||||
//* Markdown generate
|
//* Markdown generate
|
||||||
for (const target of gameTargets) {
|
for (const target of gameTargets) {
|
||||||
await (async () => {
|
await generateGameListMd(target);
|
||||||
const gameAllJsonPath = path.join(
|
await generatePatchListMd(target);
|
||||||
argvUtils.getArgv()['outputDir'],
|
|
||||||
'akEndfield',
|
|
||||||
'launcher',
|
|
||||||
'game',
|
|
||||||
target.dirName,
|
|
||||||
'all.json',
|
|
||||||
);
|
|
||||||
if (!(await Bun.file(gameAllJsonPath).exists())) return;
|
|
||||||
const gameAllJson = await Bun.file(gameAllJsonPath).json();
|
|
||||||
const mdTexts: string[] = [];
|
|
||||||
mdTexts.push(
|
|
||||||
...[
|
|
||||||
`# Game Packages (${target.name})\n`,
|
|
||||||
...gameAllJson.map(
|
|
||||||
(e: any) =>
|
|
||||||
`- [${e.rsp.version} (${DateTime.fromISO(e.updatedAt, { setZone: true }).setZone('UTC+8').toFormat('yyyy/MM/dd HH:mm:ss')})](#ver-${e.rsp.version}-${Math.ceil(DateTime.fromISO(e.updatedAt).toSeconds())})`,
|
|
||||||
),
|
|
||||||
'',
|
|
||||||
],
|
|
||||||
...gameAllJson.map((e: any) =>
|
|
||||||
[
|
|
||||||
`<h2 id="ver-${e.rsp.version}-${Math.ceil(DateTime.fromISO(e.updatedAt).toSeconds())}">${e.rsp.version} (${DateTime.fromISO(e.updatedAt, { setZone: true }).setZone('UTC+8').toFormat('yyyy/MM/dd HH:mm:ss')})</h2>\n`,
|
|
||||||
`<table>`,
|
|
||||||
` <tr><td>Unpacked Size</td><td style="text-align: right;"><b>${mathUtils.formatFileSize(
|
|
||||||
e.rsp.pkg.total_size - mathUtils.arrayTotal(e.rsp.pkg.packs.map((f: any) => parseInt(f.package_size))),
|
|
||||||
{
|
|
||||||
decimals: 2,
|
|
||||||
decimalPadding: true,
|
|
||||||
unitVisible: true,
|
|
||||||
useBinaryUnit: true,
|
|
||||||
useBitUnit: false,
|
|
||||||
unit: null,
|
|
||||||
},
|
|
||||||
)}</b></td></tr>`,
|
|
||||||
` <tr><td>Packed Size</td><td style="text-align: right;"><b>${mathUtils.formatFileSize(mathUtils.arrayTotal(e.rsp.pkg.packs.map((f: any) => parseInt(f.package_size))), { decimals: 2, decimalPadding: true, unitVisible: true, useBinaryUnit: true, useBitUnit: false, unit: null })}</b></td></tr>`,
|
|
||||||
`</table>\n`,
|
|
||||||
`|File|MD5 Checksum|Size|`,
|
|
||||||
`|:--|:--|--:|`,
|
|
||||||
...e.rsp.pkg.packs.map((f: any) => [
|
|
||||||
`|[${new URL(f.url).pathname.split('/').pop() ?? ''}](${f.url})|\`${f.md5}\`|${mathUtils.formatFileSize(parseInt(f.package_size), { decimals: 2, decimalPadding: true, unitVisible: true, useBinaryUnit: true, useBitUnit: false, unit: null })}|`,
|
|
||||||
]),
|
|
||||||
'',
|
|
||||||
].join('\n'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
await Bun.write(
|
|
||||||
path.join(argvUtils.getArgv()['outputDir'], 'akEndfield', 'launcher', 'game', target.dirName, 'list.md'),
|
|
||||||
mdTexts.join('\n'),
|
|
||||||
);
|
|
||||||
})();
|
|
||||||
|
|
||||||
await (async () => {
|
|
||||||
const patchAllJsonPath = path.join(
|
|
||||||
argvUtils.getArgv()['outputDir'],
|
|
||||||
'akEndfield',
|
|
||||||
'launcher',
|
|
||||||
'game',
|
|
||||||
target.dirName,
|
|
||||||
'all_patch.json',
|
|
||||||
);
|
|
||||||
if (!(await Bun.file(patchAllJsonPath).exists())) return;
|
|
||||||
const gameAllJson = await Bun.file(patchAllJsonPath).json();
|
|
||||||
const mdTexts: string[] = [];
|
|
||||||
mdTexts.push(
|
|
||||||
...[
|
|
||||||
`# Game Patch Packages (${target.name})\n`,
|
|
||||||
...gameAllJson.map(
|
|
||||||
(e: any) =>
|
|
||||||
`- [${e.rsp.request_version} → ${e.rsp.version} (${DateTime.fromISO(e.updatedAt, { setZone: true }).setZone('UTC+8').toFormat('yyyy/MM/dd HH:mm:ss')})](#ver-${e.rsp.request_version}-${e.rsp.version}-${Math.ceil(DateTime.fromISO(e.updatedAt).toSeconds())})`,
|
|
||||||
),
|
|
||||||
'',
|
|
||||||
],
|
|
||||||
...gameAllJson.map((e: any) =>
|
|
||||||
[
|
|
||||||
`<h2 id="ver-${e.rsp.request_version}-${e.rsp.version}-${Math.ceil(DateTime.fromISO(e.updatedAt).toSeconds())}">${e.rsp.request_version} → ${e.rsp.version} (${DateTime.fromISO(e.updatedAt, { setZone: true }).setZone('UTC+8').toFormat('yyyy/MM/dd HH:mm:ss')})</h2>\n`,
|
|
||||||
`<table>`,
|
|
||||||
` <tr><td>Unpacked Size</td><td style="text-align: right;"><b>${mathUtils.formatFileSize(
|
|
||||||
e.rsp.patch.total_size -
|
|
||||||
mathUtils.arrayTotal(e.rsp.patch.patches.map((f: any) => parseInt(f.package_size))),
|
|
||||||
{
|
|
||||||
decimals: 2,
|
|
||||||
decimalPadding: true,
|
|
||||||
unitVisible: true,
|
|
||||||
useBinaryUnit: true,
|
|
||||||
useBitUnit: false,
|
|
||||||
unit: null,
|
|
||||||
},
|
|
||||||
)}</b></td></tr>`,
|
|
||||||
` <tr><td>Packed Size</td><td style="text-align: right;"><b>${mathUtils.formatFileSize(mathUtils.arrayTotal(e.rsp.patch.patches.map((f: any) => parseInt(f.package_size))), { decimals: 2, decimalPadding: true, unitVisible: true, useBinaryUnit: true, useBitUnit: false, unit: null })}</b></td></tr>`,
|
|
||||||
`</table>\n`,
|
|
||||||
`|File|MD5 Checksum|Size|`,
|
|
||||||
`|:--|:--|--:|`,
|
|
||||||
...(e.rsp.patch.url
|
|
||||||
? [
|
|
||||||
`|[${new URL(e.rsp.patch.url).pathname.split('/').pop() ?? ''}](${e.rsp.patch.url})|\`${e.rsp.patch.md5}\`|${mathUtils.formatFileSize(parseInt(e.rsp.patch.package_size), { decimals: 2, decimalPadding: true, unitVisible: true, useBinaryUnit: true, useBitUnit: false, unit: null })}|`,
|
|
||||||
]
|
|
||||||
: []),
|
|
||||||
...e.rsp.patch.patches.map((f: any) => [
|
|
||||||
`|[${new URL(f.url).pathname.split('/').pop() ?? ''}](${f.url})|\`${f.md5}\`|${mathUtils.formatFileSize(parseInt(f.package_size), { decimals: 2, decimalPadding: true, unitVisible: true, useBinaryUnit: true, useBitUnit: false, unit: null })}|`,
|
|
||||||
]),
|
|
||||||
'',
|
|
||||||
].join('\n'),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
await Bun.write(
|
|
||||||
path.join(
|
|
||||||
argvUtils.getArgv()['outputDir'],
|
|
||||||
'akEndfield',
|
|
||||||
'launcher',
|
|
||||||
'game',
|
|
||||||
target.dirName,
|
|
||||||
'list_patch.md',
|
|
||||||
),
|
|
||||||
mdTexts.join('\n'),
|
|
||||||
);
|
|
||||||
})();
|
|
||||||
}
|
}
|
||||||
|
await generateResourceListMd(channelStr);
|
||||||
await (async () => {
|
|
||||||
const mdTexts: string[] = [];
|
|
||||||
mdTexts.push(
|
|
||||||
'# Game Resources\n',
|
|
||||||
'- [Windows](#res-Windows)',
|
|
||||||
'- [Android](#res-Android)',
|
|
||||||
'- [iOS](#res-iOS)',
|
|
||||||
'- [PlayStation](#res-PlayStation)\n',
|
|
||||||
);
|
|
||||||
// `<h2 id="ver-${e.rsp.version}-${Math.ceil(DateTime.fromISO(e.updatedAt).toSeconds())}">${e.rsp.version} (${DateTime.fromISO(e.updatedAt, { setZone: true }).setZone('UTC+8').toFormat('yyyy/MM/dd HH:mm:ss')})</h2>\n`
|
|
||||||
|
|
||||||
const platforms = ['Windows', 'Android', 'iOS', 'PlayStation'] as const;
|
|
||||||
|
|
||||||
for (const platform of platforms) {
|
|
||||||
const gameAllJson = await Bun.file(
|
|
||||||
path.join(
|
|
||||||
argvUtils.getArgv()['outputDir'],
|
|
||||||
'akEndfield',
|
|
||||||
'launcher',
|
|
||||||
'game_resources',
|
|
||||||
channelStr,
|
|
||||||
platform,
|
|
||||||
'all.json',
|
|
||||||
),
|
|
||||||
).json();
|
|
||||||
const resVersionSet: {
|
|
||||||
resVersion: string;
|
|
||||||
rsp: { rsp: Awaited<ReturnType<typeof apiUtils.akEndfield.launcher.latestGameResources>> };
|
|
||||||
versions: string[];
|
|
||||||
}[] = (() => {
|
|
||||||
const resVersions: string[] = [...new Set(gameAllJson.map((e: any) => e.rsp.res_version))] as string[];
|
|
||||||
const arr: { resVersion: string; rsp: any; versions: string[] }[] = [];
|
|
||||||
for (const resVersion of resVersions) {
|
|
||||||
arr.push({
|
|
||||||
resVersion,
|
|
||||||
rsp: gameAllJson.find((e: any) => e.rsp.res_version === resVersion),
|
|
||||||
versions: [
|
|
||||||
...new Set(
|
|
||||||
gameAllJson.filter((e: any) => e.rsp.res_version === resVersion).map((e: any) => e.req.version),
|
|
||||||
),
|
|
||||||
] as string[],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return arr;
|
|
||||||
})();
|
|
||||||
mdTexts.push(
|
|
||||||
`<h2 id="res-${platform}">${platform}</h2>\n`,
|
|
||||||
'|Res version|Initial|Main|Game version|',
|
|
||||||
'|--|--|--|--|',
|
|
||||||
...resVersionSet.map(
|
|
||||||
(resVerObj) =>
|
|
||||||
`|\`${resVerObj.rsp.rsp.res_version}\`|[${resVerObj.rsp.rsp.resources.find((e) => e.name === 'initial')!.version}](${resVerObj.rsp.rsp.resources.find((e) => e.name === 'initial')!.path})|[${resVerObj.rsp.rsp.resources.find((e) => e.name === 'main')!.version}](${resVerObj.rsp.rsp.resources.find((e) => e.name === 'main')!.path})|${resVerObj.versions.sort((a, b) => semver.compare(b, a)).join(', ')}|`,
|
|
||||||
),
|
|
||||||
'',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
await Bun.write(
|
|
||||||
path.join(argvUtils.getArgv()['outputDir'], 'akEndfield', 'launcher', 'game_resources', channelStr, 'list.md'),
|
|
||||||
mdTexts.join('\n'),
|
|
||||||
);
|
|
||||||
})();
|
|
||||||
})();
|
})();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user