Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support file objects in the legacy bucket: files.parse.com #2001

Merged
merged 1 commit into from
Jun 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion spec/ParseFile.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ describe('Parse.File testing', () => {
});
});

it('creates correct url for old files hosted on parse', done => {
it('creates correct url for old files hosted on files.parsetfss.com', done => {
var file = {
__type: 'File',
url: 'http://irrelevant.elephant/',
Expand All @@ -511,6 +511,26 @@ describe('Parse.File testing', () => {
});
});

it('creates correct url for old files hosted on files.parse.com', done => {
var file = {
__type: 'File',
url: 'http://irrelevant.elephant/',
name: 'd6e80979-a128-4c57-a167-302f874700dc-123.txt'
};
var obj = new Parse.Object('OldFileTest');
obj.set('oldfile', file);
obj.save().then(() => {
var query = new Parse.Query('OldFileTest');
return query.first();
}).then((result) => {
var fileAgain = result.get('oldfile');
expect(fileAgain.url()).toEqual(
'http://files.parse.com/test/d6e80979-a128-4c57-a167-302f874700dc-123.txt'
);
done();
});
});

it('supports files in objects without urls', done => {
var file = {
__type: 'File',
Expand Down
7 changes: 7 additions & 0 deletions src/Controllers/FilesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { FilesAdapter } from '../Adapters/Files/FilesAdapter';
import path from 'path';
import mime from 'mime';

const legacyFilesRegex = new RegExp("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}-.*");

export class FilesController extends AdaptableController {

getFileData(config, filename) {
Expand Down Expand Up @@ -59,8 +61,13 @@ export class FilesController extends AdaptableController {
continue;
}
let filename = fileObject['name'];
// all filenames starting with "tfss-" should be from files.parsetfss.com
// all filenames starting with a "-" seperated UUID should be from files.parse.com
// all other filenames have been migrated or created from Parse Server
if (filename.indexOf('tfss-') === 0) {
fileObject['url'] = 'http://files.parsetfss.com/' + config.fileKey + '/' + encodeURIComponent(filename);
} else if (legacyFilesRegex.test(filename)) {
fileObject['url'] = 'http://files.parse.com/' + config.fileKey + '/' + encodeURIComponent(filename);
} else {
fileObject['url'] = this.adapter.getFileLocation(config, filename);
}
Expand Down