Skip to content

Commit

Permalink
Fix strict mode error in Firefox.
Browse files Browse the repository at this point in the history
  • Loading branch information
John Vilk committed Aug 7, 2017
1 parent 595b347 commit f837c7d
Showing 1 changed file with 29 additions and 30 deletions.
59 changes: 29 additions & 30 deletions test/harness/factories/dbfs_factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,35 @@ import {ApiError} from '../../../src/core/api_error';

declare const Dropbox: typeof DropboxTypes.Dropbox;
export default function DBFSFactory(cb: (name: string, obj: FileSystem[]) => void): void {
function login(creds: DropboxTypes.DropboxOptions) {
const client = new Dropbox(creds);
client.usersGetCurrentAccount(undefined).then((res) => {
return new Promise<DropboxFileSystem>((resolve, reject) => {
console.debug(`Successfully connected to ${res.name.display_name}'s Dropbox.`);
DropboxFileSystem.Create({ client }, (e, fs?) => {
if (fs) {
fs.empty((e) => {
if (e) {
reject(e);
} else {
resolve(fs);
}
});
} else {
reject(e);
}
});
});
}).then((fs) => {
cb("Dropbox", [fs]);
}).catch((e: DropboxTypes.Error<any> | ApiError) => {
if (e instanceof ApiError) {
throw e;
} else {
throw new Error(`Failed to log in to Dropbox: ${e.user_message.text}`);
}
});
}
if (DropboxFileSystem.isAvailable()) {
// Authenticate with pregenerated unit testing credentials.
const req = new XMLHttpRequest();
Expand All @@ -18,36 +47,6 @@ export default function DBFSFactory(cb: (name: string, obj: FileSystem[]) => voi
login(JSON.parse(req.response));
};
req.send();

function login(creds: DropboxTypes.DropboxOptions) {
const client = new Dropbox(creds);
client.usersGetCurrentAccount(undefined).then((res) => {
return new Promise<DropboxFileSystem>((resolve, reject) => {
console.debug(`Successfully connected to ${res.name.display_name}'s Dropbox.`);
DropboxFileSystem.Create({ client }, (e, fs?) => {
if (fs) {
fs.empty((e) => {
if (e) {
reject(e);
} else {
resolve(fs);
}
});
} else {
reject(e);
}
});
});
}).then((fs) => {
cb("Dropbox", [fs]);
}).catch((e: DropboxTypes.Error<any> | ApiError) => {
if (e instanceof ApiError) {
throw e;
} else {
throw new Error(`Failed to log in to Dropbox: ${e.user_message.text}`);
}
});
}
} else {
cb('Dropbox', []);
}
Expand Down

0 comments on commit f837c7d

Please sign in to comment.