diff options
| author | Fuwn <[email protected]> | 2026-03-03 09:11:38 -0800 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-03-03 09:12:31 -0800 |
| commit | 0b3f4af0d8061fefcdeaba1352ea8176f34b1cbd (patch) | |
| tree | 5305af0876b70d0207df44febab27fb65236622d /src/lib/Tools/DumpProfile.svelte | |
| parent | refactor(effect): harden settings and media cache json parsing (diff) | |
| download | due.moe-0b3f4af0d8061fefcdeaba1352ea8176f34b1cbd.tar.xz due.moe-0b3f4af0d8061fefcdeaba1352ea8176f34b1cbd.zip | |
refactor(effect): migrate svelte json hotspots to typed decoders
Diffstat (limited to 'src/lib/Tools/DumpProfile.svelte')
| -rw-r--r-- | src/lib/Tools/DumpProfile.svelte | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/src/lib/Tools/DumpProfile.svelte b/src/lib/Tools/DumpProfile.svelte index a876f587..88605ffc 100644 --- a/src/lib/Tools/DumpProfile.svelte +++ b/src/lib/Tools/DumpProfile.svelte @@ -2,6 +2,7 @@ import Spacer from "$lib/Layout/Spacer.svelte"; import { dumpUser } from "$lib/Data/AniList/user"; import RateLimited from "$lib/Error/RateLimited.svelte"; +import { parseJsonStringOrDefault } from "$lib/Effect/json"; import Skeleton from "$lib/Loading/Skeleton.svelte"; import InputTemplate from "./InputTemplate.svelte"; import LZString from "lz-string"; @@ -9,19 +10,23 @@ import LZString from "lz-string"; let submission = ""; // Credit: @hoh -const decodeJSON = (about: string): JSON | null => { +const decodeJSON = (about: string): unknown | null => { const match = (about || "").match(/^\[\]\(json([A-Za-z0-9+/=]+)\)/); - if (match) - try { - return JSON.parse(atob(match[1])); - } catch { - try { - return JSON.parse(LZString.decompressFromBase64(match[1])); - } catch { - return null; - } - } + if (match) { + const directDecoded = parseJsonStringOrDefault<unknown | null>( + atob(match[1]), + null, + ); + + if (directDecoded !== null) return directDecoded; + + const decompressed = LZString.decompressFromBase64(match[1]); + + if (!decompressed) return null; + + return parseJsonStringOrDefault<unknown | null>(decompressed, null); + } return null; }; |