From d2124e24aa90812f34c6ef2f61fd33f2edba33fd Mon Sep 17 00:00:00 2001 From: Nicolas Cantu Date: Fri, 9 Jan 2026 01:09:02 +0100 Subject: [PATCH] lint fix wip --- .../reviewForms/useReviewFormController.ts | 2 +- lib/articleInvoice.ts | 93 +++++++++++-------- lib/articleMutations.ts | 10 +- lib/articlePublisherPublish.ts | 19 +++- lib/articleStorage.ts | 38 ++++---- 5 files changed, 98 insertions(+), 64 deletions(-) diff --git a/components/reviewForms/useReviewFormController.ts b/components/reviewForms/useReviewFormController.ts index ed13b93..56e2d9d 100644 --- a/components/reviewForms/useReviewFormController.ts +++ b/components/reviewForms/useReviewFormController.ts @@ -67,7 +67,7 @@ function buildReviewSubmitHandler(params: { }): (e: React.FormEvent) => Promise { return async (e: React.FormEvent): Promise => { e.preventDefault() - const pubkey = params.pubkey + const {pubkey} = params if (!pubkey) { return } diff --git a/lib/articleInvoice.ts b/lib/articleInvoice.ts index 64bc1c7..ca9ece7 100644 --- a/lib/articleInvoice.ts +++ b/lib/articleInvoice.ts @@ -45,49 +45,60 @@ export async function createArticleInvoice(draft: ArticleDraft): Promise { - const tags = await buildPreviewTags(draft, invoice, authorPubkey, authorPresentationId, extraTags, encryptedKey) + const tags = await buildPreviewTags({ + draft: params.draft, + invoice: params.invoice, + authorPubkey: params.authorPubkey, + authorPresentationId: params.authorPresentationId, + extraTags: params.extraTags, + encryptedKey: params.encryptedKey, + }) return { kind: 1 as const, created_at: Math.floor(Date.now() / 1000), tags, - content: encryptedContent ?? draft.preview, + content: params.encryptedContent ?? params.draft.preview, } } async function buildPreviewTags( - draft: ArticleDraft, - invoice: AlbyInvoice, - authorPubkey: string, - _authorPresentationId?: string, - extraTags: string[][] = [], - encryptedKey?: string + params: { + draft: ArticleDraft + invoice: AlbyInvoice + authorPubkey: string + authorPresentationId?: string + extraTags?: string[][] + encryptedKey?: string + } ): Promise { // Map category to new system - const category = draft.category === 'science-fiction' ? 'sciencefiction' : draft.category === 'scientific-research' ? 'research' : 'sciencefiction' + const category = params.draft.category === 'science-fiction' ? 'sciencefiction' : params.draft.category === 'scientific-research' ? 'research' : 'sciencefiction' // Generate hash ID from publication data const hashId = await generatePublicationHashId({ - pubkey: authorPubkey, - title: draft.title, - preview: draft.preview, + pubkey: params.authorPubkey, + title: params.draft.title, + preview: params.draft.preview, category, - seriesId: draft.seriesId ?? undefined, - bannerUrl: draft.bannerUrl ?? undefined, - zapAmount: draft.zapAmount, + seriesId: params.draft.seriesId ?? undefined, + bannerUrl: params.draft.bannerUrl ?? undefined, + zapAmount: params.draft.zapAmount, }) // Build tags using new system @@ -99,40 +110,40 @@ async function buildPreviewTags( version: 0, // New object hidden: false, paywall: true, // Publications are paid - title: draft.title, - preview: draft.preview, - zapAmount: draft.zapAmount, - invoice: invoice.invoice, - paymentHash: invoice.paymentHash, - ...(draft.seriesId ? { seriesId: draft.seriesId } : {}), - ...(draft.bannerUrl ? { bannerUrl: draft.bannerUrl } : {}), - ...(encryptedKey ? { encryptedKey } : {}), + title: params.draft.title, + preview: params.draft.preview, + zapAmount: params.draft.zapAmount, + invoice: params.invoice.invoice, + paymentHash: params.invoice.paymentHash, + ...(params.draft.seriesId ? { seriesId: params.draft.seriesId } : {}), + ...(params.draft.bannerUrl ? { bannerUrl: params.draft.bannerUrl } : {}), + ...(params.encryptedKey ? { encryptedKey: params.encryptedKey } : {}), }) // Build JSON metadata const publicationJson = JSON.stringify({ type: 'publication', - pubkey: authorPubkey, - title: draft.title, - preview: draft.preview, + pubkey: params.authorPubkey, + title: params.draft.title, + preview: params.draft.preview, category, - seriesId: draft.seriesId, - bannerUrl: draft.bannerUrl, - zapAmount: draft.zapAmount, - invoice: invoice.invoice, - paymentHash: invoice.paymentHash, + seriesId: params.draft.seriesId, + bannerUrl: params.draft.bannerUrl, + zapAmount: params.draft.zapAmount, + invoice: params.invoice.invoice, + paymentHash: params.invoice.paymentHash, id: hashId, version: 0, index: 0, - ...(draft.pages && draft.pages.length > 0 ? { pages: draft.pages } : {}), + ...(params.draft.pages && params.draft.pages.length > 0 ? { pages: params.draft.pages } : {}), }) // Add JSON metadata as a tag newTags.push(['json', publicationJson]) // Add any extra tags (for backward compatibility) - if (extraTags.length > 0) { - newTags.push(...extraTags) + if (params.extraTags && params.extraTags.length > 0) { + newTags.push(...params.extraTags) } return newTags diff --git a/lib/articleMutations.ts b/lib/articleMutations.ts index 5d426d8..81ca92a 100644 --- a/lib/articleMutations.ts +++ b/lib/articleMutations.ts @@ -119,7 +119,13 @@ async function publishPreviewWithInvoice( } // Build event template - const previewEventTemplate = await createPreviewEvent(draft, invoice, authorPubkey, presentationId, extraTags) + const previewEventTemplate = await createPreviewEvent({ + draft, + invoice, + authorPubkey, + authorPresentationId: presentationId, + extraTags, + }) // Set private key in orchestrator const privateKey = nostrService.getPrivateKey() @@ -552,7 +558,7 @@ async function publishUpdate( if (!publishedEvent) { return updateFailure(originalArticleId, 'Failed to publish article update') } - await storePrivateContent(publishedEvent.id, draft.content, authorPubkey, invoice) + await storePrivateContent({ articleId: publishedEvent.id, content: draft.content, authorPubkey, invoice }) return { articleId: publishedEvent.id, previewEventId: publishedEvent.id, diff --git a/lib/articlePublisherPublish.ts b/lib/articlePublisherPublish.ts index 10bee44..fea59db 100644 --- a/lib/articlePublisherPublish.ts +++ b/lib/articlePublisherPublish.ts @@ -96,7 +96,15 @@ export async function publishPreview( const { article, hash, version, index } = await buildParsedArticleFromDraft(draft, invoice, authorPubkey) // Build event template - const previewEventTemplate = await createPreviewEvent(draft, invoice, authorPubkey, presentationId, extraTags, encryptedContent, encryptedKey) + const previewEventTemplate = await createPreviewEvent({ + draft, + invoice, + authorPubkey, + authorPresentationId: presentationId, + extraTags, + encryptedContent, + encryptedKey, + }) // Set private key in orchestrator const privateKey = nostrService.getPrivateKey() @@ -208,7 +216,14 @@ export async function encryptAndPublish( return buildFailure('Failed to publish article') } - await storePrivateContent(event.id, draft.content, authorPubkey, invoice, key, iv) + await storePrivateContent({ + articleId: event.id, + content: draft.content, + authorPubkey, + invoice, + decryptionKey: key, + decryptionIV: iv, + }) console.warn('Article published with encrypted content', { articleId: event.id, authorPubkey, diff --git a/lib/articleStorage.ts b/lib/articleStorage.ts index 3c522b9..5e85064 100644 --- a/lib/articleStorage.ts +++ b/lib/articleStorage.ts @@ -51,28 +51,30 @@ async function deriveSecret(articleId: string): Promise { * If decryptionKey and decryptionIV are provided, they will be stored for sending after payment */ export async function storePrivateContent( - articleId: string, - content: string, - authorPubkey: string, - invoice?: AlbyInvoice, - decryptionKey?: string, - decryptionIV?: string + params: { + articleId: string + content: string + authorPubkey: string + invoice?: AlbyInvoice + decryptionKey?: string + decryptionIV?: string + } ): Promise { try { - const key = `article_private_content_${articleId}` - const secret = await deriveSecret(articleId) + const key = `article_private_content_${params.articleId}` + const secret = await deriveSecret(params.articleId) const data: StoredArticleData = { - content, - authorPubkey, - articleId, - ...(decryptionKey ? { decryptionKey } : {}), - ...(decryptionIV ? { decryptionIV } : {}), - invoice: invoice + content: params.content, + authorPubkey: params.authorPubkey, + articleId: params.articleId, + ...(params.decryptionKey ? { decryptionKey: params.decryptionKey } : {}), + ...(params.decryptionIV ? { decryptionIV: params.decryptionIV } : {}), + invoice: params.invoice ? { - invoice: invoice.invoice, - paymentHash: invoice.paymentHash, - amount: invoice.amount, - expiresAt: invoice.expiresAt, + invoice: params.invoice.invoice, + paymentHash: params.invoice.paymentHash, + amount: params.invoice.amount, + expiresAt: params.invoice.expiresAt, } : null, createdAt: Date.now(),