removeVideo.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
  2. import { Entity } from '@joystream/types/content-directory'
  3. import { VideoEntity } from '@joystream/cd-schemas/types/entities'
  4. import { createType } from '@joystream/types'
  5. export default class RemoveVideoCommand extends ContentDirectoryCommandBase {
  6. static description = 'Remove given Video entity and associated entities (VideoMedia, License) from content directory.'
  7. static args = [
  8. {
  9. name: 'id',
  10. required: false,
  11. description: 'ID of the Video entity',
  12. },
  13. ]
  14. async run() {
  15. const {
  16. args: { id },
  17. } = this.parse(RemoveVideoCommand)
  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 videoEntity: Entity, videoId: number
  23. if (id) {
  24. videoId = parseInt(id)
  25. videoEntity = await this.getEntity(videoId, 'Video', memberId)
  26. } else {
  27. const [id, video] = await this.promptForEntityEntry('Select a video to remove', 'Video', 'title', memberId)
  28. videoId = id.toNumber()
  29. videoEntity = video
  30. }
  31. const video = await this.parseToEntityJson<VideoEntity>(videoEntity)
  32. await this.requireConfirmation(`Are you sure you want to remove the "${video.title}" video?`)
  33. const api = this.getOriginalApi()
  34. this.log(`Removing the Video entity (ID: ${videoId})...`)
  35. await this.sendAndFollowTx(account, api.tx.contentDirectory.removeEntity(actor, videoId))
  36. this.log(`Removing the VideoMedia entity (ID: ${video.media})...`)
  37. await this.sendAndFollowTx(account, api.tx.contentDirectory.removeEntity(actor, video.media))
  38. this.log(`Removing the License entity (ID: ${video.license})...`)
  39. await this.sendAndFollowTx(account, api.tx.contentDirectory.removeEntity(actor, video.license))
  40. }
  41. }