|
3 | 3 |
|
4 | 4 | var Parse = require('parse/node').Parse; |
5 | 5 |
|
| 6 | +import { default as FilesController } from './Controllers/FilesController'; |
| 7 | + |
6 | 8 | // restOptions can include: |
7 | 9 | // skip |
8 | 10 | // limit |
@@ -316,35 +318,35 @@ RestQuery.prototype.replaceDontSelect = function() { |
316 | 318 | RestQuery.prototype.runFind = function() { |
317 | 319 | return this.config.database.find( |
318 | 320 | this.className, this.restWhere, this.findOptions).then((results) => { |
319 | | - if (this.className == '_User') { |
320 | | - for (var result of results) { |
321 | | - delete result.password; |
322 | | - } |
| 321 | + if (this.className == '_User') { |
| 322 | + for (var result of results) { |
| 323 | + delete result.password; |
323 | 324 | } |
| 325 | + } |
324 | 326 |
|
325 | | - updateParseFiles(this.config, results); |
| 327 | + this.config.filesController.expandFilesInObject(this.config, results); |
326 | 328 |
|
327 | | - if (this.keys) { |
328 | | - var keySet = this.keys; |
329 | | - results = results.map((object) => { |
330 | | - var newObject = {}; |
331 | | - for (var key in object) { |
332 | | - if (keySet.has(key)) { |
333 | | - newObject[key] = object[key]; |
334 | | - } |
| 329 | + if (this.keys) { |
| 330 | + var keySet = this.keys; |
| 331 | + results = results.map((object) => { |
| 332 | + var newObject = {}; |
| 333 | + for (var key in object) { |
| 334 | + if (keySet.has(key)) { |
| 335 | + newObject[key] = object[key]; |
335 | 336 | } |
336 | | - return newObject; |
337 | | - }); |
338 | | - } |
339 | | - |
340 | | - if (this.redirectClassName) { |
341 | | - for (var r of results) { |
342 | | - r.className = this.redirectClassName; |
343 | 337 | } |
| 338 | + return newObject; |
| 339 | + }); |
| 340 | + } |
| 341 | + |
| 342 | + if (this.redirectClassName) { |
| 343 | + for (var r of results) { |
| 344 | + r.className = this.redirectClassName; |
344 | 345 | } |
| 346 | + } |
345 | 347 |
|
346 | | - this.response = {results: results}; |
347 | | - }); |
| 348 | + this.response = {results: results}; |
| 349 | + }); |
348 | 350 | }; |
349 | 351 |
|
350 | 352 | // Returns a promise for whether it was successful. |
@@ -497,35 +499,6 @@ function replacePointers(object, path, replace) { |
497 | 499 | return answer; |
498 | 500 | } |
499 | 501 |
|
500 | | -// Find file references in REST-format object and adds the url key |
501 | | -// with the current mount point and app id |
502 | | -// Object may be a single object or list of REST-format objects |
503 | | -function updateParseFiles(config, object) { |
504 | | - if (object instanceof Array) { |
505 | | - object.map((obj) => updateParseFiles(config, obj)); |
506 | | - return; |
507 | | - } |
508 | | - if (typeof object !== 'object') { |
509 | | - return; |
510 | | - } |
511 | | - for (var key in object) { |
512 | | - if (object[key] && object[key]['__type'] && |
513 | | - object[key]['__type'] == 'File') { |
514 | | - var filename = object[key]['name']; |
515 | | - var encoded = encodeURIComponent(filename); |
516 | | - encoded = encoded.replace('%40', '@'); |
517 | | - if (filename.indexOf('tfss-') === 0) { |
518 | | - object[key]['url'] = 'http://files.parsetfss.com/' + |
519 | | - config.fileKey + '/' + encoded; |
520 | | - } else { |
521 | | - object[key]['url'] = config.mount + '/files/' + |
522 | | - config.applicationId + '/' + |
523 | | - encoded; |
524 | | - } |
525 | | - } |
526 | | - } |
527 | | -} |
528 | | - |
529 | 502 | // Finds a subobject that has the given key, if there is one. |
530 | 503 | // Returns undefined otherwise. |
531 | 504 | function findObjectWithKey(root, key) { |
|
0 commit comments