From 58fc143c66c73c793f4ee8ae34e51e434bd13f31 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 11 Feb 2026 04:13:50 +0000 Subject: [PATCH] Refactor editVideo into validation, prep, and publish steps Split the long `editVideo` method in `js/nostr/client.js` into three distinct parts: 1. `_validateEditPrerequisites`: Handles input validation and state checks. 2. `prepareVideoEditPayload`: Existing helper for payload construction. 3. `_signAndPublishEdit`: Handles signing and network operations. This improves maintainability and readability by separating concerns. Co-authored-by: PR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> --- js/nostr/client.js | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/js/nostr/client.js b/js/nostr/client.js index f84ebe5c..06762b89 100644 --- a/js/nostr/client.js +++ b/js/nostr/client.js @@ -2458,6 +2458,26 @@ export class NostrClient { * @throws {Error} If the user is not the owner or if the original event is too old. */ async editVideo(originalEventStub, updatedData, userPubkey) { + const { baseEvent, userPubkeyLower } = await this._validateEditPrerequisites( + originalEventStub, + userPubkey, + ); + + const context = prepareVideoEditPayload({ + baseEvent, + originalEventStub, + updatedData, + userPubkey, + resolveEventDTag: (evt, stub) => this.resolveEventDTag(evt, stub), + }); + + devLogger.log("Creating edited event with root ID:", context.videoRootId); + devLogger.log("Event content:", context.event.content); + + return this._signAndPublishEdit(context, userPubkeyLower); + } + + async _validateEditPrerequisites(originalEventStub, userPubkey) { if (!userPubkey) { throw new Error("Not logged in to edit."); } @@ -2475,9 +2495,7 @@ export class NostrClient { // Check that the original event is version 2 or higher if (baseEvent.version < 2) { - throw new Error( - "This video is not in the supported version for editing." - ); + throw new Error("This video is not in the supported version for editing."); } // Ownership check (compare lowercase hex public keys) @@ -2488,17 +2506,10 @@ export class NostrClient { throw new Error("You do not own this video (pubkey mismatch)."); } - const context = prepareVideoEditPayload({ - baseEvent, - originalEventStub, - updatedData, - userPubkey, - resolveEventDTag: (evt, stub) => this.resolveEventDTag(evt, stub), - }); - - devLogger.log("Creating edited event with root ID:", context.videoRootId); - devLogger.log("Event content:", context.event.content); + return { baseEvent, userPubkeyLower }; + } + async _signAndPublishEdit(context, userPubkeyLower) { await this.ensureActiveSignerForPubkey(userPubkeyLower); try {