Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,18 @@ const IncludeGrantedScopes = ['none', 'user', 'team'];
export default class DropboxAuth {
constructor(options) {
options = options || {};
fetch = options.fetch;

if (isBrowserEnv()) {
fetch = window.fetch.bind(window);
fetch = fetch || window.fetch.bind(window);
crypto = window.crypto || window.msCrypto; // for IE11
} else if (isWorkerEnv()) {
/* eslint-disable no-restricted-globals */
fetch = self.fetch.bind(self);
fetch = fetch || self.fetch.bind(self);
crypto = self.crypto;
/* eslint-enable no-restricted-globals */
} else {
fetch = require('node-fetch'); // eslint-disable-line global-require
fetch = fetch || global.fetch || require('node-fetch'); // eslint-disable-line global-require
crypto = require('crypto'); // eslint-disable-line global-require
}

Expand All @@ -65,7 +66,7 @@ export default class DropboxAuth {
Encoder = TextEncoder;
}

this.fetch = options.fetch || fetch;
this.fetch = fetch;
this.accessToken = options.accessToken;
this.accessTokenExpiresAt = options.accessTokenExpiresAt;
this.refreshToken = options.refreshToken;
Expand Down Expand Up @@ -340,7 +341,7 @@ export default class DropboxAuth {
checkAndRefreshAccessToken() {
const canRefresh = this.getRefreshToken() && this.getClientId();
const needsRefresh = !this.getAccessTokenExpiresAt()
|| (new Date(Date.now() + TokenExpirationBuffer)) >= this.getAccessTokenExpiresAt();
|| (new Date(Date.now() + TokenExpirationBuffer)) >= this.getAccessTokenExpiresAt();
const needsToken = !this.getAccessToken();
if ((needsRefresh || needsToken) && canRefresh) {
return this.refreshAccessToken();
Expand Down
2 changes: 1 addition & 1 deletion src/dropbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default class Dropbox {
this.auth = new DropboxAuth(options);
}

this.fetch = options.fetch || this.auth.fetch;
this.fetch = this.auth.fetch;
this.selectUser = options.selectUser;
this.selectAdmin = options.selectAdmin;
this.pathRoot = options.pathRoot;
Expand Down
2 changes: 1 addition & 1 deletion src/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export function parseDownloadResponse(res) {
if (isWindowOrWorker()) {
res.blob().then((data) => resolve(data));
} else {
res.buffer().then((data) => resolve(data));
res.arrayBuffer().then((data) => resolve(Buffer.from(data)));
}
}).then((data) => {
const result = JSON.parse(res.headers.get('dropbox-api-result'));
Expand Down