Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
downloadImages() {
console.log('download\t', 'connecting to dropbox');
new Dropbox({
fetch: fetch,
accessToken: this.dropBoxAccessToken
})
.filesListFolder({
path: this.dropBoxPath,
})
.then((response) => {
this._pending = response.entries.length;
if (this.pending) {
this.explode(response.entries);
} else {
this.emit('complete', {
status: 'complete'
});
}
})
this.log(`Validating access token ${accessToken}`);
try {
await this.dbx.filesListFolder({
path: '',
limit: 1,
});
this.log(`Access token is valid: ${accessToken}`);
return;
} catch (e) {
this.log(`Access token is invalid, clearing: ${accessToken}`);
this.accessToken = null;
}
}
this.log('Constructing unauthenticated Dropbox SDK client');
this.dbx = new DropboxSdk({
clientId: environment.dropboxApiKey,
fetch,
});
}
private async initSdk() {
let {accessToken} = this;
if (accessToken) {
this.log('Constructing authenticated Dropbox SDK client');
this.dbx = new DropboxSdk({
clientId: environment.dropboxApiKey,
accessToken,
fetch,
});
this.log(`Validating access token ${accessToken}`);
try {
await this.dbx.filesListFolder({
path: '',
limit: 1,
});
this.log(`Access token is valid: ${accessToken}`);
return;
} catch (e) {
this.log(`Access token is invalid, clearing: ${accessToken}`);
this.accessToken = null;
}
export function _authorizeDropbox(
appKey: string,
redirectURI: string
): Promise {
const dropboxAPI = new Dropbox({ clientId: appKey });
const url = dropboxAPI.getAuthenticationUrl(redirectURI);
return authorize(url).then(returnUrl => {
const params
= parseURLParams(parseStandardURIString(returnUrl), true) || {};
return params.access_token;
});
}
export function* getDropboxGalleries() {
const accessToken = process.env.HISTORY_DROPBOX_ACCESS_TOKEN;
const dbx = new Dropbox({ accessToken });
try {
const galleries = yield call([dbx, dbx.filesListFolder], { path: '/public' });
yield put(galleriesLoaded(galleries));
} catch (error) {
yield put(galleriesLoadingError(error));
}
}
constructor ({ accessToken, localRootDir }) {
this.dbx = new Dropbox({ accessToken })
this.localRootDir = localRootDir
}
export function getDisplayName(token: string, appKey: string) {
const dropboxAPI = new Dropbox({
accessToken: token,
clientId: appKey
});
return (
dropboxAPI.usersGetCurrentAccount()
.then(account => account.name.display_name));
}
authenticate.route("/redirect").get(function(req, res) {
var callback, key, secret, authentication_url;
callback = req.protocol + "://" + req.get("host") + req.baseUrl;
if (req.query.full_access) {
key = config.dropbox.full.key;
secret = config.dropbox.full.secret;
callback += "?full_access=true";
} else {
key = config.dropbox.app.key;
secret = config.dropbox.app.secret;
}
var client = new Dropbox({
clientId: key,
secret: secret
});
authentication_url = client.getAuthenticationUrl(callback, null, "code");
authentication_url = authentication_url.replace(
"response_type=token",
"response_type=code"
);
debug("Redirecting", req.blog.id, "authentication_url");
res.redirect(authentication_url);
});