diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f4b824..3a892b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## 0.1.28 + +fix: allow random weapon + +feat: save pathname of image in file exporter + ## 0.1.27 fix: export error when disconnected diff --git a/src/constant.ts b/src/constant.ts index 391158d..faa46ee 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.27"; +export const S3SI_VERSION = "0.1.28"; export const NSOAPP_VERSION = "2.3.1"; export const WEB_VIEW_VERSION = "1.0.0-433ec0e8"; export const S3SI_LINK = "https://github.com/spacemeowx2/s3si.ts"; diff --git a/src/exporters/file.ts b/src/exporters/file.ts index 67ba65d..5803a02 100644 --- a/src/exporters/file.ts +++ b/src/exporters/file.ts @@ -1,7 +1,7 @@ import { CoopInfo, GameExporter, VsInfo } from "../types.ts"; import { path } from "../../deps.ts"; import { NSOAPP_VERSION, S3SI_VERSION } from "../constant.ts"; -import { parseHistoryDetailId } from "../utils.ts"; +import { parseHistoryDetailId, urlSimplify } from "../utils.ts"; export type FileExporterType = { type: "VS" | "COOP"; @@ -15,9 +15,11 @@ export type FileExporterType = { * Don't save url in exported file */ function replacer(key: string, value: unknown): unknown { - return ["url", "maskImageUrl", "overlayImageUrl"].includes(key) - ? undefined - : value; + if (!["url", "maskImageUrl", "overlayImageUrl"].includes(key)) { + return value; + } + + return typeof value === "string" ? urlSimplify(value) : undefined; } /** diff --git a/src/exporters/stat.ink.ts b/src/exporters/stat.ink.ts index 7c694c4..dd127b6 100644 --- a/src/exporters/stat.ink.ts +++ b/src/exporters/stat.ink.ts @@ -10,6 +10,7 @@ import { CoopInfo, Game, GameExporter, + Image, PlayerGear, StatInkAbility, StatInkCoopPlayer, @@ -456,13 +457,23 @@ export class StatInkExporter implements GameExporter { return result; } - async mapCoopWeapon({ name }: { name: string }): Promise { + isRandomWeapon(image: Image | null): boolean { + return (image?.url.includes( + "473fffb2442075078d8bb7125744905abdeae651b6a5b7453ae295582e45f7d1", + )) ?? false; + } + async mapCoopWeapon( + { name, image }: { name: string; image: Image | null }, + ): Promise { const weaponMap = await this.api.getWeapon(); const weapon = weaponMap.find((i) => Object.values(i.name).includes(name))?.key ?? KEY_DICT.get(name); if (!weapon) { + if (this.isRandomWeapon(image)) { + return null; + } throw new Error(`Weapon not found: ${name}`); } diff --git a/src/types.ts b/src/types.ts index 06faf21..9132548 100644 --- a/src/types.ts +++ b/src/types.ts @@ -209,7 +209,7 @@ export type CoopHistoryPlayerResult = { }; isMyself: boolean; }; - weapons: { name: string }[]; + weapons: { name: string; image: Image | null }[]; specialWeapon: null | { name: string; id: string; @@ -447,7 +447,7 @@ export type StatInkCoopPlayer = { splashtag_title: string | null; uniform?: "orange" | "green" | "yellow" | "pink" | "blue" | "black" | "white"; special?: string; - weapons: string[]; + weapons: (string | null)[]; golden_eggs: number; golden_assist: number; power_eggs: number; diff --git a/src/utils.ts b/src/utils.ts index e0babf0..c224cfe 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -163,3 +163,16 @@ export function b64Number(id: string): number { export function nonNullable(v: T | null | undefined): v is T { return v !== null && v !== undefined; } + +/** + * Only preserve the pathname of the URL + * @param url A url + */ +export function urlSimplify(url: string): { pathname: string } | string { + try { + const { pathname } = new URL(url); + return { pathname }; + } catch (_e) { + return url; + } +}