|
@@ -1,12 +1,11 @@
|
|
|
import ContentDirectoryCommandBase from '../../base/ContentDirectoryCommandBase'
|
|
|
-import { CurationStatusEntity } from 'cd-schemas/types/entities/CurationStatusEntity'
|
|
|
import { InputParser } from 'cd-schemas'
|
|
|
import { flags } from '@oclif/command'
|
|
|
import { ChannelEntity } from 'cd-schemas/types/entities/ChannelEntity'
|
|
|
import { VideoEntity } from 'cd-schemas/types/entities/VideoEntity'
|
|
|
|
|
|
const CLASSES = ['Channel', 'Video'] as const
|
|
|
-const STATUSES = ['Accepted', 'Rejected'] as const
|
|
|
+const STATUSES = ['Accepted', 'Censored'] as const
|
|
|
|
|
|
export default class CurateContentCommand extends ContentDirectoryCommandBase {
|
|
|
static description = `Set the curation status of given entity (${CLASSES.join('/')}). Requires Curator access.`
|
|
@@ -23,11 +22,6 @@ export default class CurateContentCommand extends ContentDirectoryCommandBase {
|
|
|
options: [...STATUSES],
|
|
|
required: true,
|
|
|
}),
|
|
|
- rationale: flags.string({
|
|
|
- description: 'Optional rationale',
|
|
|
- char: 'r',
|
|
|
- required: false,
|
|
|
- }),
|
|
|
id: flags.integer({
|
|
|
description: 'ID of the entity to curate',
|
|
|
required: true,
|
|
@@ -35,11 +29,11 @@ export default class CurateContentCommand extends ContentDirectoryCommandBase {
|
|
|
}
|
|
|
|
|
|
async run() {
|
|
|
- const { className, status, id, rationale } = this.parse(CurateContentCommand).flags
|
|
|
+ const { className, status, id } = this.parse(CurateContentCommand).flags
|
|
|
|
|
|
const account = await this.getRequiredSelectedAccount()
|
|
|
- // Get curator actor with required maintainer access to $className and 'CurationStatus' classes
|
|
|
- const actor = await this.getCuratorContext([className, 'CurationStatus'])
|
|
|
+ // Get curator actor with required maintainer access to $className (Video/Channel) class
|
|
|
+ const actor = await this.getCuratorContext([className])
|
|
|
|
|
|
await this.requestAccountDecoding(account)
|
|
|
|
|
@@ -47,52 +41,17 @@ export default class CurateContentCommand extends ContentDirectoryCommandBase {
|
|
|
|
|
|
await this.getEntity(id, className) // Check if entity exists and is of given class
|
|
|
|
|
|
- // Check if CurationStatus for this entity already exists
|
|
|
- let existingStatusId: number | undefined
|
|
|
- try {
|
|
|
- existingStatusId = await inputParser.findEntityIdByUniqueQuery({ entityId: id }, 'CurationStatus')
|
|
|
- } catch (e) {
|
|
|
- /* Continue */
|
|
|
+ const entityUpdateInput: Partial<ChannelEntity & VideoEntity> = {
|
|
|
+ isCensored: status === 'Censored',
|
|
|
}
|
|
|
|
|
|
- if (existingStatusId) {
|
|
|
- const current = await this.getAndParseKnownEntity<CurationStatusEntity>(existingStatusId)
|
|
|
- const statusUpdate: Partial<CurationStatusEntity> = { approved: status === 'Accepted' }
|
|
|
- if (rationale !== undefined) {
|
|
|
- statusUpdate.comment = rationale
|
|
|
- }
|
|
|
-
|
|
|
- this.log(`Existing curation status found!`)
|
|
|
- this.jsonPrettyPrint(JSON.stringify(current))
|
|
|
- this.log('It will be updated to...')
|
|
|
- this.jsonPrettyPrint(JSON.stringify({ ...current, ...statusUpdate }))
|
|
|
- const confirmed = await this.simplePrompt({
|
|
|
- type: 'confirm',
|
|
|
- message: `Do you confirm this operation?`,
|
|
|
- })
|
|
|
-
|
|
|
- if (confirmed) {
|
|
|
- const operations = await inputParser.getEntityUpdateOperations(statusUpdate, 'CurationStatus', existingStatusId)
|
|
|
- await this.sendAndFollowNamedTx(account, 'contentDirectory', 'transaction', [actor, operations], true)
|
|
|
- }
|
|
|
- } else {
|
|
|
- const curationStatus: CurationStatusEntity = {
|
|
|
- entityId: id,
|
|
|
- approved: status === 'Accepted',
|
|
|
- comment: rationale,
|
|
|
- }
|
|
|
-
|
|
|
- const entityUpdateInput: Partial<ChannelEntity & VideoEntity> = {
|
|
|
- curationStatus: { new: curationStatus },
|
|
|
- }
|
|
|
-
|
|
|
- this.jsonPrettyPrint(JSON.stringify(curationStatus))
|
|
|
- const confirmed = await this.simplePrompt({ type: 'confirm', message: 'Do you confirm the provided input?' })
|
|
|
+ this.log(`Updating the ${className} with:`)
|
|
|
+ this.jsonPrettyPrint(JSON.stringify(entityUpdateInput))
|
|
|
+ const confirmed = await this.simplePrompt({ type: 'confirm', message: 'Do you confirm the provided input?' })
|
|
|
|
|
|
- if (confirmed) {
|
|
|
- const operations = await inputParser.getEntityUpdateOperations(entityUpdateInput, className, id)
|
|
|
- await this.sendAndFollowNamedTx(account, 'contentDirectory', 'transaction', [actor, operations], true)
|
|
|
- }
|
|
|
+ if (confirmed) {
|
|
|
+ const operations = await inputParser.getEntityUpdateOperations(entityUpdateInput, className, id)
|
|
|
+ await this.sendAndFollowNamedTx(account, 'contentDirectory', 'transaction', [actor, operations], true)
|
|
|
}
|
|
|
}
|
|
|
}
|