lint fix wip
This commit is contained in:
parent
f471fa3d31
commit
d2124e24aa
@ -67,7 +67,7 @@ function buildReviewSubmitHandler(params: {
|
||||
}): (e: React.FormEvent) => Promise<void> {
|
||||
return async (e: React.FormEvent): Promise<void> => {
|
||||
e.preventDefault()
|
||||
const pubkey = params.pubkey
|
||||
const {pubkey} = params
|
||||
if (!pubkey) {
|
||||
return
|
||||
}
|
||||
|
||||
@ -45,49 +45,60 @@ export async function createArticleInvoice(draft: ArticleDraft): Promise<AlbyInv
|
||||
* If encryptedContent is provided, it will be used instead of preview
|
||||
*/
|
||||
export async function createPreviewEvent(
|
||||
draft: ArticleDraft,
|
||||
invoice: AlbyInvoice,
|
||||
authorPubkey: string,
|
||||
authorPresentationId?: string,
|
||||
extraTags: string[][] = [],
|
||||
encryptedContent?: string,
|
||||
encryptedKey?: string
|
||||
params: {
|
||||
draft: ArticleDraft
|
||||
invoice: AlbyInvoice
|
||||
authorPubkey: string
|
||||
authorPresentationId?: string
|
||||
extraTags?: string[][]
|
||||
encryptedContent?: string
|
||||
encryptedKey?: string
|
||||
}
|
||||
): Promise<{
|
||||
kind: 1
|
||||
created_at: number
|
||||
tags: string[][]
|
||||
content: string
|
||||
}> {
|
||||
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<string[][]> {
|
||||
// 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
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -51,28 +51,30 @@ async function deriveSecret(articleId: string): Promise<string> {
|
||||
* 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<void> {
|
||||
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(),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user