lint fix wip
This commit is contained in:
parent
f471fa3d31
commit
d2124e24aa
@ -67,7 +67,7 @@ function buildReviewSubmitHandler(params: {
|
|||||||
}): (e: React.FormEvent) => Promise<void> {
|
}): (e: React.FormEvent) => Promise<void> {
|
||||||
return async (e: React.FormEvent): Promise<void> => {
|
return async (e: React.FormEvent): Promise<void> => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
const pubkey = params.pubkey
|
const {pubkey} = params
|
||||||
if (!pubkey) {
|
if (!pubkey) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,49 +45,60 @@ export async function createArticleInvoice(draft: ArticleDraft): Promise<AlbyInv
|
|||||||
* If encryptedContent is provided, it will be used instead of preview
|
* If encryptedContent is provided, it will be used instead of preview
|
||||||
*/
|
*/
|
||||||
export async function createPreviewEvent(
|
export async function createPreviewEvent(
|
||||||
draft: ArticleDraft,
|
params: {
|
||||||
invoice: AlbyInvoice,
|
draft: ArticleDraft
|
||||||
authorPubkey: string,
|
invoice: AlbyInvoice
|
||||||
authorPresentationId?: string,
|
authorPubkey: string
|
||||||
extraTags: string[][] = [],
|
authorPresentationId?: string
|
||||||
encryptedContent?: string,
|
extraTags?: string[][]
|
||||||
|
encryptedContent?: string
|
||||||
encryptedKey?: string
|
encryptedKey?: string
|
||||||
|
}
|
||||||
): Promise<{
|
): Promise<{
|
||||||
kind: 1
|
kind: 1
|
||||||
created_at: number
|
created_at: number
|
||||||
tags: string[][]
|
tags: string[][]
|
||||||
content: 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 {
|
return {
|
||||||
kind: 1 as const,
|
kind: 1 as const,
|
||||||
created_at: Math.floor(Date.now() / 1000),
|
created_at: Math.floor(Date.now() / 1000),
|
||||||
tags,
|
tags,
|
||||||
content: encryptedContent ?? draft.preview,
|
content: params.encryptedContent ?? params.draft.preview,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function buildPreviewTags(
|
async function buildPreviewTags(
|
||||||
draft: ArticleDraft,
|
params: {
|
||||||
invoice: AlbyInvoice,
|
draft: ArticleDraft
|
||||||
authorPubkey: string,
|
invoice: AlbyInvoice
|
||||||
_authorPresentationId?: string,
|
authorPubkey: string
|
||||||
extraTags: string[][] = [],
|
authorPresentationId?: string
|
||||||
|
extraTags?: string[][]
|
||||||
encryptedKey?: string
|
encryptedKey?: string
|
||||||
|
}
|
||||||
): Promise<string[][]> {
|
): Promise<string[][]> {
|
||||||
// Map category to new system
|
// 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
|
// Generate hash ID from publication data
|
||||||
const hashId = await generatePublicationHashId({
|
const hashId = await generatePublicationHashId({
|
||||||
pubkey: authorPubkey,
|
pubkey: params.authorPubkey,
|
||||||
title: draft.title,
|
title: params.draft.title,
|
||||||
preview: draft.preview,
|
preview: params.draft.preview,
|
||||||
category,
|
category,
|
||||||
seriesId: draft.seriesId ?? undefined,
|
seriesId: params.draft.seriesId ?? undefined,
|
||||||
bannerUrl: draft.bannerUrl ?? undefined,
|
bannerUrl: params.draft.bannerUrl ?? undefined,
|
||||||
zapAmount: draft.zapAmount,
|
zapAmount: params.draft.zapAmount,
|
||||||
})
|
})
|
||||||
|
|
||||||
// Build tags using new system
|
// Build tags using new system
|
||||||
@ -99,40 +110,40 @@ async function buildPreviewTags(
|
|||||||
version: 0, // New object
|
version: 0, // New object
|
||||||
hidden: false,
|
hidden: false,
|
||||||
paywall: true, // Publications are paid
|
paywall: true, // Publications are paid
|
||||||
title: draft.title,
|
title: params.draft.title,
|
||||||
preview: draft.preview,
|
preview: params.draft.preview,
|
||||||
zapAmount: draft.zapAmount,
|
zapAmount: params.draft.zapAmount,
|
||||||
invoice: invoice.invoice,
|
invoice: params.invoice.invoice,
|
||||||
paymentHash: invoice.paymentHash,
|
paymentHash: params.invoice.paymentHash,
|
||||||
...(draft.seriesId ? { seriesId: draft.seriesId } : {}),
|
...(params.draft.seriesId ? { seriesId: params.draft.seriesId } : {}),
|
||||||
...(draft.bannerUrl ? { bannerUrl: draft.bannerUrl } : {}),
|
...(params.draft.bannerUrl ? { bannerUrl: params.draft.bannerUrl } : {}),
|
||||||
...(encryptedKey ? { encryptedKey } : {}),
|
...(params.encryptedKey ? { encryptedKey: params.encryptedKey } : {}),
|
||||||
})
|
})
|
||||||
|
|
||||||
// Build JSON metadata
|
// Build JSON metadata
|
||||||
const publicationJson = JSON.stringify({
|
const publicationJson = JSON.stringify({
|
||||||
type: 'publication',
|
type: 'publication',
|
||||||
pubkey: authorPubkey,
|
pubkey: params.authorPubkey,
|
||||||
title: draft.title,
|
title: params.draft.title,
|
||||||
preview: draft.preview,
|
preview: params.draft.preview,
|
||||||
category,
|
category,
|
||||||
seriesId: draft.seriesId,
|
seriesId: params.draft.seriesId,
|
||||||
bannerUrl: draft.bannerUrl,
|
bannerUrl: params.draft.bannerUrl,
|
||||||
zapAmount: draft.zapAmount,
|
zapAmount: params.draft.zapAmount,
|
||||||
invoice: invoice.invoice,
|
invoice: params.invoice.invoice,
|
||||||
paymentHash: invoice.paymentHash,
|
paymentHash: params.invoice.paymentHash,
|
||||||
id: hashId,
|
id: hashId,
|
||||||
version: 0,
|
version: 0,
|
||||||
index: 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
|
// Add JSON metadata as a tag
|
||||||
newTags.push(['json', publicationJson])
|
newTags.push(['json', publicationJson])
|
||||||
|
|
||||||
// Add any extra tags (for backward compatibility)
|
// Add any extra tags (for backward compatibility)
|
||||||
if (extraTags.length > 0) {
|
if (params.extraTags && params.extraTags.length > 0) {
|
||||||
newTags.push(...extraTags)
|
newTags.push(...params.extraTags)
|
||||||
}
|
}
|
||||||
|
|
||||||
return newTags
|
return newTags
|
||||||
|
|||||||
@ -119,7 +119,13 @@ async function publishPreviewWithInvoice(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Build event template
|
// 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
|
// Set private key in orchestrator
|
||||||
const privateKey = nostrService.getPrivateKey()
|
const privateKey = nostrService.getPrivateKey()
|
||||||
@ -552,7 +558,7 @@ async function publishUpdate(
|
|||||||
if (!publishedEvent) {
|
if (!publishedEvent) {
|
||||||
return updateFailure(originalArticleId, 'Failed to publish article update')
|
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 {
|
return {
|
||||||
articleId: publishedEvent.id,
|
articleId: publishedEvent.id,
|
||||||
previewEventId: publishedEvent.id,
|
previewEventId: publishedEvent.id,
|
||||||
|
|||||||
@ -96,7 +96,15 @@ export async function publishPreview(
|
|||||||
const { article, hash, version, index } = await buildParsedArticleFromDraft(draft, invoice, authorPubkey)
|
const { article, hash, version, index } = await buildParsedArticleFromDraft(draft, invoice, authorPubkey)
|
||||||
|
|
||||||
// Build event template
|
// 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
|
// Set private key in orchestrator
|
||||||
const privateKey = nostrService.getPrivateKey()
|
const privateKey = nostrService.getPrivateKey()
|
||||||
@ -208,7 +216,14 @@ export async function encryptAndPublish(
|
|||||||
return buildFailure('Failed to publish article')
|
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', {
|
console.warn('Article published with encrypted content', {
|
||||||
articleId: event.id,
|
articleId: event.id,
|
||||||
authorPubkey,
|
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
|
* If decryptionKey and decryptionIV are provided, they will be stored for sending after payment
|
||||||
*/
|
*/
|
||||||
export async function storePrivateContent(
|
export async function storePrivateContent(
|
||||||
articleId: string,
|
params: {
|
||||||
content: string,
|
articleId: string
|
||||||
authorPubkey: string,
|
content: string
|
||||||
invoice?: AlbyInvoice,
|
authorPubkey: string
|
||||||
decryptionKey?: string,
|
invoice?: AlbyInvoice
|
||||||
|
decryptionKey?: string
|
||||||
decryptionIV?: string
|
decryptionIV?: string
|
||||||
|
}
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const key = `article_private_content_${articleId}`
|
const key = `article_private_content_${params.articleId}`
|
||||||
const secret = await deriveSecret(articleId)
|
const secret = await deriveSecret(params.articleId)
|
||||||
const data: StoredArticleData = {
|
const data: StoredArticleData = {
|
||||||
content,
|
content: params.content,
|
||||||
authorPubkey,
|
authorPubkey: params.authorPubkey,
|
||||||
articleId,
|
articleId: params.articleId,
|
||||||
...(decryptionKey ? { decryptionKey } : {}),
|
...(params.decryptionKey ? { decryptionKey: params.decryptionKey } : {}),
|
||||||
...(decryptionIV ? { decryptionIV } : {}),
|
...(params.decryptionIV ? { decryptionIV: params.decryptionIV } : {}),
|
||||||
invoice: invoice
|
invoice: params.invoice
|
||||||
? {
|
? {
|
||||||
invoice: invoice.invoice,
|
invoice: params.invoice.invoice,
|
||||||
paymentHash: invoice.paymentHash,
|
paymentHash: params.invoice.paymentHash,
|
||||||
amount: invoice.amount,
|
amount: params.invoice.amount,
|
||||||
expiresAt: invoice.expiresAt,
|
expiresAt: params.invoice.expiresAt,
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
createdAt: Date.now(),
|
createdAt: Date.now(),
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user