Browse Source

storage-node: Fix review comments.

Shamil Gadelshin 4 years ago
parent
commit
c5745245a7

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

@@ -28,7 +28,7 @@
   },
   "scripts": {
     "test": "mocha 'dist/test/**/*.js'",
-    "lint": "eslint 'paths/**/*.js' 'lib/**/*.js'",
+    "lint": "eslint --ext .js,.jsx,.ts,.tsx . && tsc --noEmit --pretty",
     "build": "tsc --build"
   },
   "bin": {

+ 4 - 5
storage-node/packages/cli/src/cli.ts

@@ -1,4 +1,3 @@
-#!/usr/bin/env node
 /*
  * This file is part of the storage node for the Joystream project.
  * Copyright (C) 2019 Joystream Contributors
@@ -40,9 +39,9 @@ const usage = `
     $ storage-cli command [arguments..]
 
   Commands:
-    upload            Upload a file to a Colossus storage node. Requires a
-                      source file path to upload, data object ID, account key file,
-                      pass phrase to unlock it and a member ID.
+    upload            Upload a file to the Joystream Network. Requires a
+                      source file path to upload, data object ID, member ID and account key file with
+                      pass phrase to unlock it.
     download          Retrieve a file. Requires a storage node URL and a content
                       ID, as well as an output filename.
     head              Send a HEAD request for a file, and print headers.
@@ -82,7 +81,7 @@ const commands = {
 
     await downloadCmd.run();
   },
-  // Shows asset information derived from request headers.
+  // Shows asset information derived from response headers.
   // Accepts colossus URL and content ID.
   head: async (api: any, storageNodeUrl: string, contentId: string) => {
     let headCmd = new HeadCommand(api, storageNodeUrl, contentId);

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

@@ -8,22 +8,22 @@ export class DownloadCommand extends BaseCommand{
     private readonly api: any;
     private readonly storageNodeUrl: string;
     private readonly contentId: string;
-    private readonly filePath: string;
+    private readonly outputFilePath: string;
 
-    constructor(api: any, storageNodeUrl: string, contentId: string, filePath: string) {
+    constructor(api: any, storageNodeUrl: string, contentId: string, outputFilePath: string) {
         super();
 
         this.api = api;
         this.storageNodeUrl = storageNodeUrl;
         this.contentId = contentId;
-        this.filePath = filePath;
+        this.outputFilePath = outputFilePath;
     }
 
     // Provides parameter validation. Overrides the abstract method from the base class.
     protected validateParameters(): boolean {
         return this.storageNodeUrl && this.storageNodeUrl !== ""
             && this.contentId && this.contentId !== ""
-            && this.filePath && this.filePath !== "";
+            && this.outputFilePath && this.outputFilePath !== "";
     }
 
     // Shows command usage. Overrides the abstract method from the base class.
@@ -40,10 +40,10 @@ export class DownloadCommand extends BaseCommand{
         if (!this.assertParameters()) return;
 
         const assetUrl = this.createAndLogAssetUrl(this.storageNodeUrl, this.contentId);
-        console.log(chalk.yellow('File path:', this.filePath));
+        console.log(chalk.yellow('File path:', this.outputFilePath));
 
         // Create file write stream and set error handler.
-        const writer = fs.createWriteStream(this.filePath)
+        const writer = fs.createWriteStream(this.outputFilePath)
             .on('error', (err) => {
                 this.fail(`File write failed: ${err}`);
             });

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

@@ -35,18 +35,18 @@ export class UploadCommand extends BaseCommand{
     constructor(api: any,
                 mediaSourceFilePath: string,
                 dataObjectTypeId: string,
+                memberId: string,
                 keyFile: string,
-                passPhrase: string,
-                memberId: string
+                passPhrase: string
     ) {
         super();
 
         this.api = api;
         this.mediaSourceFilePath = mediaSourceFilePath;
         this.dataObjectTypeId = dataObjectTypeId;
+        this.memberId = memberId;
         this.keyFile = keyFile;
         this.passPhrase = passPhrase;
-        this.memberId = memberId;
     }
 
     // Provides parameter validation. Overrides the abstract method from the base class.
@@ -181,8 +181,8 @@ export class UploadCommand extends BaseCommand{
     // Shows command usage. Overrides the abstract method from the base class.
     protected showUsage() {
         console.log(chalk.yellow(`
-        Usage:   storage-cli upload mediaSourceFilePath dataObjectTypeId keyFilePath passPhrase memberId
-        Example: storage-cli upload ./movie.mp4 1 ./keyFile.json secretPhrase 1
+        Usage:   storage-cli upload mediaSourceFilePath dataObjectTypeId memberId keyFilePath passPhrase
+        Example: storage-cli upload ./movie.mp4 1 1 ./keyFile.json secretPhrase
       `));
     }
 

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

@@ -34,7 +34,8 @@
   },
   "scripts": {
     "test": "mocha --exit 'test/**/*.js'",
-    "lint": "eslint '**/*.js' --ignore-pattern 'test/**/*.js'"
+    "lint": "eslint '**/*.js' --ignore-pattern 'test/**/*.js'",
+    "checks": "yarn lint && prettier ./ --check && tsc --noEmit --pretty"
   },
   "devDependencies": {
     "chai": "^4.2.0",