瀏覽代碼

Add "attribution" to runtime license schema (+ CLI side handling)

Leszek Wiesner 4 年之前
父節點
當前提交
a102394c10

+ 5 - 2
cli/src/base/AccountsCommandBase.ts

@@ -177,8 +177,11 @@ export default abstract class AccountsCommandBase extends ApiCommandBase {
     return password
   }
 
-  async requireConfirmation(message = 'Are you sure you want to execute this action?'): Promise<void> {
-    const { confirmed } = await inquirer.prompt([{ type: 'confirm', name: 'confirmed', message, default: false }])
+  async requireConfirmation(
+    message = 'Are you sure you want to execute this action?',
+    defaultVal = false
+  ): Promise<void> {
+    const { confirmed } = await inquirer.prompt([{ type: 'confirm', name: 'confirmed', message, default: defaultVal }])
     if (!confirmed) this.exit(ExitCodes.OK)
   }
 

+ 6 - 15
cli/src/base/MediaCommandBase.ts

@@ -1,5 +1,5 @@
 import ContentDirectoryCommandBase from './ContentDirectoryCommandBase'
-import { VideoEntity, KnownLicenseEntity } from 'cd-schemas/types/entities'
+import { VideoEntity, KnownLicenseEntity, LicenseEntity } from '@joystream/cd-schemas/types/entities'
 import fs from 'fs'
 import { DistinctQuestion } from 'inquirer'
 import path from 'path'
@@ -12,7 +12,7 @@ const MAX_USER_LICENSE_CONTENT_LENGTH = 4096
  */
 export default abstract class MediaCommandBase extends ContentDirectoryCommandBase {
   async promptForNewLicense(): Promise<VideoEntity['license']> {
-    let license: VideoEntity['license']
+    let licenseInput: LicenseEntity
     const licenseType: 'known' | 'custom' = await this.simplePrompt({
       type: 'list',
       message: 'Choose license type',
@@ -24,18 +24,9 @@ export default abstract class MediaCommandBase extends ContentDirectoryCommandBa
     if (licenseType === 'known') {
       const [id, knownLicenseEntity] = await this.promptForEntityEntry('Choose License', 'KnownLicense', 'code')
       const knownLicense = await this.parseToKnownEntityJson<KnownLicenseEntity>(knownLicenseEntity)
+      licenseInput = { knownLicense: id.toNumber() }
       if (knownLicense.attributionRequired) {
-        // Attribution required - convert to UserDefinedLicense
-        const attribution = await this.simplePrompt({ message: 'Attribution' })
-        const { name, code, description, url } = knownLicense
-        const licenseContent =
-          `${code}${name ? ` (${name})` : ''}\n\n` +
-          (description ? `${description}\n\n` : '') +
-          (url ? `${url}\n\n` : '') +
-          `Attribution: ${attribution}`
-        license = { new: { userDefinedLicense: { new: { content: licenseContent } } } }
-      } else {
-        license = { new: { knownLicense: id.toNumber() } }
+        licenseInput.attribution = await this.simplePrompt({ message: 'Attribution' })
       }
     } else {
       let licenseContent: null | string = null
@@ -52,10 +43,10 @@ export default abstract class MediaCommandBase extends ContentDirectoryCommandBa
           licenseContent = null
         }
       }
-      license = { new: { userDefinedLicense: { new: { content: licenseContent } } } }
+      licenseInput = { userDefinedLicense: { new: { content: licenseContent } } }
     }
 
-    return license
+    return { new: licenseInput }
   }
 
   async promptForPublishedBeforeJoystream(current?: number | null): Promise<number | null> {

+ 3 - 1
cli/src/commands/media/uploadVideo.ts

@@ -423,7 +423,9 @@ export default class UploadVideoCommand extends MediaCommandBase {
 
     this.jsonPrettyPrint(JSON.stringify(videoInput))
 
-    if (!confirm) await this.requireConfirmation('Do you confirm the provided input?')
+    if (!confirm) {
+      await this.requireConfirmation('Do you confirm the provided input?', true)
+    }
 
     // Parse inputs into operations and send final extrinsic
     const inputParser = InputParser.createWithKnownSchemas(this.getOriginalApi(), [

+ 6 - 0
content-directory-schemas/inputs/schemas/LicenseSchema.json

@@ -12,6 +12,12 @@
       "description": "Reference to user-defined license",
       "required": false,
       "property_type": { "Single": { "Reference": { "className": "UserDefinedLicense", "sameOwner": true } } }
+    },
+    {
+      "name": "attribution",
+      "description": "Attribution (if required by the license)",
+      "required": false,
+      "property_type": { "Single": { "Text": 512 } }
     }
   ]
 }