Browse Source

createChannel / createVideo - Make assets not required

Leszek Wiesner 3 years ago
parent
commit
5c20cd87a4
2 changed files with 16 additions and 16 deletions
  1. 8 8
      cli/src/commands/content/createChannel.ts
  2. 8 8
      cli/src/commands/content/createVideo.ts

+ 8 - 8
cli/src/commands/content/createChannel.ts

@@ -6,7 +6,6 @@ import { CreateInterface } from '@joystream/types'
 import { ChannelCreationParameters } from '@joystream/types/content'
 import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
 import UploadCommandBase from '../../base/UploadCommandBase'
-import ExitCodes from '../../ExitCodes'
 
 export default class CreateChannelCommand extends UploadCommandBase {
   static description = 'Create channel inside content directory.'
@@ -34,15 +33,16 @@ export default class CreateChannelCommand extends UploadCommandBase {
 
     const meta = channelMetadataFromInput(channelInput)
     const { coverPhotoPath, avatarPhotoPath } = channelInput
-    if (!coverPhotoPath || !avatarPhotoPath) {
-      // TODO: Handle with json schema validation?
-      this.error('Invalid input! coverPhotoPath and avatarPhotoPath are required!', { exit: ExitCodes.InvalidInput })
-    }
-    const inputAssets = await this.prepareInputAssets([coverPhotoPath, avatarPhotoPath], input)
+    const assetsPaths = [coverPhotoPath, avatarPhotoPath].filter((v) => v !== undefined) as string[]
+    const inputAssets = await this.prepareInputAssets(assetsPaths, input)
     const assets = inputAssets.map(({ parameters }) => ({ Upload: parameters }))
     // Set assets indexes in the metadata
-    meta.setCoverPhoto(0)
-    meta.setAvatarPhoto(1)
+    if (coverPhotoPath) {
+      meta.setCoverPhoto(0)
+    }
+    if (avatarPhotoPath) {
+      meta.setAvatarPhoto(coverPhotoPath ? 1 : 0)
+    }
 
     const channelCreationParameters: CreateInterface<ChannelCreationParameters> = {
       assets,

+ 8 - 8
cli/src/commands/content/createVideo.ts

@@ -6,7 +6,6 @@ import { CreateInterface } from '@joystream/types'
 import { flags } from '@oclif/command'
 import { VideoCreationParameters } from '@joystream/types/content'
 import { MediaType, VideoMetadata } from '@joystream/content-metadata-protobuf'
-import ExitCodes from '../../ExitCodes'
 
 export default class CreateVideoCommand extends UploadCommandBase {
   static description = 'Create video under specific channel inside content directory.'
@@ -52,15 +51,16 @@ export default class CreateVideoCommand extends UploadCommandBase {
 
     // Assets
     const { videoPath, thumbnailPhotoPath } = videoCreationParametersInput
-    if (!videoPath || !thumbnailPhotoPath) {
-      // TODO: Handle with json schema validation?
-      this.error('Invalid input! videoPath and thumbnailVideoPath are required!', { exit: ExitCodes.InvalidInput })
-    }
-    const inputAssets = await this.prepareInputAssets([videoPath, thumbnailPhotoPath], input)
+    const assetsPaths = [videoPath, thumbnailPhotoPath].filter((a) => a !== undefined) as string[]
+    const inputAssets = await this.prepareInputAssets(assetsPaths, input)
     const assets = inputAssets.map(({ parameters }) => ({ Upload: parameters }))
     // Set assets indexes in the metadata
-    meta.setVideo(0)
-    meta.setThumbnailPhoto(1)
+    if (videoPath) {
+      meta.setVideo(0)
+    }
+    if (thumbnailPhotoPath) {
+      meta.setThumbnailPhoto(videoPath ? 1 : 0)
+    }
 
     // Try to get video file metadata
     const videoFileMetadata = await this.getVideoFileMetadata(inputAssets[0].path)