|
@@ -5,38 +5,27 @@ import { BaseCommand } from './base'
|
|
|
|
|
|
// Download command class. Validates input parameters and execute the logic for asset downloading.
|
|
|
export class DownloadCommand extends BaseCommand {
|
|
|
- private readonly api: any
|
|
|
- private readonly storageNodeUrl: string
|
|
|
private readonly contentId: string
|
|
|
private readonly outputFilePath: string
|
|
|
|
|
|
- constructor(api: any, storageNodeUrl: string, contentId: string, outputFilePath: string) {
|
|
|
- super()
|
|
|
+ constructor(api: any, contentId: string, outputFilePath: string) {
|
|
|
+ super(api)
|
|
|
|
|
|
- this.api = api
|
|
|
- this.storageNodeUrl = storageNodeUrl
|
|
|
this.contentId = contentId
|
|
|
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.outputFilePath &&
|
|
|
- this.outputFilePath !== ''
|
|
|
- )
|
|
|
+ return this.contentId && this.contentId !== '' && this.outputFilePath && this.outputFilePath !== ''
|
|
|
}
|
|
|
|
|
|
// Shows command usage. Overrides the abstract method from the base class.
|
|
|
protected showUsage() {
|
|
|
console.log(
|
|
|
chalk.yellow(`
|
|
|
- Usage: storage-cli download colossusURL contentID filePath
|
|
|
- Example: storage-cli download http://localhost:3001 0x7a6ba7e9157e5fba190dc146fe1baa8180e29728a5c76779ed99655500cff795 ./movie.mp4
|
|
|
+ Usage: storage-cli download contentID filePath
|
|
|
+ Example: storage-cli download 0x7a6ba7e9157e5fba190dc146fe1baa8180e29728a5c76779ed99655500cff795 ./movie.mp4
|
|
|
`)
|
|
|
)
|
|
|
}
|
|
@@ -46,7 +35,9 @@ export class DownloadCommand extends BaseCommand {
|
|
|
// Checks for input parameters, shows usage if they are invalid.
|
|
|
if (!this.assertParameters()) return
|
|
|
|
|
|
- const assetUrl = this.createAndLogAssetUrl(this.storageNodeUrl, this.contentId)
|
|
|
+ const storageNodeUrl = await this.getAnyProviderEndpoint()
|
|
|
+
|
|
|
+ const assetUrl = this.createAndLogAssetUrl(storageNodeUrl, this.contentId)
|
|
|
console.log(chalk.yellow('File path:', this.outputFilePath))
|
|
|
|
|
|
// Create file write stream and set error handler.
|