Skip to content

Commit 79be1c9

Browse files
Fix types (#133)
1 parent 14f41ba commit 79be1c9

6 files changed

Lines changed: 25 additions & 222 deletions

File tree

src/cli/Commands.ts

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Command } from 'commander';
12
import { logger } from '../lib/utils/logger';
23
import { buildCommand } from './CommandInterface';
34
import { createBucket } from './create-bucket';
@@ -7,16 +8,14 @@ import { getDownloadLinks } from './get-download-links';
78
import { getFileInfo } from './get-filo-info';
89
import { renameFile } from './rename-file';
910
import { uploadFile } from './upload-file';
10-
import { uploadFileMultipart } from './upload-file-multipart';
11-
import { uploadFolder } from './upload-folder-zip';
1211

1312
function notifyProgramFinished(programName: string) {
1413
return () => {
1514
logger.info('Program "%s" finished', programName);
1615
};
1716
}
1817

19-
export const uploadFileCommand = buildCommand({
18+
export const uploadFileCommand: Command = buildCommand({
2019
version: '0.0.1',
2120
command: 'upload-file <path>',
2221
description: 'Upload a file',
@@ -25,25 +24,7 @@ export const uploadFileCommand = buildCommand({
2524
return uploadFile(path);
2625
});
2726

28-
export const uploadFileMultipartCommand = buildCommand({
29-
version: '0.0.1',
30-
command: 'upload-file-multipart <path>',
31-
description: 'Upload a file using multipart',
32-
options: [],
33-
}).action((path) => {
34-
return uploadFileMultipart(path);
35-
});
36-
37-
export const uploadFolderZipCommand = buildCommand({
38-
version: '0.0.1',
39-
command: 'upload-folder-zip <path>',
40-
description: 'Upload a folder zipped',
41-
options: [],
42-
}).action((path: string) => {
43-
uploadFolder(path).finally(notifyProgramFinished('upload-folder-zip'));
44-
});
45-
46-
export const downloadFileCommand = buildCommand({
27+
export const downloadFileCommand: Command = buildCommand({
4728
version: '0.0.1',
4829
command: 'download-file <fileId> <path>',
4930
description: 'Download a file',
@@ -52,7 +33,7 @@ export const downloadFileCommand = buildCommand({
5233
downloadFile(fileId, path, 1).finally(notifyProgramFinished('download-file'));
5334
});
5435

55-
export const downloadFileCommandParallel = buildCommand({
36+
export const downloadFileCommandParallel: Command = buildCommand({
5637
version: '0.0.1',
5738
command: 'download-file-parallel <fileId> <path>',
5839
description: 'Download a file',
@@ -61,7 +42,7 @@ export const downloadFileCommandParallel = buildCommand({
6142
downloadFile(fileId, path, 10).finally(notifyProgramFinished('download-file-parallel'));
6243
});
6344

64-
export const renameFileCommand = buildCommand({
45+
export const renameFileCommand: Command = buildCommand({
6546
version: '0.0.1',
6647
command: 'rename-file <fileId> <newName>',
6748
description: 'Renames a file in the network',
@@ -70,7 +51,7 @@ export const renameFileCommand = buildCommand({
7051
renameFile(fileId, newName).finally(notifyProgramFinished('rename-file'));
7152
});
7253

73-
export const getFileInfoCommand = buildCommand({
54+
export const getFileInfoCommand: Command = buildCommand({
7455
version: '0.0.1',
7556
command: 'get-file-info <fileId>',
7657
description: 'Gets file info',
@@ -79,7 +60,7 @@ export const getFileInfoCommand = buildCommand({
7960
getFileInfo(fileId).finally(notifyProgramFinished('get-file-info'));
8061
});
8162

82-
export const createBucketCommand = buildCommand({
63+
export const createBucketCommand: Command = buildCommand({
8364
version: '0.0.1',
8465
command: 'create-bucket <bucketName>',
8566
description: 'Creates a bucket with the given name',
@@ -88,7 +69,7 @@ export const createBucketCommand = buildCommand({
8869
createBucket(bucketName).finally(notifyProgramFinished('create-bucket'));
8970
});
9071

91-
export const deleteBucketCommand = buildCommand({
72+
export const deleteBucketCommand: Command = buildCommand({
9273
version: '0.0.1',
9374
command: 'delete-bucket <bucketId>',
9475
description: 'Deletes a bucket given its id',
@@ -97,7 +78,7 @@ export const deleteBucketCommand = buildCommand({
9778
deleteBucket(bucketId).finally(notifyProgramFinished('delete-bucket'));
9879
});
9980

100-
export const getDownloadLinksCommand = buildCommand({
81+
export const getDownloadLinksCommand: Command = buildCommand({
10182
version: '0.0.1',
10283
command: 'get-download-links <bucketId> <fileIdsSeparatedByCommas>',
10384
description: 'Gets download links of file ids',

src/cli/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import * as commands from './Commands';
77
const program = new Command();
88

99
program.addCommand(commands.uploadFileCommand);
10-
program.addCommand(commands.uploadFileMultipartCommand);
11-
program.addCommand(commands.uploadFolderZipCommand);
1210
program.addCommand(commands.downloadFileCommand);
1311
program.addCommand(commands.downloadFileCommandParallel);
1412
program.addCommand(commands.renameFileCommand);

src/cli/upload-file-multipart.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/cli/upload-file.ts

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,21 @@ export async function uploadFile(filepath: string) {
1212

1313
try {
1414
const network = getEnvironment();
15-
1615
const bucketId = EnvService.instance.get('BUCKET_ID');
16+
const abortController = new AbortController();
1717

18-
const fileId = await new Promise((resolve: (fileId: string) => void, reject) => {
19-
const state = network.upload(bucketId, {
20-
progressCallback: (progress: number) => {
21-
logger.info('Progress %s%', (progress * 100).toFixed(2));
22-
},
23-
finishedCallback: (err: Error | null, res: string | null) => {
24-
if (err) {
25-
return reject(err);
26-
} else if (!res) {
27-
return reject('No response received from Network download');
28-
}
29-
resolve(res);
30-
},
31-
fileSize: statSync(filepath).size,
32-
source: createReadStream(filepath),
33-
});
18+
process.on('SIGINT', () => {
19+
logger.info('Aborting upload');
20+
abortController.abort();
21+
});
3422

35-
process.on('SIGINT', () => {
36-
logger.info('Aborting upload');
37-
network.uploadCancel(state);
38-
});
23+
const fileId = await network.upload(bucketId, {
24+
progressCallback: (progress: number) => {
25+
logger.info('Progress %s%', (progress * 100).toFixed(2));
26+
},
27+
fileSize: statSync(filepath).size,
28+
source: createReadStream(filepath),
29+
abortSignal: abortController.signal,
3930
});
4031

4132
console.log('File %s uploaded', fileId);

src/cli/upload-folder-zip.ts

Lines changed: 0 additions & 125 deletions
This file was deleted.

tests/services/api.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@ import { expect } from 'chai';
33
import { generateShardMeta } from '../mocks';
44
import { Bridge } from '../../src/services/api';
55
import { Methods } from '../../src/lib';
6+
import { AppDetails } from '@internxt/sdk/dist/shared';
67

78
const bridgeUrl = 'https://api.internxt.com';
89
const bridgePass = 'bridgePass';
910
const bridgeUser = 'fake@user.com';
10-
const bridge = new Bridge({ bridgePass, bridgeUser, bridgeUrl });
11+
const appDetails: AppDetails = { clientName: 'clientName', clientVersion: '1.0.0' };
12+
const bridge = new Bridge({ bridgePass, bridgeUser, bridgeUrl, appDetails });
1113

1214
describe('services/api.ts', () => {
1315
describe('Bridge', () => {
1416
describe('# constructor()', () => {
1517
it('Should throw if bridge url is empty', () => {
1618
expect(() => {
17-
new Bridge({ bridgeUser: 'fake@user.com', bridgePass: 'fakePass', bridgeUrl: '' });
19+
new Bridge({ bridgeUser: 'fake@user.com', bridgePass: 'fakePass', bridgeUrl: '', appDetails });
1820
}).to.throw('Empty bridge url');
1921
});
2022
});

0 commit comments

Comments
 (0)