feat: add user prefix to file exporter
parent
a5120fbfef
commit
1f16903aa1
|
|
@ -1,6 +1,7 @@
|
|||
import { BattleExporter, VsBattle } from "../types.ts";
|
||||
import { base64, path } from "../../deps.ts";
|
||||
import { path } from "../../deps.ts";
|
||||
import { NSOAPP_VERSION, S3SI_VERSION } from "../constant.ts";
|
||||
import { parseVsHistoryDetailId } from "../utils.ts";
|
||||
|
||||
export type FileExporterType = {
|
||||
type: "VS" | "COOP";
|
||||
|
|
@ -30,16 +31,9 @@ export class FileExporter implements BattleExporter<VsBattle> {
|
|||
constructor(private exportPath: string) {
|
||||
}
|
||||
getFilenameById(id: string) {
|
||||
const fullId = base64.decode(id);
|
||||
const ts = new TextDecoder().decode(
|
||||
fullId.slice(fullId.length - 52, fullId.length - 37),
|
||||
);
|
||||
const { uid, timestamp } = parseVsHistoryDetailId(id);
|
||||
|
||||
if (!/\d{8}T\d{6}/.test(ts)) {
|
||||
throw new Error("Invalid battle ID");
|
||||
}
|
||||
|
||||
return `${ts}Z.json`;
|
||||
return `${uid}_${timestamp}Z.json`;
|
||||
}
|
||||
async exportBattle(battle: VsBattle) {
|
||||
await Deno.mkdir(this.exportPath, { recursive: true });
|
||||
|
|
|
|||
23
src/utils.ts
23
src/utils.ts
|
|
@ -82,6 +82,11 @@ export async function showError(p: Promise<void>) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id id of VeVsHistoryDetail
|
||||
* @param namespace uuid namespace
|
||||
* @returns
|
||||
*/
|
||||
export function battleId(
|
||||
id: string,
|
||||
namespace = S3SI_NAMESPACE,
|
||||
|
|
@ -90,3 +95,21 @@ export function battleId(
|
|||
const tsUuid = fullId.slice(fullId.length - 52, fullId.length);
|
||||
return uuid.v5.generate(namespace, tsUuid);
|
||||
}
|
||||
|
||||
export function parseVsHistoryDetailId(id: string) {
|
||||
const plainText = new TextDecoder().decode(base64.decode(id));
|
||||
|
||||
const re = /VsHistoryDetail-([a-z0-9-]+):(\w+):(\d{8}T\d{6})_([0-9a-f-]{36})/;
|
||||
if (!re.test(plainText)) {
|
||||
throw new Error(`Invalid battle ID: ${plainText}`);
|
||||
}
|
||||
|
||||
const [, uid, listType, timestamp, uuid] = plainText.match(re)!;
|
||||
|
||||
return {
|
||||
uid,
|
||||
listType,
|
||||
timestamp,
|
||||
uuid,
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue