featuredVideos.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
  2. import { displayTable } from '../../helpers/display'
  3. import { FeaturedVideoEntity, VideoEntity } from '@joystream/cd-schemas/types/entities'
  4. import chalk from 'chalk'
  5. export default class FeaturedVideosCommand extends ContentDirectoryCommandBase {
  6. static description = 'Show a list of currently featured videos.'
  7. async run() {
  8. const featuredEntries = await this.entitiesByClassAndOwner('FeaturedVideo')
  9. const featured = await Promise.all(
  10. featuredEntries
  11. .filter(([, entity]) => entity.supported_schemas.toArray().length) // Ignore FeaturedVideo entities without schema
  12. .map(([, entity]) => this.parseToEntityJson<FeaturedVideoEntity>(entity))
  13. )
  14. const videoIds: number[] = featured.map(({ video: videoId }) => videoId)
  15. const videos = await Promise.all(videoIds.map((videoId) => this.getAndParseKnownEntity<VideoEntity>(videoId)))
  16. if (videos.length) {
  17. displayTable(
  18. videos.map(({ title, channel }, index) => ({
  19. featuredVideoEntityId: featuredEntries[index][0].toNumber(),
  20. videoId: videoIds[index],
  21. channelId: channel,
  22. title,
  23. })),
  24. 3
  25. )
  26. this.log(`\nTIP: Use ${chalk.bold('content-directory:entity ID')} command to see more details about given video`)
  27. } else {
  28. this.log(`No videos have been featured yet! Set some with ${chalk.bold('media:setFeaturedVideos')}`)
  29. }
  30. }
  31. }