mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 07:52:24 +00:00
Merge pull request #2284 from PR0M3TH3AN/refactor-publish-video-4795921066793206834
🧹 Refactor publishVideo to use context object pattern
This commit is contained in:
3 files changed
+31
-76
No files matched your search
+6
-49
@@ -2370,34 +2370,14 @@ export class NostrClient {
|
||||
* @throws {Error} If not logged in or if the primary publish fails.
|
||||
*/
|
||||
async publishVideo(videoPayload, pubkey) {
|
||||
const {
|
||||
event,
|
||||
videoData,
|
||||
nip71Metadata,
|
||||
finalUrl,
|
||||
finalMagnet,
|
||||
finalThumbnail,
|
||||
finalDescription,
|
||||
finalTitle,
|
||||
mimeType,
|
||||
fileSha256,
|
||||
originalFileSha256,
|
||||
videoRootId,
|
||||
dTagValue,
|
||||
createdAt,
|
||||
contentObject,
|
||||
wantPrivate,
|
||||
normalizedPubkey,
|
||||
} = await prepareVideoPublishPayload(videoPayload, pubkey);
|
||||
const context = await prepareVideoPublishPayload(videoPayload, pubkey);
|
||||
|
||||
const userPubkeyLower = normalizedPubkey.toLowerCase();
|
||||
|
||||
devLogger.log("Publish event with series identifier:", videoRootId);
|
||||
devLogger.log("Event content:", event.content);
|
||||
devLogger.log("Publish event with series identifier:", context.videoRootId);
|
||||
devLogger.log("Event content:", context.event.content);
|
||||
|
||||
try {
|
||||
// 1. Publish the primary Video Note (Kind 30078)
|
||||
const { signedEvent } = await this.signAndPublishEvent(event, {
|
||||
const { signedEvent } = await this.signAndPublishEvent(context.event, {
|
||||
context: "video note",
|
||||
logName: "Video note",
|
||||
devLogLabel: "video note",
|
||||
@@ -2405,33 +2385,10 @@ export class NostrClient {
|
||||
});
|
||||
|
||||
// 2. Publish NIP-94 Mirror (Kind 1063) if a hosted URL is present.
|
||||
await handlePublishNip94(this, signedEvent, finalUrl, {
|
||||
videoData,
|
||||
videoPayload,
|
||||
finalMagnet,
|
||||
finalThumbnail,
|
||||
finalDescription,
|
||||
finalTitle,
|
||||
mimeType,
|
||||
fileSha256,
|
||||
originalFileSha256,
|
||||
pubkey: normalizedPubkey,
|
||||
createdAt,
|
||||
isPrivate: contentObject.isPrivate,
|
||||
});
|
||||
await handlePublishNip94(this, signedEvent, context);
|
||||
|
||||
// 3. Publish NIP-71 Metadata (Kind 22) if categories/tags were added.
|
||||
await handlePublishNip71(
|
||||
this,
|
||||
signedEvent,
|
||||
videoPayload,
|
||||
nip71Metadata,
|
||||
contentObject,
|
||||
wantPrivate,
|
||||
userPubkeyLower,
|
||||
videoRootId,
|
||||
dTagValue
|
||||
);
|
||||
await handlePublishNip71(this, signedEvent, context);
|
||||
|
||||
return signedEvent;
|
||||
} catch (err) {
|
||||
|
||||
@@ -194,7 +194,8 @@ export async function prepareVideoPublishPayload(videoPayload, pubkey, { timesta
|
||||
createdAt,
|
||||
contentObject,
|
||||
wantPrivate,
|
||||
normalizedPubkey
|
||||
normalizedPubkey,
|
||||
videoPayload
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+23
-26
@@ -12,10 +12,11 @@ import {
|
||||
*
|
||||
* @param {import("./client.js").NostrClient} client - The client instance.
|
||||
* @param {import("nostr-tools").Event} signedEvent - The signed video event.
|
||||
* @param {string} finalUrl - The final URL of the video.
|
||||
* @param {object} mirrorParams - Parameters for the mirror.
|
||||
* @param {object} context - The publish context returned by prepareVideoPublishPayload.
|
||||
*/
|
||||
export async function handlePublishNip94(client, signedEvent, finalUrl, mirrorParams) {
|
||||
export async function handlePublishNip94(client, signedEvent, context) {
|
||||
const { finalUrl } = context;
|
||||
|
||||
if (!finalUrl) {
|
||||
devLogger.log("Skipping NIP-94 mirror: no hosted URL provided.");
|
||||
return;
|
||||
@@ -31,10 +32,10 @@ export async function handlePublishNip94(client, signedEvent, finalUrl, mirrorPa
|
||||
mimeType,
|
||||
fileSha256,
|
||||
originalFileSha256,
|
||||
pubkey,
|
||||
normalizedPubkey,
|
||||
createdAt,
|
||||
isPrivate,
|
||||
} = mirrorParams;
|
||||
contentObject,
|
||||
} = context;
|
||||
|
||||
const mirrorOptions = await prepareVideoMirrorOptions({
|
||||
videoData,
|
||||
@@ -47,9 +48,9 @@ export async function handlePublishNip94(client, signedEvent, finalUrl, mirrorPa
|
||||
mimeType,
|
||||
fileSha256,
|
||||
originalFileSha256,
|
||||
pubkey,
|
||||
pubkey: normalizedPubkey,
|
||||
createdAt,
|
||||
isPrivate,
|
||||
isPrivate: contentObject.isPrivate,
|
||||
});
|
||||
|
||||
try {
|
||||
@@ -81,25 +82,21 @@ export async function handlePublishNip94(client, signedEvent, finalUrl, mirrorPa
|
||||
*
|
||||
* @param {import("./client.js").NostrClient} client - The client instance.
|
||||
* @param {import("nostr-tools").Event} signedEvent - The signed video event.
|
||||
* @param {object} videoPayload - The video payload.
|
||||
* @param {object} nip71Metadata - The NIP-71 metadata.
|
||||
* @param {object} contentObject - The content object.
|
||||
* @param {boolean} wantPrivate - Whether the video is private.
|
||||
* @param {string} userPubkeyLower - The lowercased user pubkey.
|
||||
* @param {string} videoRootId - The video root ID.
|
||||
* @param {string} dTagValue - The d tag value.
|
||||
* @param {object} context - The publish context returned by prepareVideoPublishPayload.
|
||||
*/
|
||||
export async function handlePublishNip71(
|
||||
client,
|
||||
signedEvent,
|
||||
videoPayload,
|
||||
nip71Metadata,
|
||||
contentObject,
|
||||
wantPrivate,
|
||||
userPubkeyLower,
|
||||
videoRootId,
|
||||
dTagValue,
|
||||
) {
|
||||
export async function handlePublishNip71(client, signedEvent, context) {
|
||||
const {
|
||||
videoPayload,
|
||||
nip71Metadata,
|
||||
contentObject,
|
||||
wantPrivate,
|
||||
normalizedPubkey,
|
||||
videoRootId,
|
||||
dTagValue,
|
||||
} = context;
|
||||
|
||||
const userPubkeyLower = normalizedPubkey.toLowerCase();
|
||||
|
||||
const nip71EditedFlag =
|
||||
videoPayload && typeof videoPayload === "object"
|
||||
? videoPayload.nip71Edited
|
||||
|
||||
Reference in new issue
Block a user