-
Notifications
You must be signed in to change notification settings - Fork 115
/
Copy pathchannel.ts
61 lines (55 loc) · 1.84 KB
/
channel.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
import { displayCollapsedRow, displayHeader, displayTable } from '../../helpers/display'
import { PalletContentIterableEnumsChannelActionPermission } from '@polkadot/types/lookup'
import { BTreeSet } from '@polkadot/types'
import BN from 'bn.js'
import { formatBalance } from '@polkadot/util'
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',
},
]
static flags = {
...ContentDirectoryCommandBase.flags,
}
async displayCollaboratorsSet(
set: [BN, BTreeSet<PalletContentIterableEnumsChannelActionPermission>][]
): Promise<void> {
if (set.length > 0) {
displayTable(
set.map(([id, p]) => ({
'MemberId': id.toString(),
'Permissions': p.toString(),
})),
3
)
} else {
this.log('NONE')
}
}
async run(): Promise<void> {
const { channelId } = this.parse(ChannelCommand).args
const channel = await this.getApi().channelById(channelId)
if (channel) {
displayCollapsedRow({
'ID': channelId.toString(),
'Owner': JSON.stringify(channel.owner.toJSON()),
'ChannelStateBloatBond': formatBalance(channel.channelStateBloatBond.amount),
'DataObjects': channel.dataObjects.toString(),
'PrivilegeLevel': channel.privilegeLevel.toString(),
})
displayHeader(`Media`)
displayCollapsedRow({
'NumberOfVideos': channel.numVideos.toNumber(),
})
displayHeader(`Collaborators`)
await this.displayCollaboratorsSet([...channel.collaborators])
} else {
this.error(`Channel not found by channel id: "${channelId}"!`)
}
}
}