Skip to content

Commit

Permalink
VFS: Dropbox now supports find() (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
andersevenrud committed Aug 22, 2017
1 parent 9a76a61 commit f7e79c7
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions src/client/javascript/vfs/transports/dropbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
// https://github.com/dropbox/dropbox-sdk-js/blob/master/examples/javascript/auth/index.html
// http://dropbox.github.io/dropbox-sdk-js/Dropbox.html

// TODO: find()

import Promise from 'bluebird';
import Transport from 'vfs/transport';
import Preloader from 'utils/preloader';
Expand All @@ -44,6 +42,7 @@ import {_} from 'core/locales';
import * as FS from 'utils/fs';

const AUTH_TIMEOUT = (1000 * 30);
const MAX_RESULTS = 100;

///////////////////////////////////////////////////////////////////////////////
// TRANSPORTER
Expand Down Expand Up @@ -160,6 +159,35 @@ export default class DropboxTransport extends Transport {
});
}

_createMetadata(root, iter) {
return {
id: iter.id,
filename: iter.name,
path: FS.pathJoin(root, iter.path_display),
type: iter['.tag'] === 'folder' ? 'dir' : 'file',
size: iter.size || 0
};
}

find(file, options, a, mount) {
const root = FS.getPathFromVirtual(file.path);

return new Promise((resolve, reject) => {
this.dbx.filesSearch({
path: root === '/' ? '' : root,
query: options.query,
max_results: MAX_RESULTS,
mode: {
'.tag': 'filename'
}
}).then((response) => {
return resolve(response.matches.map((iter) => {
return this._createMetadata(mount.option('root'), iter.metadata);
}));
}).catch(reject);
});
}

scandir(item, options, mount) {
const root = FS.getPathFromVirtual(item.path);

Expand All @@ -171,13 +199,7 @@ export default class DropboxTransport extends Transport {

this.dbx[m](a).then((response) => {
const found = (response.entries || []).map((iter) => {
return {
id: iter.id,
filename: iter.name,
path: FS.pathJoin(item.path, iter.name),
type: iter['.tag'] === 'folder' ? 'dir' : 'file',
size: iter.size || 0
};
return this._createMetadata(mount.option('root'), iter);
});

result = result.concat(found);
Expand All @@ -199,7 +221,6 @@ export default class DropboxTransport extends Transport {
this.dbx.sharingGetSharedLinkFile({
url
}).then((data) => {
console.error(data);
return resolve(data.fileBlob);
}).catch(reject);
}).catch(reject);
Expand Down

0 comments on commit f7e79c7

Please sign in to comment.