-
Notifications
You must be signed in to change notification settings - Fork 351
/
download.ts
32 lines (29 loc) · 1 KB
/
download.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { Dropbox, Error, sharing } from 'dropbox'; // eslint-disable-line no-unused-vars
import fs = require('fs');
const prompt = require('prompt');
prompt.start();
prompt.get({
properties: {
accessToken: {
description: 'Please enter an API V2 access token',
},
sharedLink: {
description: 'Please enter a shared link to a file',
},
},
}, (error: any, result: any) => {
const dbx = new Dropbox({ accessToken: result.accessToken });
dbx.sharingGetSharedLinkFile({ url: result.sharedLink })
.then((data: any) => {
// Note: The fileBinary field is not part of the Dropbox SDK
// specification, so it is not included in the TypeScript type.
// It is injected by the SDK.
fs.writeFile(data.result.name, (<any> data).result.fileBinary, { encoding: 'binary' }, (err) => {
if (err) { throw err; }
console.log(`File: ${data.result.name} saved.`);
});
})
.catch((err: Error<sharing.GetSharedLinkFileError>) => {
throw err;
});
});