From 2ae890866c3b1dba7ab7db301d3ff4880959df7e Mon Sep 17 00:00:00 2001 From: spacemeowx2 Date: Mon, 31 Oct 2022 12:33:00 +0800 Subject: [PATCH] feat: display url when --no-progress --- src/app.ts | 22 ++++++++++++++-------- src/constant.ts | 2 +- src/exporters/file.ts | 4 ++++ src/exporters/stat.ink.ts | 11 +++++++---- src/types.ts | 9 ++++++++- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/app.ts b/src/app.ts index 1d2d279..5bf40c2 100644 --- a/src/app.ts +++ b/src/app.ts @@ -247,6 +247,7 @@ class GameFetcher { } type Progress = { + currentUrl?: string; current: number; total: number; }; @@ -340,13 +341,17 @@ export class App { const allProgress: Record = {}; const redraw = (name: string, progress: Progress) => { allProgress[name] = progress; - bar?.render( - Object.entries(allProgress).map(([name, progress]) => ({ - completed: progress.current, - total: progress.total, - text: name, - })), - ); + if (bar) { + bar.render( + Object.entries(allProgress).map(([name, progress]) => ({ + completed: progress.current, + total: progress.total, + text: name, + })), + ); + } else if (progress.currentUrl) { + console.log(`Battle uploaded to ${progress.currentUrl}`); + } }; const endBar = () => { bar?.end(); @@ -554,9 +559,10 @@ export class App { const step = async (id: string) => { const detail = await fetcher.fetch(type, id); - await exporter.exportGame(detail); + const { url } = await exporter.exportGame(detail); exported += 1; onStep?.({ + currentUrl: url, current: exported, total: workQueue.length, }); diff --git a/src/constant.ts b/src/constant.ts index 2c890f0..bff7dfd 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.11"; +export const S3SI_VERSION = "0.1.12"; 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"; diff --git a/src/exporters/file.ts b/src/exporters/file.ts index 234781a..67ba65d 100644 --- a/src/exporters/file.ts +++ b/src/exporters/file.ts @@ -53,6 +53,10 @@ export class FileExporter implements GameExporter { filepath, JSON.stringify(body, replacer), ); + + return { + url: filepath, + }; } async notExported({ list }: { list: string[] }): Promise { const out: string[] = []; diff --git a/src/exporters/stat.ink.ts b/src/exporters/stat.ink.ts index b763322..69e7509 100644 --- a/src/exporters/stat.ink.ts +++ b/src/exporters/stat.ink.ts @@ -11,6 +11,7 @@ import { GameExporter, StatInkPlayer, StatInkPostBody, + StatInkPostResponse, StatInkStage, VsHistoryDetail, VsInfo, @@ -58,7 +59,7 @@ export class StatInkExporter implements GameExporter { async exportGame(game: VsInfo | CoopInfo) { if (game.type === "CoopInfo") { // TODO: support coop - return; + return {}; } const body = await this.mapBattle(game); @@ -71,9 +72,7 @@ export class StatInkExporter implements GameExporter { body: msgpack.encode(body), }); - const json: { - error?: unknown; - } = await resp.json().catch(() => ({})); + const json: StatInkPostResponse = await resp.json().catch(() => ({})); if (resp.status !== 200 && resp.status !== 201) { throw new APIError({ @@ -90,6 +89,10 @@ export class StatInkExporter implements GameExporter { json, }); } + + return { + url: json.url, + }; } async notExported({ list }: { list: string[] }): Promise { const uuid = await (await fetch("https://stat.ink/api/v3/s3s/uuid-list", { diff --git a/src/types.ts b/src/types.ts index ae76d52..3cfe87b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -161,7 +161,7 @@ export type GameExporter< notExported: ( { type, list }: { type: T["type"]; list: string[] }, ) => Promise; - exportGame: (game: T) => Promise; + exportGame: (game: T) => Promise<{ url?: string }>; }; export type RespMap = { @@ -323,3 +323,10 @@ export type StatInkPostBody = { start_at: number; // the battle starts at e.g. 1599577200 end_at: number; }; + +export type StatInkPostResponse = { + error?: unknown; +} & { + id: string; + url: string; +};