Publish content with an atomic price and visibility policy

This commit is contained in:
archipelago
2026-10-06 07:51:00 -04:00
parent 65b51b98f4
commit 19207282f9
9 changed files with 456 additions and 142 deletions
+4 -15
View File
@@ -467,27 +467,16 @@ async function addContentItem() {
addContentError.value = ''
try {
await rpcClient.call({
method: 'content.add',
method: 'content.publish',
params: {
filename: newContentFilename.value.trim(),
mime_type: newContentMimeType.value.trim() || 'application/octet-stream',
description: newContentDescription.value.trim(),
access: newContentAccess.value,
availability: 'all_peers',
...(newContentAccess.value === 'paid' ? { price_sats: newContentPrice.value || 100 } : {}),
},
})
if (newContentAccess.value !== 'free') {
const items = (await rpcClient.call<{ items: ContentItemData[] }>({ method: 'content.list-mine' })).items || []
const latest = items[items.length - 1]
if (latest) {
await rpcClient.call({
method: 'content.set-pricing',
params: {
id: latest.id,
access: newContentAccess.value,
...(newContentAccess.value === 'paid' ? { price_sats: newContentPrice.value || 100 } : {}),
},
})
}
}
showAddContentModal.value = false
newContentFilename.value = ''
newContentMimeType.value = 'application/octet-stream'
@@ -116,3 +116,17 @@ describe('Web5SharedContent', () => {
expect(wrapper.text()).not.toContain('Refreshing peer content...')
})
})
it('creates a paid Web5 share with its price in the first write', async () => {
vi.mocked(rpcClient.call).mockReset()
vi.mocked(rpcClient.call).mockResolvedValue({ items: [] })
const wrapper = mount(Web5SharedContent, { props: { showStagger: false, peers: [] } })
await flushPromises()
const vm = (wrapper.vm as any).$.setupState
vm.newContentFilename = 'film.mp4'; vm.newContentAccess = 'paid'; vm.newContentPrice = 1
await vm.addContentItem()
const writes = vi.mocked(rpcClient.call).mock.calls.map(([call]) => call).filter(call => ['content.publish','content.set-pricing'].includes(call.method))
expect(writes).toHaveLength(1)
expect(writes[0]).toMatchObject({ method: 'content.publish', params: { filename: 'film.mp4', access: 'paid', price_sats: 1, availability: 'all_peers' } })
wrapper.unmount()
})