|
@@ -2,10 +2,19 @@ import { KeyringPair } from '@polkadot/keyring/types'
|
|
|
import path from 'path'
|
|
|
import { CLI, CommandResult } from './base'
|
|
|
import { TmpFileManager } from './utils'
|
|
|
-import { MemberId } from '@joystream/types/common'
|
|
|
+import {
|
|
|
+ VideoInputParameters,
|
|
|
+ ChannelCreationInputParameters,
|
|
|
+ ChannelUpdateInputParameters,
|
|
|
+ ChannelCategoryInputParameters,
|
|
|
+ VideoCategoryInputParameters,
|
|
|
+} from '@joystream/cli/src/Types'
|
|
|
+import ExitCodes from '@joystream/cli/src/ExitCodes'
|
|
|
|
|
|
const CLI_ROOT_PATH = path.resolve(__dirname, '../../../../cli')
|
|
|
|
|
|
+type Modify<T, R> = Omit<T, keyof R> & R
|
|
|
+
|
|
|
export interface ICreatedVideoData {
|
|
|
videoId: number
|
|
|
assetContentIds: string[]
|
|
@@ -75,30 +84,26 @@ export class JoystreamCLI extends CLI {
|
|
|
return parseInt((text.match(/with id (\d+) successfully created/) as RegExpMatchArray)[1])
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- Checks if CLI's stderr contains warning about no storage provider available.
|
|
|
+ /*
|
|
|
+ Decide if CLI error indicates that storage provider is not available.
|
|
|
*/
|
|
|
- private containsWarningNoStorage(stderr: string): boolean {
|
|
|
- return !!stderr.match(/^\s*\S\s*Warning: No storage provider is currently available!/m)
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- Checks if CLI's stderr contains warning about no password used when importing account.
|
|
|
- */
|
|
|
- private containsWarningEmptyPassword(text: string): boolean {
|
|
|
- return !!text.match(/^\s*\S\s*Warning: Using empty password is not recommended!/)
|
|
|
+ private isErrorDueToNoStorage(exitCode: number): boolean {
|
|
|
+ // TODO: remove `% 256` after https://github.com/Joystream/joystream/issues/3251 is fixed
|
|
|
+ return exitCode === ExitCodes.ActionCurrentlyUnavailable % 256
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
Creates a new channel.
|
|
|
*/
|
|
|
- async createChannel(channel: unknown, args: string[]): Promise<number> {
|
|
|
+ async createChannel(
|
|
|
+ channel: Modify<ChannelCreationInputParameters, { category?: number }>,
|
|
|
+ args: string[]
|
|
|
+ ): Promise<number> {
|
|
|
const jsonFile = this.tmpFileManager.jsonFile(channel)
|
|
|
|
|
|
const { out, stderr, exitCode } = await this.run('content:createChannel', ['--input', jsonFile, ...args])
|
|
|
|
|
|
- if (exitCode && !this.containsWarningNoStorage(stderr)) {
|
|
|
- // ignore warnings
|
|
|
+ if (exitCode && !this.isErrorDueToNoStorage(exitCode)) {
|
|
|
throw new Error(`Unexpected CLI failure on creating channel: "${stderr}"`)
|
|
|
}
|
|
|
|
|
@@ -108,7 +113,7 @@ export class JoystreamCLI extends CLI {
|
|
|
/**
|
|
|
Creates a new channel category.
|
|
|
*/
|
|
|
- async createChannelCategory(channelCategory: unknown): Promise<number> {
|
|
|
+ async createChannelCategory(channelCategory: ChannelCategoryInputParameters): Promise<number> {
|
|
|
const jsonFile = this.tmpFileManager.jsonFile(channelCategory)
|
|
|
|
|
|
const { stdout, stderr, exitCode } = await this.run('content:createChannelCategory', [
|
|
@@ -128,7 +133,11 @@ export class JoystreamCLI extends CLI {
|
|
|
/**
|
|
|
Creates a new video.
|
|
|
*/
|
|
|
- async createVideo(channelId: number, video: unknown, canOmitUpload = true): Promise<ICreatedVideoData> {
|
|
|
+ async createVideo(
|
|
|
+ channelId: number,
|
|
|
+ video: Modify<VideoInputParameters, { category: number }>,
|
|
|
+ canOmitUpload = true
|
|
|
+ ): Promise<ICreatedVideoData> {
|
|
|
const jsonFile = this.tmpFileManager.jsonFile(video)
|
|
|
|
|
|
const { stdout, stderr, exitCode } = await this.run(
|
|
@@ -139,7 +148,7 @@ export class JoystreamCLI extends CLI {
|
|
|
)
|
|
|
|
|
|
// prevent error from CLI that create
|
|
|
- if (canOmitUpload && exitCode && !this.containsWarningNoStorage(stderr)) {
|
|
|
+ if (canOmitUpload && exitCode && !this.isErrorDueToNoStorage(exitCode)) {
|
|
|
// ignore warnings
|
|
|
throw new Error(`Unexpected CLI failure on creating video: "${stderr}"`)
|
|
|
}
|
|
@@ -156,7 +165,7 @@ export class JoystreamCLI extends CLI {
|
|
|
/**
|
|
|
Creates a new video category.
|
|
|
*/
|
|
|
- async createVideoCategory(videoCategory: unknown): Promise<number> {
|
|
|
+ async createVideoCategory(videoCategory: VideoCategoryInputParameters): Promise<number> {
|
|
|
const jsonFile = this.tmpFileManager.jsonFile(videoCategory)
|
|
|
|
|
|
const { stdout, stderr, exitCode } = await this.run('content:createVideoCategory', [
|
|
@@ -176,7 +185,7 @@ export class JoystreamCLI extends CLI {
|
|
|
/**
|
|
|
Updates an existing video.
|
|
|
*/
|
|
|
- async updateVideo(videoId: number, video: unknown): Promise<void> {
|
|
|
+ async updateVideo(videoId: number, video: Modify<VideoInputParameters, { category: number }>): Promise<void> {
|
|
|
const jsonFile = this.tmpFileManager.jsonFile(video)
|
|
|
|
|
|
const { stdout, stderr, exitCode } = await this.run('content:updateVideo', [
|
|
@@ -185,7 +194,7 @@ export class JoystreamCLI extends CLI {
|
|
|
videoId.toString(),
|
|
|
])
|
|
|
|
|
|
- if (exitCode && !this.containsWarningNoStorage(stderr)) {
|
|
|
+ if (exitCode && !this.isErrorDueToNoStorage(exitCode)) {
|
|
|
// ignore warnings
|
|
|
throw new Error(`Unexpected CLI failure on creating video category: "${stderr}"`)
|
|
|
}
|
|
@@ -194,7 +203,10 @@ export class JoystreamCLI extends CLI {
|
|
|
/**
|
|
|
Updates a channel.
|
|
|
*/
|
|
|
- async updateChannel(channelId: number, channel: unknown): Promise<void> {
|
|
|
+ async updateChannel(
|
|
|
+ channelId: number,
|
|
|
+ channel: Modify<ChannelUpdateInputParameters, { category: number }>
|
|
|
+ ): Promise<void> {
|
|
|
const jsonFile = this.tmpFileManager.jsonFile(channel)
|
|
|
|
|
|
const { stdout, stderr, exitCode } = await this.run('content:updateChannel', [
|
|
@@ -203,7 +215,7 @@ export class JoystreamCLI extends CLI {
|
|
|
channelId.toString(),
|
|
|
])
|
|
|
|
|
|
- if (exitCode && !this.containsWarningNoStorage(stderr)) {
|
|
|
+ if (exitCode && !this.isErrorDueToNoStorage(exitCode)) {
|
|
|
// ignore warnings
|
|
|
throw new Error(`Unexpected CLI failure on creating video category: "${stderr}"`)
|
|
|
}
|