@super-protocol/sp-cli 0.0.2-beta.15 → 0.0.2-beta.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -21
- package/dist/commands/auth/login.js +1 -1
- package/dist/commands/files/download.js +8 -6
- package/dist/commands/files/upload.js +8 -6
- package/dist/managers/account-manager.js +1 -1
- package/dist/managers/config-file-manager.js +14 -3
- package/dist/services/storage.service.d.ts +1 -0
- package/dist/services/storage.service.js +62 -38
- package/dist/utils/progress.js +10 -2
- package/oclif.manifest.json +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ $ npm install -g @super-protocol/sp-cli
|
|
|
21
21
|
$ sp COMMAND
|
|
22
22
|
running command...
|
|
23
23
|
$ sp (--version)
|
|
24
|
-
@super-protocol/sp-cli/0.0.2-beta.
|
|
24
|
+
@super-protocol/sp-cli/0.0.2-beta.17 linux-x64 node-v22.21.1
|
|
25
25
|
$ sp --help [COMMAND]
|
|
26
26
|
USAGE
|
|
27
27
|
$ sp COMMAND
|
|
@@ -65,7 +65,7 @@ DESCRIPTION
|
|
|
65
65
|
Information about current authorized user
|
|
66
66
|
```
|
|
67
67
|
|
|
68
|
-
_See code: [src/commands/account/info.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
68
|
+
_See code: [src/commands/account/info.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.17/src/commands/account/info.ts)_
|
|
69
69
|
|
|
70
70
|
## `sp auth login`
|
|
71
71
|
|
|
@@ -89,7 +89,7 @@ EXAMPLES
|
|
|
89
89
|
$ sp auth login
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
-
_See code: [src/commands/auth/login.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
92
|
+
_See code: [src/commands/auth/login.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.17/src/commands/auth/login.ts)_
|
|
93
93
|
|
|
94
94
|
## `sp auth me`
|
|
95
95
|
|
|
@@ -102,7 +102,7 @@ GLOBAL FLAGS
|
|
|
102
102
|
--json Format output as json.
|
|
103
103
|
```
|
|
104
104
|
|
|
105
|
-
_See code: [src/commands/auth/me.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
105
|
+
_See code: [src/commands/auth/me.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.17/src/commands/auth/me.ts)_
|
|
106
106
|
|
|
107
107
|
## `sp autocomplete [SHELL]`
|
|
108
108
|
|
|
@@ -163,7 +163,7 @@ EXAMPLES
|
|
|
163
163
|
$ sp config delete - Delete a configuration
|
|
164
164
|
```
|
|
165
165
|
|
|
166
|
-
_See code: [src/commands/config/index.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
166
|
+
_See code: [src/commands/config/index.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.17/src/commands/config/index.ts)_
|
|
167
167
|
|
|
168
168
|
## `sp config add [FILE]`
|
|
169
169
|
|
|
@@ -202,7 +202,7 @@ EXAMPLES
|
|
|
202
202
|
}
|
|
203
203
|
```
|
|
204
204
|
|
|
205
|
-
_See code: [src/commands/config/add.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
205
|
+
_See code: [src/commands/config/add.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.17/src/commands/config/add.ts)_
|
|
206
206
|
|
|
207
207
|
## `sp config create`
|
|
208
208
|
|
|
@@ -229,7 +229,7 @@ EXAMPLES
|
|
|
229
229
|
$ sp config create --name "Production" --url "https://api.dp.superprotocol.com"
|
|
230
230
|
```
|
|
231
231
|
|
|
232
|
-
_See code: [src/commands/config/create.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
232
|
+
_See code: [src/commands/config/create.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.17/src/commands/config/create.ts)_
|
|
233
233
|
|
|
234
234
|
## `sp config delete`
|
|
235
235
|
|
|
@@ -257,7 +257,7 @@ EXAMPLES
|
|
|
257
257
|
$ sp config delete --name "My Config" --force
|
|
258
258
|
```
|
|
259
259
|
|
|
260
|
-
_See code: [src/commands/config/delete.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
260
|
+
_See code: [src/commands/config/delete.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.17/src/commands/config/delete.ts)_
|
|
261
261
|
|
|
262
262
|
## `sp config list`
|
|
263
263
|
|
|
@@ -277,7 +277,7 @@ EXAMPLES
|
|
|
277
277
|
$ sp config list
|
|
278
278
|
```
|
|
279
279
|
|
|
280
|
-
_See code: [src/commands/config/list.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
280
|
+
_See code: [src/commands/config/list.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.17/src/commands/config/list.ts)_
|
|
281
281
|
|
|
282
282
|
## `sp config show`
|
|
283
283
|
|
|
@@ -297,7 +297,7 @@ EXAMPLES
|
|
|
297
297
|
$ sp config show
|
|
298
298
|
```
|
|
299
299
|
|
|
300
|
-
_See code: [src/commands/config/show.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
300
|
+
_See code: [src/commands/config/show.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.17/src/commands/config/show.ts)_
|
|
301
301
|
|
|
302
302
|
## `sp config use`
|
|
303
303
|
|
|
@@ -317,11 +317,11 @@ EXAMPLES
|
|
|
317
317
|
$ sp config use
|
|
318
318
|
```
|
|
319
319
|
|
|
320
|
-
_See code: [src/commands/config/use.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
320
|
+
_See code: [src/commands/config/use.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.17/src/commands/config/use.ts)_
|
|
321
321
|
|
|
322
322
|
## `sp files download RESOURCEFILE LOCALDIRECTORY`
|
|
323
323
|
|
|
324
|
-
Download file or directory described in resource
|
|
324
|
+
Download file or directory described in resource file
|
|
325
325
|
|
|
326
326
|
```
|
|
327
327
|
USAGE
|
|
@@ -332,24 +332,24 @@ ARGUMENTS
|
|
|
332
332
|
LOCALDIRECTORY Path to save downloaded file
|
|
333
333
|
|
|
334
334
|
FLAGS
|
|
335
|
-
--maximum-concurrent=<value> [default: 1] Maximum concurrent pieces to
|
|
335
|
+
--maximum-concurrent=<value> [default: 1] Maximum concurrent pieces to download at once per transfer
|
|
336
336
|
|
|
337
337
|
GLOBAL FLAGS
|
|
338
338
|
--config=<value> Specify config file.
|
|
339
339
|
--json Format output as json.
|
|
340
340
|
|
|
341
341
|
DESCRIPTION
|
|
342
|
-
Download file or directory described in resource
|
|
342
|
+
Download file or directory described in resource file
|
|
343
343
|
|
|
344
344
|
EXAMPLES
|
|
345
345
|
$ sp files download ./resource.json ./pathToDownload
|
|
346
346
|
```
|
|
347
347
|
|
|
348
|
-
_See code: [src/commands/files/download.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
348
|
+
_See code: [src/commands/files/download.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.17/src/commands/files/download.ts)_
|
|
349
349
|
|
|
350
350
|
## `sp files upload PATH`
|
|
351
351
|
|
|
352
|
-
Upload
|
|
352
|
+
Upload file or directory to remote storage
|
|
353
353
|
|
|
354
354
|
```
|
|
355
355
|
USAGE
|
|
@@ -373,13 +373,13 @@ GLOBAL FLAGS
|
|
|
373
373
|
--json Format output as json.
|
|
374
374
|
|
|
375
375
|
DESCRIPTION
|
|
376
|
-
Upload
|
|
376
|
+
Upload file or directory to remote storage
|
|
377
377
|
|
|
378
378
|
EXAMPLES
|
|
379
379
|
$ sp files upload ./file.txt
|
|
380
380
|
```
|
|
381
381
|
|
|
382
|
-
_See code: [src/commands/files/upload.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
382
|
+
_See code: [src/commands/files/upload.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.17/src/commands/files/upload.ts)_
|
|
383
383
|
|
|
384
384
|
## `sp help [COMMAND]`
|
|
385
385
|
|
|
@@ -450,7 +450,7 @@ EXAMPLES
|
|
|
450
450
|
$ sp storage create --not-default
|
|
451
451
|
```
|
|
452
452
|
|
|
453
|
-
_See code: [src/commands/storage/create.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
453
|
+
_See code: [src/commands/storage/create.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.17/src/commands/storage/create.ts)_
|
|
454
454
|
|
|
455
455
|
## `sp storage select`
|
|
456
456
|
|
|
@@ -476,7 +476,7 @@ EXAMPLES
|
|
|
476
476
|
$ sp storage select --id=2de3e3a4-0000-1111-2222-333344445555
|
|
477
477
|
```
|
|
478
478
|
|
|
479
|
-
_See code: [src/commands/storage/select.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
479
|
+
_See code: [src/commands/storage/select.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.17/src/commands/storage/select.ts)_
|
|
480
480
|
|
|
481
481
|
## `sp storage update`
|
|
482
482
|
|
|
@@ -503,5 +503,5 @@ EXAMPLES
|
|
|
503
503
|
$ sp storage update --id=2de3e3a4-0000-1111-2222-333344445555
|
|
504
504
|
```
|
|
505
505
|
|
|
506
|
-
_See code: [src/commands/storage/update.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.
|
|
506
|
+
_See code: [src/commands/storage/update.ts](https://github.com/Super-Protocol/sp-cli/blob/v0.0.2-beta.17/src/commands/storage/update.ts)_
|
|
507
507
|
<!-- commandsstop -->
|
|
@@ -44,7 +44,7 @@ export default class SpLogin extends BaseCommand {
|
|
|
44
44
|
this.warn('Storage initialization failed. You can set up storage later using "sp storage create" or "sp storage select".');
|
|
45
45
|
}
|
|
46
46
|
const account = accountManager.getAddress();
|
|
47
|
-
this.log(`
|
|
47
|
+
this.log(`Logged in with account ${account}`);
|
|
48
48
|
return { account, success: true };
|
|
49
49
|
}
|
|
50
50
|
}
|
|
@@ -8,13 +8,13 @@ export default class FilesDownload extends BaseCommand {
|
|
|
8
8
|
// eslint-disable-next-line perfectionist/sort-objects
|
|
9
9
|
localDirectory: Args.string({ description: 'Path to save downloaded file', required: true }),
|
|
10
10
|
};
|
|
11
|
-
static description = 'Download file or directory described in resource
|
|
11
|
+
static description = 'Download file or directory described in resource file';
|
|
12
12
|
static examples = [
|
|
13
13
|
'<%= config.bin %> <%= command.id %> ./resource.json ./pathToDownload ',
|
|
14
14
|
];
|
|
15
15
|
static flags = {
|
|
16
16
|
'maximum-concurrent': Flags.integer({
|
|
17
|
-
default: 1, description: 'Maximum concurrent pieces to
|
|
17
|
+
default: 1, description: 'Maximum concurrent pieces to download at once per transfer', max: 1000, min: 1,
|
|
18
18
|
}),
|
|
19
19
|
};
|
|
20
20
|
static help = 'Download and decrypt a file from the remote storage to <localPath> using resource file <resourcePath>';
|
|
@@ -25,20 +25,19 @@ export default class FilesDownload extends BaseCommand {
|
|
|
25
25
|
async run() {
|
|
26
26
|
const { args, flags } = await this.parse(FilesDownload);
|
|
27
27
|
const { providerClient } = this.container;
|
|
28
|
-
const
|
|
28
|
+
const storageService = new StorageService(providerClient, this.logger);
|
|
29
29
|
const progress = createProgressPrinter({
|
|
30
30
|
action: 'Download',
|
|
31
31
|
start: 'Downloading: ',
|
|
32
32
|
});
|
|
33
33
|
try {
|
|
34
|
-
await
|
|
34
|
+
await storageService.download({
|
|
35
35
|
downloadPath: args.localDirectory,
|
|
36
36
|
maximumConcurrent: flags['maximum-concurrent'],
|
|
37
37
|
resourcePath: args.resourceFile,
|
|
38
38
|
}, ({ current, key, total }) => {
|
|
39
39
|
progress.advance(key, current / total * 100, `Downloading: ${key} [${current}/${total}]`);
|
|
40
40
|
});
|
|
41
|
-
progress.finish();
|
|
42
41
|
}
|
|
43
42
|
catch (error) {
|
|
44
43
|
let reason = '';
|
|
@@ -48,6 +47,9 @@ export default class FilesDownload extends BaseCommand {
|
|
|
48
47
|
}
|
|
49
48
|
this.error(`Download aborted. Reason: ${reason}`);
|
|
50
49
|
}
|
|
51
|
-
|
|
50
|
+
finally {
|
|
51
|
+
progress.finish();
|
|
52
|
+
}
|
|
53
|
+
this.log('Download successfully completed');
|
|
52
54
|
}
|
|
53
55
|
}
|
|
@@ -6,7 +6,7 @@ export default class FilesUpload extends BaseCommand {
|
|
|
6
6
|
static args = {
|
|
7
7
|
path: Args.string({ description: 'file or directory to upload', required: true }),
|
|
8
8
|
};
|
|
9
|
-
static description = 'Upload
|
|
9
|
+
static description = 'Upload file or directory to remote storage';
|
|
10
10
|
static examples = [
|
|
11
11
|
'<%= config.bin %> <%= command.id %> ./file.txt',
|
|
12
12
|
];
|
|
@@ -45,24 +45,23 @@ export default class FilesUpload extends BaseCommand {
|
|
|
45
45
|
async run() {
|
|
46
46
|
const { args, flags } = await this.parse(FilesUpload);
|
|
47
47
|
const { providerClient } = this.container;
|
|
48
|
-
const
|
|
48
|
+
const storageService = new StorageService(providerClient, this.logger);
|
|
49
49
|
const progress = createProgressPrinter({
|
|
50
50
|
action: 'Upload',
|
|
51
51
|
start: 'Uploading: ',
|
|
52
52
|
});
|
|
53
53
|
try {
|
|
54
|
-
await
|
|
54
|
+
await storageService.upload({
|
|
55
55
|
localPath: args.path,
|
|
56
56
|
maximumConcurrent: flags['maximum-concurrent'],
|
|
57
57
|
metadataPath: flags.metadata,
|
|
58
58
|
outputPath: flags.output,
|
|
59
59
|
remotePath: flags.filename,
|
|
60
60
|
sync: flags.sync,
|
|
61
|
-
withEncryption: flags['skip-encryption'],
|
|
61
|
+
withEncryption: !flags['skip-encryption'],
|
|
62
62
|
}, ({ current, key, total }) => {
|
|
63
63
|
progress.advance(key, current / total * 100, `Uploading: ${key} [${current}/${total}]`);
|
|
64
64
|
});
|
|
65
|
-
progress.finish();
|
|
66
65
|
}
|
|
67
66
|
catch (error) {
|
|
68
67
|
let reason = '';
|
|
@@ -72,6 +71,9 @@ export default class FilesUpload extends BaseCommand {
|
|
|
72
71
|
}
|
|
73
72
|
this.error(`Upload aborted. Reason: ${reason}`);
|
|
74
73
|
}
|
|
75
|
-
|
|
74
|
+
finally {
|
|
75
|
+
progress.finish();
|
|
76
|
+
}
|
|
77
|
+
this.log('Upload successfully completed');
|
|
76
78
|
}
|
|
77
79
|
}
|
|
@@ -65,7 +65,7 @@ export class AccountManager {
|
|
|
65
65
|
}
|
|
66
66
|
catch (error) {
|
|
67
67
|
this.logger.warn({ err: error }, 'Incorrect config file');
|
|
68
|
-
ux.warn("Account doesn't
|
|
68
|
+
ux.warn("Account doesn't exist in current configuration");
|
|
69
69
|
const ask = await confirm({
|
|
70
70
|
message: 'Do you want to create new account?',
|
|
71
71
|
});
|
|
@@ -170,10 +170,21 @@ export class ConfigFileManager {
|
|
|
170
170
|
return this.runtimeConfigFile;
|
|
171
171
|
}
|
|
172
172
|
if (!this.configs.currentConfig) {
|
|
173
|
-
|
|
174
|
-
|
|
173
|
+
try {
|
|
174
|
+
await this.createConfig(DEFAULT_USER_CONFIG_FILE, DEFAULT_USER_CONFIG_NAME);
|
|
175
|
+
}
|
|
176
|
+
catch {
|
|
177
|
+
//
|
|
178
|
+
}
|
|
179
|
+
try {
|
|
180
|
+
await this.setCurrentConfig(DEFAULT_USER_CONFIG_FILE);
|
|
181
|
+
}
|
|
182
|
+
catch (error) {
|
|
183
|
+
this.logger.error({ err: error }, 'Failed to set default config');
|
|
184
|
+
throw error;
|
|
185
|
+
}
|
|
175
186
|
}
|
|
176
|
-
return path.join(this.configsDir, this.configs.currentConfig);
|
|
187
|
+
return path.join(this.configsDir, this.configs.currentConfig || DEFAULT_USER_CONFIG_FILE);
|
|
177
188
|
}
|
|
178
189
|
async importConfig(sourcePath, targetName) {
|
|
179
190
|
if (!fs.existsSync(sourcePath)) {
|
|
@@ -67,5 +67,6 @@ export declare class StorageService {
|
|
|
67
67
|
} | undefined>;
|
|
68
68
|
updateStorage(id: string, storage: UpdateStorageDto): Promise<StorageResponseDto>;
|
|
69
69
|
upload(params: IUploadParams, progressCb: ProgressCb): Promise<void>;
|
|
70
|
+
private getStorageCredentials;
|
|
70
71
|
}
|
|
71
72
|
export {};
|
|
@@ -67,13 +67,22 @@ export class StorageService {
|
|
|
67
67
|
}
|
|
68
68
|
let localPath = preparePath(params.downloadPath);
|
|
69
69
|
if (resource.filepath) {
|
|
70
|
-
|
|
70
|
+
const sanitizedFilepath = resource.filepath.replaceAll('..', '').replace(/^\/+/, '');
|
|
71
|
+
localPath = joinPaths(localPath, sanitizedFilepath);
|
|
72
|
+
}
|
|
73
|
+
try {
|
|
74
|
+
this.logger.info('Starting download');
|
|
75
|
+
const downloadResult = await download(resource, localPath, {
|
|
76
|
+
encryption: resourceFile.encryption,
|
|
77
|
+
progressCallback: progressCb,
|
|
78
|
+
threads: params.maximumConcurrent,
|
|
79
|
+
});
|
|
80
|
+
this.logger.info(downloadResult, 'Downloaded');
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
this.logger.error({ err: error }, 'Download failed with error');
|
|
84
|
+
throw error;
|
|
71
85
|
}
|
|
72
|
-
await download(resource, localPath, {
|
|
73
|
-
encryption: resourceFile.encryption,
|
|
74
|
-
progressCallback: progressCb,
|
|
75
|
-
threads: params.maximumConcurrent,
|
|
76
|
-
});
|
|
77
86
|
}
|
|
78
87
|
async getCentralizedStorage() {
|
|
79
88
|
try {
|
|
@@ -234,7 +243,7 @@ export class StorageService {
|
|
|
234
243
|
}
|
|
235
244
|
async upload(params, progressCb) {
|
|
236
245
|
const storage = await this.getCurrentStorage();
|
|
237
|
-
const remotePath =
|
|
246
|
+
const remotePath = params.remotePath ? params.remotePath.replaceAll('..', '').replace(/^\/+/, '') : generateExternalId();
|
|
238
247
|
const resourceFilePath = preparePath(params.outputPath || '');
|
|
239
248
|
try {
|
|
240
249
|
await fs.stat(resourceFilePath);
|
|
@@ -249,32 +258,7 @@ export class StorageService {
|
|
|
249
258
|
if (params.metadataPath) {
|
|
250
259
|
metadata = await readJsonFile({ path: preparePath(params.metadataPath) });
|
|
251
260
|
}
|
|
252
|
-
const writeCredentials = storage
|
|
253
|
-
? {
|
|
254
|
-
bucket: storage.bucket,
|
|
255
|
-
prefix: joinPaths(storage.prefix, remotePath),
|
|
256
|
-
token: storage.storjCredentials.writeAccessToken,
|
|
257
|
-
}
|
|
258
|
-
: {
|
|
259
|
-
accessKeyId: storage.s3Credentials.writeAccessKeyId,
|
|
260
|
-
bucket: storage.bucket,
|
|
261
|
-
endpoint: S3_ENDPOINT,
|
|
262
|
-
prefix: joinPaths(storage.prefix, remotePath),
|
|
263
|
-
secretKey: storage.s3Credentials.writeSecretAccessKey,
|
|
264
|
-
};
|
|
265
|
-
const readCredentials = storage.storageType === StorageType.StorJ
|
|
266
|
-
? {
|
|
267
|
-
bucket: storage.bucket,
|
|
268
|
-
prefix: joinPaths(storage.prefix, remotePath),
|
|
269
|
-
token: storage.storjCredentials.readAccessToken,
|
|
270
|
-
}
|
|
271
|
-
: {
|
|
272
|
-
accessKeyId: storage.s3Credentials.readAccessKeyId,
|
|
273
|
-
bucket: storage.bucket,
|
|
274
|
-
endpoint: S3_ENDPOINT,
|
|
275
|
-
prefix: joinPaths(storage.prefix, remotePath),
|
|
276
|
-
secretKey: storage.s3Credentials.readSecretAccessKey,
|
|
277
|
-
};
|
|
261
|
+
const { readCredentials, writeCredentials } = this.getStorageCredentials(storage, remotePath);
|
|
278
262
|
const info = await fs.stat(params.localPath);
|
|
279
263
|
let { localPath } = params;
|
|
280
264
|
let sourcePath;
|
|
@@ -283,6 +267,7 @@ export class StorageService {
|
|
|
283
267
|
localPath = dirname(localPath);
|
|
284
268
|
}
|
|
285
269
|
try {
|
|
270
|
+
this.logger.info('Starting upload');
|
|
286
271
|
const uploadResult = await upload(localPath, {
|
|
287
272
|
credentials: writeCredentials,
|
|
288
273
|
filepath: '',
|
|
@@ -301,15 +286,54 @@ export class StorageService {
|
|
|
301
286
|
...metadata,
|
|
302
287
|
...uploadResult,
|
|
303
288
|
};
|
|
304
|
-
await fs.writeFile(resourceFilePath, JSON.stringify(result, null, 2));
|
|
289
|
+
await fs.writeFile(resourceFilePath, JSON.stringify(result, null, 2), { flag: 'wx' });
|
|
305
290
|
this.logger.info(`Resource file was created in ${resourceFilePath}`);
|
|
306
291
|
}
|
|
307
292
|
catch (error) {
|
|
308
|
-
this.logger.error({ err: error }, '
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
293
|
+
this.logger.error({ err: error }, 'Something went wrong with upload');
|
|
294
|
+
throw error;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
getStorageCredentials(storage, remotePath) {
|
|
298
|
+
if (storage.storageType === StorageType.StorJ) {
|
|
299
|
+
const { readAccessToken, writeAccessToken } = storage.storjCredentials || {};
|
|
300
|
+
if (!writeAccessToken || !readAccessToken) {
|
|
301
|
+
throw new StorageError('StorJ credentials are missing or incomplete');
|
|
302
|
+
}
|
|
303
|
+
return {
|
|
304
|
+
readCredentials: {
|
|
305
|
+
bucket: storage.bucket,
|
|
306
|
+
prefix: joinPaths(storage.prefix, remotePath),
|
|
307
|
+
token: readAccessToken,
|
|
308
|
+
}, writeCredentials: {
|
|
309
|
+
bucket: storage.bucket,
|
|
310
|
+
prefix: joinPaths(storage.prefix, remotePath),
|
|
311
|
+
token: writeAccessToken,
|
|
312
|
+
},
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
if (storage.storageType === StorageType.S3) {
|
|
316
|
+
const { readAccessKeyId, readSecretAccessKey, writeAccessKeyId, writeSecretAccessKey } = storage.s3Credentials || {};
|
|
317
|
+
if (!writeAccessKeyId || !writeSecretAccessKey || !readAccessKeyId || !readSecretAccessKey) {
|
|
318
|
+
throw new StorageError('S3 credentials are missing or incomplete');
|
|
319
|
+
}
|
|
320
|
+
return {
|
|
321
|
+
readCredentials: {
|
|
322
|
+
accessKeyId: readAccessKeyId,
|
|
323
|
+
bucket: storage.bucket,
|
|
324
|
+
endpoint: S3_ENDPOINT,
|
|
325
|
+
prefix: joinPaths(storage.prefix, remotePath),
|
|
326
|
+
secretKey: readSecretAccessKey,
|
|
327
|
+
}, writeCredentials: {
|
|
328
|
+
accessKeyId: writeAccessKeyId,
|
|
329
|
+
bucket: storage.bucket,
|
|
330
|
+
endpoint: S3_ENDPOINT,
|
|
331
|
+
prefix: joinPaths(storage.prefix, remotePath),
|
|
332
|
+
secretKey: writeSecretAccessKey,
|
|
333
|
+
},
|
|
334
|
+
};
|
|
312
335
|
}
|
|
336
|
+
throw new StorageError(`Unknown storage type: ${storage.storageType}`);
|
|
313
337
|
}
|
|
314
338
|
}
|
|
315
339
|
__decorate([
|
package/dist/utils/progress.js
CHANGED
|
@@ -2,6 +2,7 @@ import * as p from '@clack/prompts';
|
|
|
2
2
|
export const createProgressPrinter = ({ action, done = 'completed', start, }) => {
|
|
3
3
|
const progressBars = {};
|
|
4
4
|
let lastKey = '';
|
|
5
|
+
let lastProgress = 0;
|
|
5
6
|
const getProgress = (key) => {
|
|
6
7
|
if (key in progressBars) {
|
|
7
8
|
lastKey = key;
|
|
@@ -9,6 +10,7 @@ export const createProgressPrinter = ({ action, done = 'completed', start, }) =>
|
|
|
9
10
|
}
|
|
10
11
|
if (lastKey in progressBars) {
|
|
11
12
|
const progressBar = progressBars[lastKey];
|
|
13
|
+
lastProgress = 0;
|
|
12
14
|
progressBar.stop(`${action} ${lastKey} ${done}`);
|
|
13
15
|
}
|
|
14
16
|
const progressBar = p.progress({ size: 100, style: 'block' });
|
|
@@ -16,11 +18,17 @@ export const createProgressPrinter = ({ action, done = 'completed', start, }) =>
|
|
|
16
18
|
progressBars[key] = progressBar;
|
|
17
19
|
return progressBar;
|
|
18
20
|
};
|
|
19
|
-
const finish = () =>
|
|
21
|
+
const finish = () => {
|
|
22
|
+
if (lastKey && progressBars[lastKey]) {
|
|
23
|
+
lastProgress = 0;
|
|
24
|
+
progressBars[lastKey].stop(`${action} ${lastKey} ${done}`);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
20
27
|
return {
|
|
21
28
|
advance(key, num, message) {
|
|
22
29
|
const progress = getProgress(key);
|
|
23
|
-
progress.advance(num, message);
|
|
30
|
+
progress.advance(num - lastProgress, message);
|
|
31
|
+
lastProgress = num;
|
|
24
32
|
},
|
|
25
33
|
finish,
|
|
26
34
|
};
|
package/oclif.manifest.json
CHANGED
|
@@ -426,7 +426,7 @@
|
|
|
426
426
|
"required": true
|
|
427
427
|
}
|
|
428
428
|
},
|
|
429
|
-
"description": "Download file or directory described in resource
|
|
429
|
+
"description": "Download file or directory described in resource file",
|
|
430
430
|
"examples": [
|
|
431
431
|
"<%= config.bin %> <%= command.id %> ./resource.json ./pathToDownload "
|
|
432
432
|
],
|
|
@@ -448,7 +448,7 @@
|
|
|
448
448
|
"type": "option"
|
|
449
449
|
},
|
|
450
450
|
"maximum-concurrent": {
|
|
451
|
-
"description": "Maximum concurrent pieces to
|
|
451
|
+
"description": "Maximum concurrent pieces to download at once per transfer",
|
|
452
452
|
"name": "maximum-concurrent",
|
|
453
453
|
"default": 1,
|
|
454
454
|
"hasDynamicHelp": false,
|
|
@@ -482,7 +482,7 @@
|
|
|
482
482
|
"required": true
|
|
483
483
|
}
|
|
484
484
|
},
|
|
485
|
-
"description": "Upload
|
|
485
|
+
"description": "Upload file or directory to remote storage",
|
|
486
486
|
"examples": [
|
|
487
487
|
"<%= config.bin %> <%= command.id %> ./file.txt"
|
|
488
488
|
],
|
|
@@ -733,5 +733,5 @@
|
|
|
733
733
|
]
|
|
734
734
|
}
|
|
735
735
|
},
|
|
736
|
-
"version": "0.0.2-beta.
|
|
736
|
+
"version": "0.0.2-beta.17"
|
|
737
737
|
}
|