Browse Source

CLI: improve videosByChannelId

iorveth 4 years ago
parent
commit
7e3b7a170b
2 changed files with 15 additions and 6 deletions
  1. 10 2
      cli/src/Api.ts
  2. 5 4
      cli/src/commands/content/videos.ts

+ 10 - 2
cli/src/Api.ts

@@ -521,8 +521,16 @@ export default class Api {
   }
 
   async videosByChannelId(channelId: number): Promise<[VideoId, Video][]> {
-    const videoEntries = await this.entriesByIds<VideoId, Video>(this._api.query.content.videoById)
-    return videoEntries.filter(([, video]) => video.in_channel.toNumber() === channelId)
+    const channel = await this.channelById(channelId)
+    if (channel) {
+      return Promise.all(
+        channel.videos.map(
+          async (video_id) => [video_id, await this._api.query.content.videoById<Video>(video_id)] as [VideoId, Video]
+        )
+      )
+    } else {
+      return []
+    }
   }
 
   async videoById(videoId: number): Promise<Video | null> {

+ 5 - 4
cli/src/commands/content/videos.ts

@@ -1,5 +1,5 @@
 import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
-// import chalk from 'chalk'
+import { Video, VideoId } from '@joystream/types/content'
 import { displayTable } from '../../helpers/display'
 
 export default class VideosCommand extends ContentDirectoryCommandBase {
@@ -16,10 +16,11 @@ export default class VideosCommand extends ContentDirectoryCommandBase {
   async run() {
     const { channelId } = this.parse(VideosCommand).args
 
-    let videos = await this.getApi().availableVideos()
-
+    let videos: [VideoId, Video][]
     if (channelId) {
-      videos = videos.filter(([, /* id */ video]) => video.in_channel.eqn(channelId))
+      videos = await this.getApi().videosByChannelId(channelId)
+    } else {
+      videos = await this.getApi().availableVideos()
     }
 
     if (videos.length > 0) {