فهرست منبع

CLI: upgrade createChannel command

iorveth 4 سال پیش
والد
کامیت
33401a13db

+ 42 - 0
cli/src/commands/content/addCuratorToGroup.ts

@@ -0,0 +1,42 @@
+import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
+import chalk from 'chalk'
+
+export default class AddCuratorToGroupCommand extends ContentDirectoryCommandBase {
+  static description = 'Add Curator to existing Curator Group.'
+  static args = [
+    {
+      name: 'groupId',
+      required: false,
+      description: 'ID of the Curator Group',
+    },
+    {
+      name: 'curatorId',
+      required: false,
+      description: 'ID of the curator',
+    },
+  ]
+
+  async run() {
+    const account = await this.getRequiredSelectedAccount()
+    await this.requireLead()
+
+    let { groupId, curatorId } = this.parse(AddCuratorToGroupCommand).args
+
+    if (groupId === undefined) {
+      groupId = await this.promptForCuratorGroup()
+    } else {
+      await this.getCuratorGroup(groupId)
+    }
+
+    if (curatorId === undefined) {
+      curatorId = await this.promptForCurator()
+    } else {
+      await this.getCurator(curatorId)
+    }
+
+    await this.requestAccountDecoding(account)
+    await this.sendAndFollowNamedTx(account, 'contentDirectory', 'addCuratorToGroup', [groupId, curatorId])
+
+    console.log(chalk.green(`Curator ${chalk.white(curatorId)} succesfully added to group ${chalk.white(groupId)}!`))
+  }
+}

+ 41 - 0
cli/src/commands/content/channel.ts

@@ -0,0 +1,41 @@
+import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
+import { displayCollapsedRow, displayHeader } from '../../helpers/display'
+
+export default class ChannelCommand extends ContentDirectoryCommandBase {
+  static description = 'Show Channel details by id.'
+  static args = [
+    {
+      name: 'channelId',
+      required: true,
+      description: 'Name or ID of the Channel',
+    },
+  ]
+
+  async run() {
+    const { channelId } = this.parse(ChannelCommand).args
+    const [id, aChannel] = await this.channelEntryById(channelId)
+
+    displayCollapsedRow({
+      'ID': id.toString(),
+      'Owner': JSON.stringify(aChannel.owner.toJSON()),
+      'IsCensored': aChannel.is_censored.toString(),
+      'RewardAccount': aChannel.reward_account? aChannel.reward_account.toString() : 'NONE'
+    })
+
+    displayHeader(`Media`)
+
+    displayCollapsedRow({
+      'NumberOfVideos': aChannel.videos.length,
+      'NumberOfPlaylists': aChannel.playlists.length,
+      'NumberOfSeries': aChannel.series.length,
+    })
+
+    displayHeader(`MediaData`)
+
+    displayCollapsedRow({
+      'Videos': JSON.stringify(aChannel.videos.toJSON()),
+      'Playlists': JSON.stringify(aChannel.playlists.toJSON()),
+      'Series': JSON.stringify(aChannel.series.toJSON()),
+    })
+  }
+}

+ 21 - 0
cli/src/commands/content/channels.ts

@@ -0,0 +1,21 @@
+import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
+// import chalk from 'chalk'
+import { displayTable } from '../../helpers/display'
+
+export default class ChannelsCommand extends ContentDirectoryCommandBase {
+  static description = 'List existing content directory channels.'
+
+  async run() {
+    const channels = await this.getApi().availableChannels()
+
+    displayTable(
+      channels.map(([id, c]) => ({
+        'ID': id.toString(),
+        'Owner': JSON.stringify(c.owner.toJSON()),
+        'IsCensored': c.is_censored.toString(),
+        'RewardAccount': c.reward_account? c.reward_account.toString() : 'NONE'
+      })),
+      3
+    )
+  }
+}

+ 10 - 3
cli/src/commands/content/createChannel.ts

@@ -1,15 +1,21 @@
 import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
 import { IOFlags, getInputJson } from '../../helpers/InputOutput'
-import {ChannelCreationParameters, NewAsset} from '@joystream/types/content'
+import { NewAsset} from '@joystream/types/content'
 import {ChannelMetadata} from '@joystream/content-metadata-protobuf'
 import { Vec, Option} from '@polkadot/types';
 import AccountId from '@polkadot/types/generic/AccountId';
 import { Bytes } from '@polkadot/types/primitive';
 
 type ChannelCreationParametersInput = {
-  assets: import("@polkadot/types/types").Constructor<Vec<NewAsset>>,
+  assets: Vec<NewAsset>,
   meta: ChannelMetadata.AsObject,
-  reward_account: import("@polkadot/types/types").Constructor<Option<AccountId>>,
+  reward_account: Option<AccountId>,
+}
+
+type ChannelCreationParameters = {
+  assets: Vec<NewAsset>,
+  meta: Bytes,
+  reward_account: Option<AccountId>,
 }
 
 export default class CreateChannelCommand extends ContentDirectoryCommandBase {
@@ -43,6 +49,7 @@ export default class CreateChannelCommand extends ContentDirectoryCommandBase {
       channelMetadata.setCategory(channelCreationParametersInput.meta.category!)
 
       let channelCreationParameters: ChannelCreationParameters = {
+        assets: channelCreationParametersInput.assets,
         meta: channelMetadata.serializeBinary() as Bytes,
         reward_account: channelCreationParametersInput.reward_account,
       }

+ 18 - 0
cli/src/commands/content/createCuratorGroup.ts

@@ -0,0 +1,18 @@
+import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
+import chalk from 'chalk'
+
+export default class AddCuratorGroupCommand extends ContentDirectoryCommandBase {
+  static description = 'Create new Curator Group.'
+  static aliases = ['addCuratorGroup']
+
+  async run() {
+    const account = await this.getRequiredSelectedAccount()
+    await this.requireLead()
+
+    await this.requestAccountDecoding(account)
+    await this.buildAndSendExtrinsic(account, 'contentDirectory', 'addCuratorGroup')
+
+    const newGroupId = (await this.getApi().nextCuratorGroupId()) - 1
+    console.log(chalk.green(`New group succesfully created! (ID: ${chalk.white(newGroupId)})`))
+  }
+}

+ 34 - 0
cli/src/commands/content/curatorGroup.ts

@@ -0,0 +1,34 @@
+import { WorkingGroups } from '../../Types'
+import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
+import chalk from 'chalk'
+import { displayCollapsedRow, displayHeader } from '../../helpers/display'
+
+export default class CuratorGroupCommand extends ContentDirectoryCommandBase {
+  static description = 'Show Curator Group details by ID.'
+  static args = [
+    {
+      name: 'id',
+      required: true,
+      description: 'ID of the Curator Group',
+    },
+  ]
+
+  async run() {
+    const { id } = this.parse(CuratorGroupCommand).args
+    const group = await this.getCuratorGroup(id)
+    const members = (await this.getApi().groupMembers(WorkingGroups.Curators)).filter((curator) =>
+      group.curators.toArray().some((groupCurator) => groupCurator.eq(curator.workerId))
+    )
+
+    displayCollapsedRow({
+      'ID': id,
+      'Status': group.active.valueOf() ? 'Active' : 'Inactive',
+    })
+    displayHeader(`Group Members (${members.length})`)
+    this.log(
+      members
+        .map((curator) => chalk.white(`${curator.profile.handle} (WorkerID: ${curator.workerId.toString()})`))
+        .join(', ')
+    )
+  }
+}

+ 24 - 0
cli/src/commands/content/curatorGroups.ts

@@ -0,0 +1,24 @@
+import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
+// import chalk from 'chalk'
+import { displayTable } from '../../helpers/display'
+
+export default class CuratorGroupsCommand extends ContentDirectoryCommandBase {
+  static description = 'List existing Curator Groups.'
+
+  async run() {
+    const groups = await this.getApi().availableCuratorGroups()
+
+    if (groups.length) {
+      displayTable(
+        groups.map(([id, group]) => ({
+          'ID': id.toString(),
+          'Status': group.active.valueOf() ? 'Active' : 'Inactive',
+          'Members': group.curators.toArray().length,
+        })),
+        5
+      )
+    } else {
+      this.log('No Curator Groups available!')
+    }
+  }
+}

+ 46 - 0
cli/src/commands/content/removeCuratorFromGroup.ts

@@ -0,0 +1,46 @@
+import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
+import chalk from 'chalk'
+
+export default class RemoveCuratorFromGroupCommand extends ContentDirectoryCommandBase {
+  static description = 'Remove Curator from Curator Group.'
+  static args = [
+    {
+      name: 'groupId',
+      required: false,
+      description: 'ID of the Curator Group',
+    },
+    {
+      name: 'curatorId',
+      required: false,
+      description: 'ID of the curator',
+    },
+  ]
+
+  async run() {
+    const account = await this.getRequiredSelectedAccount()
+    await this.requireLead()
+
+    let { groupId, curatorId } = this.parse(RemoveCuratorFromGroupCommand).args
+
+    if (groupId === undefined) {
+      groupId = await this.promptForCuratorGroup()
+    }
+
+    const group = await this.getCuratorGroup(groupId)
+    const groupCuratorIds = group.curators.toArray().map((id) => id.toNumber())
+
+    if (curatorId === undefined) {
+      curatorId = await this.promptForCurator('Choose a Curator to remove', groupCuratorIds)
+    } else {
+      if (!groupCuratorIds.includes(parseInt(curatorId))) {
+        this.error(`Curator ${chalk.white(curatorId)} is not part of group ${chalk.white(groupId)}`)
+      }
+      await this.getCurator(curatorId)
+    }
+
+    await this.requestAccountDecoding(account)
+    await this.sendAndFollowNamedTx(account, 'contentDirectory', 'removeCuratorFromGroup', [groupId, curatorId])
+
+    this.log(chalk.green(`Curator ${chalk.white(curatorId)} successfully removed from group ${chalk.white(groupId)}!`))
+  }
+}

+ 28 - 0
cli/src/commands/content/removeCuratorGroup.ts

@@ -0,0 +1,28 @@
+import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
+import chalk from 'chalk'
+
+export default class RemoveCuratorGroupCommand extends ContentDirectoryCommandBase {
+  static description = 'Remove existing Curator Group.'
+  static args = [
+    {
+      name: 'id',
+      required: false,
+      description: 'ID of the Curator Group to remove',
+    },
+  ]
+
+  async run() {
+    const account = await this.getRequiredSelectedAccount()
+    await this.requireLead()
+
+    let { id } = this.parse(RemoveCuratorGroupCommand).args
+    if (id === undefined) {
+      id = await this.promptForCuratorGroup('Select Curator Group to remove')
+    }
+
+    await this.requestAccountDecoding(account)
+    await this.sendAndFollowNamedTx(account, 'contentDirectory', 'removeCuratorGroup', [id])
+
+    console.log(chalk.green(`Curator Group ${chalk.white(id)} succesfully removed!`))
+  }
+}

+ 61 - 0
cli/src/commands/content/setCuratorGroupStatus.ts

@@ -0,0 +1,61 @@
+import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
+import chalk from 'chalk'
+import ExitCodes from '../../ExitCodes'
+
+export default class SetCuratorGroupStatusCommand extends ContentDirectoryCommandBase {
+  static description = 'Set Curator Group status (Active/Inactive).'
+  static args = [
+    {
+      name: 'id',
+      required: false,
+      description: 'ID of the Curator Group',
+    },
+    {
+      name: 'status',
+      required: false,
+      description: 'New status of the group (1 - active, 0 - inactive)',
+    },
+  ]
+
+  async run() {
+    const account = await this.getRequiredSelectedAccount()
+    await this.requireLead()
+
+    let { id, status } = this.parse(SetCuratorGroupStatusCommand).args
+
+    if (id === undefined) {
+      id = await this.promptForCuratorGroup()
+    } else {
+      await this.getCuratorGroup(id)
+    }
+
+    if (status === undefined) {
+      status = await this.simplePrompt({
+        type: 'list',
+        message: 'Select new status',
+        choices: [
+          { name: 'Active', value: true },
+          { name: 'Inactive', value: false },
+        ],
+      })
+    } else {
+      if (status !== '0' && status !== '1') {
+        this.error('Invalid status provided. Use "1" for Active and "0" for Inactive.', {
+          exit: ExitCodes.InvalidInput,
+        })
+      }
+      status = !!parseInt(status)
+    }
+
+    await this.requestAccountDecoding(account)
+    await this.sendAndFollowNamedTx(account, 'contentDirectory', 'setCuratorGroupStatus', [id, status])
+
+    console.log(
+      chalk.green(
+        `Curator Group ${chalk.white(id)} status succesfully changed to: ${chalk.white(
+          status ? 'Active' : 'Inactive'
+        )}!`
+      )
+    )
+  }
+}