diff --git a/CHANGELOG b/CHANGELOG index 6ea0794..8b6213e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +## 0.1.16 + +fix: RankTracker broken when token expires + ## 0.1.15 fix: rank point change is not uploaded at first challenge ([#11](https://github.com/spacemeowx2/s3si.ts/issues/11)) diff --git a/src/app.ts b/src/app.ts index 494a0ec..0d48095 100644 --- a/src/app.ts +++ b/src/app.ts @@ -129,28 +129,7 @@ export class App { return out; } async exportOnce() { - const exporters = await this.getExporters(); - const stats: Record = Object.fromEntries( - exporters.map((e) => [e.name, 0]), - ); - - await retryRecoverableError(() => - this._exportOnce({ - stats, - }), { - ...this.recoveryToken, - recovery: () => { - if (Object.values(stats).some((i) => i > 0)) { - printStats(stats); - for (const key of Object.keys(stats)) { - stats[key] = 0; - } - } - return this.recoveryToken.recovery(); - }, - }); - - printStats(stats); + await retryRecoverableError(() => this._exportOnce(), this.recoveryToken); } exporterProgress(title: string) { const bar = !this.opts.noProgress @@ -172,7 +151,9 @@ export class App { })), ); } else if (progress.currentUrl) { - console.log(`Battle uploaded to ${progress.currentUrl}`); + console.log( + `Battle exported to ${progress.currentUrl} (${progress.current}/${progress.total})`, + ); } }; const endBar = () => { @@ -181,13 +162,15 @@ export class App { return { redraw, endBar }; } - private async _exportOnce( - { stats }: { - stats: Record; - }, - ) { + private async _exportOnce() { const exporters = await this.getExporters(); + const initStats = () => + Object.fromEntries( + exporters.map((e) => [e.name, 0]), + ); + let stats = initStats(); const skipMode = this.getSkipMode(); + const errors: unknown[] = []; if (skipMode.includes("vs")) { console.log("Skip exporting VS games."); @@ -211,18 +194,27 @@ export class App { fetcher, exporter: e, gameList, - onStep: (progress) => redraw(e.name, progress), + onStep: (progress) => { + redraw(e.name, progress); + stats[e.name] = progress.current; + }, }) .then((count) => { stats[e.name] = count; }), ) .catch((err) => { + errors.push(err); console.error(`\nFailed to export to ${e.name}:`, err); }) ), ); + printStats(stats); + if (errors.length > 0) { + throw errors[0]; + } + // save rankState only if all exporters succeeded fetcher.setRankState(finalRankState); await this.writeState({ @@ -233,6 +225,8 @@ export class App { endBar(); } + stats = initStats(); + // TODO: remove this filter when stat.ink support coop export const coopExporter = exporters.filter((e) => e.name !== "stat.ink"); if (skipMode.includes("coop") || coopExporter.length === 0) { @@ -258,18 +252,27 @@ export class App { fetcher, exporter: e, gameList: coopBattleList, - onStep: (progress) => redraw(e.name, progress), + onStep: (progress) => { + stats[e.name] = progress.current; + redraw(e.name, progress); + }, }) .then((count) => { stats[e.name] = count; }), ) .catch((err) => { + errors.push(err); console.error(`\nFailed to export to ${e.name}:`, err); }) ), ); + printStats(stats); + if (errors.length > 0) { + throw errors[0]; + } + endBar(); } } diff --git a/src/constant.ts b/src/constant.ts index 76641a4..5bb9401 100644 --- a/src/constant.ts +++ b/src/constant.ts @@ -1,7 +1,7 @@ import type { StatInkPostBody, VsHistoryDetail } from "./types.ts"; export const AGENT_NAME = "s3si.ts"; -export const S3SI_VERSION = "0.1.15"; +export const S3SI_VERSION = "0.1.16"; export const NSOAPP_VERSION = "2.3.1"; export const WEB_VIEW_VERSION = "1.0.0-5644e7a2"; export const S3SI_LINK = "https://github.com/spacemeowx2/s3si.ts";