reuploadAssets.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import UploadCommandBase from '../../base/UploadCommandBase'
  2. import { getInputJson } from '../../helpers/InputOutput'
  3. import AssetsSchema from '../../schemas/json/Assets.schema.json'
  4. import { Assets as AssetsInput } from '../../schemas/typings/Assets.schema'
  5. import { flags } from '@oclif/command'
  6. import BN from 'bn.js'
  7. export default class ReuploadVideoAssetsCommand extends UploadCommandBase {
  8. static description = 'Allows reuploading assets that were not successfully uploaded during channel/video creation'
  9. static flags = {
  10. input: flags.string({
  11. char: 'i',
  12. required: true,
  13. description: 'Path to JSON file containing array of assets to reupload (contentIds and paths)',
  14. }),
  15. }
  16. async run(): Promise<void> {
  17. const { input } = this.parse(ReuploadVideoAssetsCommand).flags
  18. // Get context
  19. const [memberId, membership] = await this.getRequiredMemberContext()
  20. // Get input from file
  21. const inputData = await getInputJson<AssetsInput>(input, AssetsSchema)
  22. const { bagId } = inputData
  23. const inputAssets = inputData.assets.map(({ objectId, path }) => ({
  24. dataObjectId: new BN(objectId),
  25. path,
  26. }))
  27. // Upload assets
  28. await this.uploadAssets(
  29. await this.getDecodedPair(membership.controller_account),
  30. memberId.toNumber(),
  31. bagId,
  32. inputAssets,
  33. input,
  34. ''
  35. )
  36. }
  37. }