Browse Source

storage-node cli fix axios maxBodyLength, maxContentLength params

Mokhtar Naamani 4 years ago
parent
commit
7056abbce3

+ 1 - 1
storage-node/packages/cli/package.json

@@ -48,7 +48,7 @@
     "@joystream/service-discovery": "^0.1.0",
     "@joystream/storage-utils": "^0.1.0",
     "@joystream/types": "^0.16.0",
-    "axios": "^0.19.2",
+    "axios": "^0.21.1",
     "chalk": "^2.4.2",
     "lodash": "^4.17.11",
     "meow": "^5.0.0",

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

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

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

@@ -2,6 +2,7 @@ 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 {
@@ -60,6 +61,8 @@ export class DownloadCommand extends BaseCommand {
         url: assetUrl,
         method: 'GET',
         responseType: 'stream',
+        // max length of response
+        maxContentLength: MAX_CONTENT_LENGTH,
       })
 
       response.data.pipe(writer)

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

@@ -8,11 +8,9 @@ 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 maximum content length for the assets (files). Limits the upload.
-const MAX_CONTENT_LENGTH = 500 * 1024 * 1024 // 500Mb
-
 // Defines the necessary parameters for the AddContent runtime tx.
 interface AddContentParams {
   accountId: string
@@ -137,7 +135,8 @@ export class UploadCommand extends BaseCommand {
           'Content-Type': '', // https://github.com/Joystream/storage-node-joystream/issues/16
           'Content-Length': fileSize.toString(),
         },
-        maxContentLength: MAX_CONTENT_LENGTH,
+        // max length of body in put request
+        maxBodyLength: MAX_CONTENT_LENGTH,
       }
       await axios.put(assetUrl, file, config)
 

+ 1 - 1
yarn.lock

@@ -7237,7 +7237,7 @@ axios@^0.18.0, axios@^0.18.1:
     follow-redirects "1.5.10"
     is-buffer "^2.0.2"
 
-axios@^0.19.0, axios@^0.19.2:
+axios@^0.19.0:
   version "0.19.2"
   resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.2.tgz#3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27"
   integrity sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==