Support legacy Nostr video payloads

This commit is contained in:
thePR0M3TH3AN committed 2025-09-23 10:30:21 -04:00
1 parent a84f635539
commit 0569755901
4 files changed
+190 -97

No files matched your search

+33 -24
View File
@@ -1,5 +1,6 @@
// js/subscriptions.js
import { nostrClient } from "./nostr.js";
import { parseVideoEventPayload } from "./videoEventUtils.js";
/**
* Manages the user's subscription list (kind=30002) *privately*,
@@ -500,34 +501,42 @@ class SubscriptionsManager {
}
convertEventToVideo(evt) {
try {
const content = JSON.parse(evt.content || "{}");
const hasFields = !!(
content.title && (content.url || content.magnet)
);
const versionOk = content.version >= 2;
if (!versionOk || !hasFields) {
return { id: evt.id, invalid: true };
}
const { parsedContent, parseError, title, url, magnet, version } =
parseVideoEventPayload(evt);
if (!title) {
return {
id: evt.id,
pubkey: evt.pubkey,
created_at: evt.created_at,
videoRootId: content.videoRootId || evt.id,
version: content.version,
deleted: content.deleted === true,
isPrivate: content.isPrivate === true,
title: content.title || "",
url: content.url || "",
magnet: content.magnet || "",
thumbnail: content.thumbnail || "",
description: content.description || "",
tags: evt.tags || [],
invalid: false,
invalid: true,
reason: parseError ? "missing title (json parse error)" : "missing title",
};
} catch (err) {
return { id: evt.id, invalid: true };
}
if (!url && !magnet) {
return {
id: evt.id,
invalid: true,
reason: "missing playable source",
};
}
return {
id: evt.id,
pubkey: evt.pubkey,
created_at: evt.created_at,
videoRootId: parsedContent.videoRootId || evt.id,
version,
deleted: parsedContent.deleted === true,
isPrivate: parsedContent.isPrivate ?? false,
title,
url,
magnet,
thumbnail: parsedContent.thumbnail ?? "",
description: parsedContent.description ?? "",
mode: parsedContent.mode ?? "live",
tags: evt.tags || [],
invalid: false,
};
}
dedupeToNewestByRoot(videos) {