Skip to content

Commit f7e79c7

Browse files
committed
VFS: Dropbox now supports find() (#28)
1 parent 9a76a61 commit f7e79c7

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

src/client/javascript/vfs/transports/dropbox.js

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
// https://github.com/dropbox/dropbox-sdk-js/blob/master/examples/javascript/auth/index.html
3333
// http://dropbox.github.io/dropbox-sdk-js/Dropbox.html
3434

35-
// TODO: find()
36-
3735
import Promise from 'bluebird';
3836
import Transport from 'vfs/transport';
3937
import Preloader from 'utils/preloader';
@@ -44,6 +42,7 @@ import {_} from 'core/locales';
4442
import * as FS from 'utils/fs';
4543

4644
const AUTH_TIMEOUT = (1000 * 30);
45+
const MAX_RESULTS = 100;
4746

4847
///////////////////////////////////////////////////////////////////////////////
4948
// TRANSPORTER
@@ -160,6 +159,35 @@ export default class DropboxTransport extends Transport {
160159
});
161160
}
162161

162+
_createMetadata(root, iter) {
163+
return {
164+
id: iter.id,
165+
filename: iter.name,
166+
path: FS.pathJoin(root, iter.path_display),
167+
type: iter['.tag'] === 'folder' ? 'dir' : 'file',
168+
size: iter.size || 0
169+
};
170+
}
171+
172+
find(file, options, a, mount) {
173+
const root = FS.getPathFromVirtual(file.path);
174+
175+
return new Promise((resolve, reject) => {
176+
this.dbx.filesSearch({
177+
path: root === '/' ? '' : root,
178+
query: options.query,
179+
max_results: MAX_RESULTS,
180+
mode: {
181+
'.tag': 'filename'
182+
}
183+
}).then((response) => {
184+
return resolve(response.matches.map((iter) => {
185+
return this._createMetadata(mount.option('root'), iter.metadata);
186+
}));
187+
}).catch(reject);
188+
});
189+
}
190+
163191
scandir(item, options, mount) {
164192
const root = FS.getPathFromVirtual(item.path);
165193

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

172200
this.dbx[m](a).then((response) => {
173201
const found = (response.entries || []).map((iter) => {
174-
return {
175-
id: iter.id,
176-
filename: iter.name,
177-
path: FS.pathJoin(item.path, iter.name),
178-
type: iter['.tag'] === 'folder' ? 'dir' : 'file',
179-
size: iter.size || 0
180-
};
202+
return this._createMetadata(mount.option('root'), iter);
181203
});
182204

183205
result = result.concat(found);
@@ -199,7 +221,6 @@ export default class DropboxTransport extends Transport {
199221
this.dbx.sharingGetSharedLinkFile({
200222
url
201223
}).then((data) => {
202-
console.error(data);
203224
return resolve(data.fileBlob);
204225
}).catch(reject);
205226
}).catch(reject);

0 commit comments

Comments
 (0)