瀏覽代碼

storage-node: cli: Change contentID type.

Shamil Gadelshin 4 年之前
父節點
當前提交
f495d3f2e2
共有 2 個文件被更改,包括 14 次插入5 次删除
  1. 11 2
      storage-node/packages/cli/src/commands/base.ts
  2. 3 3
      storage-node/packages/cli/src/commands/upload.ts

+ 11 - 2
storage-node/packages/cli/src/commands/base.ts

@@ -1,12 +1,21 @@
 import chalk from 'chalk'
 import removeEndingForwardSlash from '@joystream/storage-utils/stripEndingSlash'
+import {ContentId} from "@joystream/types/media";
 
 // Commands base abstract class. Contains reusable methods.
 export abstract class BaseCommand {
   // Creates the Colossus asset URL and logs it.
-  protected createAndLogAssetUrl(url: string, contentId: string): string {
+  protected createAndLogAssetUrl(url: string, contentId: string | ContentId): string {
+    let normalizedContentId: string;
+
+    if (typeof contentId === "string") {
+      normalizedContentId = contentId
+    } else {
+      normalizedContentId = contentId.encode()
+    }
+
     const normalizedUrl = removeEndingForwardSlash(url)
-    const assetUrl = `${normalizedUrl}/asset/v0/${contentId}`
+    const assetUrl = `${normalizedUrl}/asset/v0/${normalizedContentId}`
     console.log(chalk.yellow('Generated asset URL:', assetUrl))
 
     return assetUrl

+ 3 - 3
storage-node/packages/cli/src/commands/upload.ts

@@ -18,7 +18,7 @@ const MAX_CONTENT_LENGTH = 500 * 1024 * 1024 // 500Mb
 interface AddContentParams {
   accountId: string
   ipfsCid: string
-  contentId: string
+  contentId: ContentId
   fileSize: BN
   dataObjectTypeId: number
   memberId: number
@@ -96,7 +96,7 @@ export class UploadCommand extends BaseCommand {
     return {
       accountId,
       ipfsCid: await this.computeIpfsHash(),
-      contentId: ContentId.generate().encode(),
+      contentId: ContentId.generate(),
       fileSize: new BN(this.getFileSize()),
       dataObjectTypeId,
       memberId,
@@ -206,7 +206,7 @@ export class UploadCommand extends BaseCommand {
 
     const addContentParams = await this.getAddContentParams()
     debug(`AddContent Tx params: ${JSON.stringify(addContentParams)}`)
-    debug(`Decoded CID: ${ContentId.decode(addContentParams.contentId).toString()}`)
+    debug(`Decoded CID: ${addContentParams.contentId.toString()}`)
 
     const dataObject = await this.createContent(addContentParams)
     debug(`Received data object: ${dataObject.toString()}`)