Skip to content

Commit

Permalink
Accept v2 lz-string encoded import payloads
Browse files Browse the repository at this point in the history
  • Loading branch information
cynicaloptimist committed Aug 22, 2024
1 parent 6002bff commit 664600f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
19 changes: 16 additions & 3 deletions client/TrackerViewModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as React from "react";
import * as SocketIOClient from "socket.io-client";

import * as compression from "json-url";
import * as lzString from "lz-string";
import { TagState } from "../common/CombatantState";
import { PersistentCharacter } from "../common/PersistentCharacter";
import { Settings } from "../common/Settings";
Expand Down Expand Up @@ -217,8 +218,9 @@ export class TrackerViewModel {
return;
}
const urlParams = new URLSearchParams(window.location.search);
const compressedStatBlockJSON = urlParams.get("s");
if (!compressedStatBlockJSON) {
const compressedStatBlockJSONv1 = urlParams.get("s");
const compressedStatBlockJSONv2 = urlParams.get("i");
if (!compressedStatBlockJSONv1 && !compressedStatBlockJSONv2) {
return;
}

Expand Down Expand Up @@ -266,7 +268,18 @@ export class TrackerViewModel {
return;
}

const json = await codec.decompress(compressedStatBlockJSON);
let json = "";
if (compressedStatBlockJSONv1) {
json = await codec.decompress(compressedStatBlockJSONv1);
}
if (compressedStatBlockJSONv2) {
json = lzString.decompressFromEncodedURIComponent(
compressedStatBlockJSONv2
);
}
if (!json.length) {
return;
}

const parsedStatBlock = ParseJSONOrDefault(json, {});
const statBlock: StatBlock = {
Expand Down
13 changes: 7 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
"knockout": "^3.5.1",
"localforage": "^1.10.0",
"lodash": "^4.17.21",
"lz-string": "^1.5.0",
"moment": "^2.29.4",
"mongodb": "^4.17.1",
"mongodb-memory-server": "^7.6.3",
Expand Down

0 comments on commit 664600f

Please sign in to comment.