Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function uploadPhoto(api: {dropboxAccessToken: string}, identityIndex: number,
identityAddress: string, photoFile: any, photoIndex: number): Promise<*> {
const dbx = new Dropbox({ accessToken: api.dropboxAccessToken })
const path = getAvatarPath(identityIndex, identityAddress, photoIndex)
return new Promise((resolve, reject) => dbx.filesUpload({ path, contents: photoFile })
.then((response) => {
dbx.sharingCreateSharedLinkWithSettings({ path: response.path_lower, settings: {} })
.then((shareLinkResponse) => {
/* Appending dropbox share url with ?dl=1 returns the actual file
instead of dropbox sign up page */
const avatarUrl = `${shareLinkResponse.url.split('=')[0]}=1`
resolve(avatarUrl)
})
.catch((error) => {
reject(error)
})
})
.catch((error) => {
export default ({ apiKey = null, client = null } = {}) => {
if (!client && typeof apiKey === 'string') {
client = new Dropbox({
accessToken: apiKey
});
} else if (!client) {
throw new Error('Dropbox client or apiKey should be provided.');
}
const api = {
// fs adapter type (for downstream integrations)
[TYPE_KEY]: 'dropbox-fs',
/**
* Read a directory and list all the files and folders inside
*
* @param {String} remotePath
* @param {Object} options
* @param {Function} callback
}
} else {
returnedObject = {};
}
//Now, if there is an error with fetching localData we need to do a few things:
//1: Grab the accessToken for the storage provider and use that to make the request.
//2: If the token is expire, we need to provide a refreshToken and get a new access & refresh token.
//3: If we got new tokens, we need to store those.
//4: Fetch the appropriate file.
//TODO: It would probably be smart to use IPFS as a fallback in case of file overwriting or something drastic.
if (!returnedObject.data) {
//Dropbox
if (params.provider === "dropbox") {
//Creating a Dropbox constructor with params from the method call.
const dbx = new Dropbox({
accessToken: params.token,
fetch: fetch
});
//Make the Dropbox call here and return it to the file that's calling this function.
return dbx
.filesDownload({ path: params.filePath })
.then(response => {
console.log(response)
return response;
})
.catch(error => {
console.log(error);
return "error fetching file";
});
} else if(params.provider === 'google') {
//First we need to use the refreshToken to get a new access token.
constructor(accessToken) {
this._token = accessToken || null;
this._client = (accessToken) ?
new Dropbox({ accessToken }) :
new Dropbox({
clientId: "5fstmwjaisrt06t"
});
}
function deleteProfile(api: {dropboxAccessToken: string}, identityIndex: number,
identityAddress: string): Promise<*> {
const dbx = new Dropbox({ accessToken: api.dropboxAccessToken })
const path = getProfilePath(identityIndex, identityAddress)
return dbx.filesDelete({ path })
}
saveToDropbox(id, url) {
this.handleShowSnackbar("Saving to Dropbox...", 500);
const { accessToken } = this.state;
const dropbox = new Dropbox({ accessToken });
dropbox.filesSaveUrl({ path: `/photo-${id}.jpg`, url: url })
.then(response => this.handleShowSnackbar("Image saved to your Dropbox successfully"))
.catch(error => this.handleShowSnackbar("Oops an error occured. Please check your internet connection"))
}
function deletePhoto(api: {dropboxAccessToken: string}, identityIndex: number,
identityAddress: string, photoIndex: number): Promise<*> {
const dbx = new Dropbox({ accessToken: api.dropboxAccessToken })
const path = getAvatarPath(identityIndex, identityAddress, photoIndex)
return dbx.filesDelete({ path })
}
export function getClient() {
if (!__client) {
__client = new Dropbox({
clientId: DROPBOX_CLIENT_ID
});
}
return __client;
}