feat: display url when --no-progress

main
spacemeowx2 2022-10-31 12:33:00 +08:00
parent a0bf4c53f5
commit 2ae890866c
5 changed files with 34 additions and 14 deletions

View File

@ -247,6 +247,7 @@ class GameFetcher {
}
type Progress = {
currentUrl?: string;
current: number;
total: number;
};
@ -340,13 +341,17 @@ export class App {
const allProgress: Record<string, Progress> = {};
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,
});

View File

@ -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";

View File

@ -53,6 +53,10 @@ export class FileExporter implements GameExporter {
filepath,
JSON.stringify(body, replacer),
);
return {
url: filepath,
};
}
async notExported({ list }: { list: string[] }): Promise<string[]> {
const out: string[] = [];

View File

@ -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<string[]> {
const uuid = await (await fetch("https://stat.ink/api/v3/s3s/uuid-list", {

View File

@ -161,7 +161,7 @@ export type GameExporter<
notExported: (
{ type, list }: { type: T["type"]; list: string[] },
) => Promise<string[]>;
exportGame: (game: T) => Promise<void>;
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;
};