updateVideoCategory.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
  2. import { getInputJson } from '../../helpers/InputOutput'
  3. import { VideoCategoryInputParameters } from '../../Types'
  4. import { asValidatedMetadata, metadataToBytes } from '../../helpers/serialization'
  5. import { flags } from '@oclif/command'
  6. import { CreateInterface } from '@joystream/types'
  7. import { VideoCategoryUpdateParameters } from '@joystream/types/content'
  8. import { VideoCategoryInputSchema } from '../../schemas/ContentDirectory'
  9. import { VideoCategoryMetadata } from '@joystream/metadata-protobuf'
  10. export default class UpdateVideoCategoryCommand extends ContentDirectoryCommandBase {
  11. static description = 'Update video category inside content directory.'
  12. static flags = {
  13. context: ContentDirectoryCommandBase.categoriesContextFlag,
  14. input: flags.string({
  15. char: 'i',
  16. required: true,
  17. description: `Path to JSON file to use as input`,
  18. }),
  19. ...ContentDirectoryCommandBase.flags,
  20. }
  21. static args = [
  22. {
  23. name: 'videoCategoryId',
  24. required: true,
  25. description: 'ID of the Video Category',
  26. },
  27. ]
  28. async run(): Promise<void> {
  29. const { context, input } = this.parse(UpdateVideoCategoryCommand).flags
  30. const { videoCategoryId } = this.parse(UpdateVideoCategoryCommand).args
  31. const [actor, address] = context ? await this.getContentActor(context) : await this.getCategoryManagementActor()
  32. const videoCategoryInput = await getInputJson<VideoCategoryInputParameters>(input, VideoCategoryInputSchema)
  33. const meta = asValidatedMetadata(VideoCategoryMetadata, videoCategoryInput)
  34. const videoCategoryUpdateParameters: CreateInterface<VideoCategoryUpdateParameters> = {
  35. new_meta: metadataToBytes(VideoCategoryMetadata, meta),
  36. }
  37. this.jsonPrettyPrint(JSON.stringify(videoCategoryInput))
  38. await this.requireConfirmation('Do you confirm the provided input?', true)
  39. await this.sendAndFollowNamedTx(await this.getDecodedPair(address), 'content', 'updateVideoCategory', [
  40. actor,
  41. videoCategoryId,
  42. videoCategoryUpdateParameters,
  43. ])
  44. }
  45. }