fix: random weapon (#29)

* fix: allow weapon to be random

* feat: save pathname of image in file exporter

* fix: allow random weapon

* build: update chagnelog
main
imspace 2022-11-26 00:31:21 +08:00 committed by GitHub
parent 0e4f080054
commit 54d53fc488
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 8 deletions

View File

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

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

View File

@ -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;
}
/**

View File

@ -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<string> {
isRandomWeapon(image: Image | null): boolean {
return (image?.url.includes(
"473fffb2442075078d8bb7125744905abdeae651b6a5b7453ae295582e45f7d1",
)) ?? false;
}
async mapCoopWeapon(
{ name, image }: { name: string; image: Image | null },
): Promise<string | null> {
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}`);
}

View File

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

View File

@ -163,3 +163,16 @@ export function b64Number(id: string): number {
export function nonNullable<T>(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;
}
}