瀏覽代碼

storage-node: cli move const into command base.ts

Mokhtar Naamani 4 年之前
父節點
當前提交
543f46c4a9

+ 6 - 1
storage-node/packages/cli/src/commands/base.ts

@@ -41,8 +41,13 @@ export abstract class BaseCommand {
   }
 
   // Shows the error message and ends the process with error code.
-  protected fail(message: string) {
+  protected fail(message: string): void {
     console.log(chalk.red(message))
     process.exit(1)
   }
+
+  protected maxContentSize(): number {
+    // Maximum content length for the assets (files)
+    return 2000 * 1024 * 1024
+  }
 }

+ 0 - 2
storage-node/packages/cli/src/commands/consts.ts

@@ -1,2 +0,0 @@
-// Defines maximum content length for the assets (files)
-export const MAX_CONTENT_LENGTH = 2000 * 1024 * 1024 // 2GB

+ 1 - 2
storage-node/packages/cli/src/commands/download.ts

@@ -2,7 +2,6 @@ import axios from 'axios'
 import chalk from 'chalk'
 import fs from 'fs'
 import { BaseCommand } from './base'
-import { MAX_CONTENT_LENGTH } from './consts'
 
 // Download command class. Validates input parameters and execute the logic for asset downloading.
 export class DownloadCommand extends BaseCommand {
@@ -62,7 +61,7 @@ export class DownloadCommand extends BaseCommand {
         method: 'GET',
         responseType: 'stream',
         // max length of response
-        maxContentLength: MAX_CONTENT_LENGTH,
+        maxContentLength: this.maxContentSize(),
       })
 
       response.data.pipe(writer)

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

@@ -8,7 +8,6 @@ import { DiscoveryClient } from '@joystream/service-discovery'
 import Debug from 'debug'
 import chalk from 'chalk'
 import { aliceKeyPair } from './dev'
-import { MAX_CONTENT_LENGTH } from './consts'
 const debug = Debug('joystream:storage-cli:upload')
 
 // Defines the necessary parameters for the AddContent runtime tx.
@@ -146,8 +145,8 @@ export class UploadCommand extends BaseCommand {
           'Content-Type': '', // https://github.com/Joystream/storage-node-joystream/issues/16
           'Content-Length': fileSize.toString(),
         },
-        // max length of body in put request
-        maxBodyLength: MAX_CONTENT_LENGTH,
+        // max length of body in PUT request
+        maxBodyLength: this.maxContentSize(),
       }
       await axios.put(assetUrl, file, config)