mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 16:02:26 +00:00
Merge pull request #240 from PR0M3TH3AN/codex/fix-fetchwatchhistory-json-parsing-issues
Handle legacy watch history payloads without JSON parse errors
This commit is contained in:
1 file changed
+32
-17
+32
-17
@@ -3720,23 +3720,38 @@ class NostrClient {
|
||||
const isIndexEvent = isIndexIdentifier(identifier);
|
||||
|
||||
if (isIndexEvent && typeof event.content === "string") {
|
||||
try {
|
||||
const parsed = JSON.parse(event.content);
|
||||
if (!snapshotId && typeof parsed?.snapshot === "string" && parsed.snapshot) {
|
||||
snapshotId = parsed.snapshot;
|
||||
}
|
||||
if (
|
||||
totalChunks === null &&
|
||||
Number.isFinite(Number.parseInt(parsed?.totalChunks, 10))
|
||||
) {
|
||||
totalChunks = Math.max(0, Math.floor(Number.parseInt(parsed.totalChunks, 10)));
|
||||
}
|
||||
} catch (error) {
|
||||
if (isDevMode) {
|
||||
console.warn(
|
||||
"[nostr] Failed to parse watch history index payload:",
|
||||
error
|
||||
);
|
||||
const trimmedContent = event.content.trim();
|
||||
if (trimmedContent) {
|
||||
const firstChar = trimmedContent[0];
|
||||
if (firstChar === "{" || firstChar === "[") {
|
||||
try {
|
||||
const parsed = JSON.parse(trimmedContent);
|
||||
if (
|
||||
!snapshotId &&
|
||||
typeof parsed?.snapshot === "string" &&
|
||||
parsed.snapshot
|
||||
) {
|
||||
snapshotId = parsed.snapshot;
|
||||
}
|
||||
if (
|
||||
totalChunks === null &&
|
||||
Number.isFinite(Number.parseInt(parsed?.totalChunks, 10))
|
||||
) {
|
||||
totalChunks = Math.max(
|
||||
0,
|
||||
Math.floor(Number.parseInt(parsed.totalChunks, 10))
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
if (isDevMode) {
|
||||
console.warn(
|
||||
"[nostr] Failed to parse watch history index payload:",
|
||||
error
|
||||
);
|
||||
}
|
||||
}
|
||||
} else if (!snapshotId) {
|
||||
snapshotId = trimmedContent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user