Publish content with an atomic price and visibility policy
This commit is contained in:
@@ -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()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user