feat: avoid duplicate with s3s' upload (#45)

main
spacemeowx2 2022-11-30 16:08:27 +08:00 committed by imspace
parent 52ef6863a9
commit 1547c65c83
3 changed files with 29 additions and 8 deletions

View File

@ -36,6 +36,7 @@ import {
b64Number, b64Number,
gameId, gameId,
nonNullable, nonNullable,
s3sCoopGameId,
s3siGameId, s3siGameId,
urlSimplify, urlSimplify,
} from "../utils.ts"; } from "../utils.ts";
@ -309,8 +310,12 @@ export class StatInkExporter implements GameExporter {
for (const id of list) { for (const id of list) {
const s3sId = await gameId(id); const s3sId = await gameId(id);
const s3siId = await s3siGameId(id); const s3siId = await s3siGameId(id);
const s3sCoopId = await s3sCoopGameId(id);
if (!uuid.includes(s3sId) && !uuid.includes(s3siId)) { if (
!uuid.includes(s3sId) && !uuid.includes(s3siId) &&
!uuid.includes(s3sCoopId)
) {
out.push(id); out.push(id);
} }
} }

View File

@ -1,6 +1,9 @@
import { base64 } from "../deps.ts"; import { base64 } from "../deps.ts";
import { assertEquals } from "../dev_deps.ts"; import { assertEquals } from "../dev_deps.ts";
import { gameId } from "./utils.ts"; import { gameId, s3sCoopGameId } from "./utils.ts";
const COOP_ID =
`CoopHistoryDetail-u-asdf:20220101T012345_12345678-abcd-1234-5678-0123456789ab`;
Deno.test("gameId", async () => { Deno.test("gameId", async () => {
assertEquals( assertEquals(
@ -13,11 +16,12 @@ Deno.test("gameId", async () => {
); );
assertEquals( assertEquals(
await gameId( await gameId(base64.encode(COOP_ID)),
base64.encode( "58329d62-737d-5b43-ac22-e35e6e44b077",
`"CoopHistoryDetail-u-asdf:20220101T012345_12345678-abcd-1234-5678-0123456789ab`,
),
),
"175af427-e83b-5bac-b02c-9539cc1fd684",
); );
}); });
Deno.test("s3sCoopGameId", async () => {
const S3S_COOP_UUID = "be4435b1-0ac5-577b-81bb-766585bec028";
assertEquals(await s3sCoopGameId(base64.encode(COOP_ID)), S3S_COOP_UUID);
});

View File

@ -115,6 +115,18 @@ export function s3siGameId(id: string) {
return uuid.v5.generate(S3SI_NAMESPACE, tsUuid); return uuid.v5.generate(S3SI_NAMESPACE, tsUuid);
} }
/**
* https://github.com/spacemeowx2/s3si.ts/issues/45
*
* @param id id of CoopHistoryDetail
* @returns uuid used in stat.ink
*/
export function s3sCoopGameId(id: string) {
const fullId = base64.decode(id);
const tsUuid = fullId.slice(fullId.length - 52, fullId.length);
return uuid.v5.generate(COOP_NAMESPACE, tsUuid);
}
/** /**
* @param id VsHistoryDetail id or CoopHistoryDetail id * @param id VsHistoryDetail id or CoopHistoryDetail id
*/ */