removeChannel.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
  2. import { Entity } from '@joystream/types/content-directory'
  3. import { createType } from '@joystream/types'
  4. import { ChannelEntity } from '@joystream/cd-schemas/types/entities'
  5. export default class RemoveChannelCommand extends ContentDirectoryCommandBase {
  6. static description = 'Removes a channel (required controller access).'
  7. static args = [
  8. {
  9. name: 'id',
  10. required: false,
  11. description: 'ID of the Channel entity',
  12. },
  13. ]
  14. async run() {
  15. const {
  16. args: { id },
  17. } = this.parse(RemoveChannelCommand)
  18. const account = await this.getRequiredSelectedAccount()
  19. const memberId = await this.getRequiredMemberId()
  20. const actor = createType('Actor', { Member: memberId })
  21. await this.requestAccountDecoding(account)
  22. let channelEntity: Entity, channelId: number
  23. if (id) {
  24. channelId = parseInt(id)
  25. channelEntity = await this.getEntity(channelId, 'Channel', memberId)
  26. } else {
  27. const [id, channel] = await this.promptForEntityEntry('Select a channel to remove', 'Channel', 'handle', memberId)
  28. channelId = id.toNumber()
  29. channelEntity = channel
  30. }
  31. const channel = await this.parseToEntityJson<ChannelEntity>(channelEntity)
  32. await this.requireConfirmation(`Are you sure you want to remove "${channel.handle}" channel?`)
  33. const api = this.getOriginalApi()
  34. this.log(`Removing Channel entity (ID: ${channelId})...`)
  35. await this.sendAndFollowTx(account, api.tx.contentDirectory.removeEntity(actor, channelId))
  36. }
  37. }