createVideoCategory.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 { VideoCategoryCreationParameters } from '@joystream/types/content'
  8. import { VideoCategoryInputSchema } from '../../json-schemas/ContentDirectory'
  9. import chalk from 'chalk'
  10. import { VideoCategoryMetadata } from '@joystream/metadata-protobuf'
  11. export default class CreateVideoCategoryCommand extends ContentDirectoryCommandBase {
  12. static description = 'Create video category inside content directory.'
  13. static flags = {
  14. context: ContentDirectoryCommandBase.categoriesContextFlag,
  15. input: flags.string({
  16. char: 'i',
  17. required: true,
  18. description: `Path to JSON file to use as input`,
  19. }),
  20. }
  21. async run() {
  22. const { context, input } = this.parse(CreateVideoCategoryCommand).flags
  23. const [actor, address] = context ? await this.getContentActor(context) : await this.getCategoryManagementActor()
  24. const videoCategoryInput = await getInputJson<VideoCategoryInputParameters>(input, VideoCategoryInputSchema)
  25. const meta = asValidatedMetadata(VideoCategoryMetadata, videoCategoryInput)
  26. const videoCategoryCreationParameters: CreateInterface<VideoCategoryCreationParameters> = {
  27. meta: metadataToBytes(VideoCategoryMetadata, meta),
  28. }
  29. this.jsonPrettyPrint(JSON.stringify(videoCategoryInput))
  30. await this.requireConfirmation('Do you confirm the provided input?', true)
  31. const result = await this.sendAndFollowNamedTx(
  32. await this.getDecodedPair(address),
  33. 'content',
  34. 'createVideoCategory',
  35. [actor, videoCategoryCreationParameters]
  36. )
  37. if (result) {
  38. const event = this.findEvent(result, 'content', 'VideoCategoryCreated')
  39. this.log(
  40. chalk.green(`VideoCategory with id ${chalk.cyanBright(event?.data[1].toString())} successfully created!`)
  41. )
  42. }
  43. }
  44. }