File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -491,7 +491,7 @@ describe('Parse.File testing', () => {
491491 } ) ;
492492 } ) ;
493493
494- it ( 'creates correct url for old files hosted on parse ' , done => {
494+ it ( 'creates correct url for old files hosted on files.parsetfss.com ' , done => {
495495 var file = {
496496 __type : 'File' ,
497497 url : 'http://irrelevant.elephant/' ,
@@ -511,6 +511,26 @@ describe('Parse.File testing', () => {
511511 } ) ;
512512 } ) ;
513513
514+ it ( 'creates correct url for old files hosted on files.parse.com' , done => {
515+ var file = {
516+ __type : 'File' ,
517+ url : 'http://irrelevant.elephant/' ,
518+ name : 'd6e80979-a128-4c57-a167-302f874700dc-123.txt'
519+ } ;
520+ var obj = new Parse . Object ( 'OldFileTest' ) ;
521+ obj . set ( 'oldfile' , file ) ;
522+ obj . save ( ) . then ( ( ) => {
523+ var query = new Parse . Query ( 'OldFileTest' ) ;
524+ return query . first ( ) ;
525+ } ) . then ( ( result ) => {
526+ var fileAgain = result . get ( 'oldfile' ) ;
527+ expect ( fileAgain . url ( ) ) . toEqual (
528+ 'http://files.parse.com/test/d6e80979-a128-4c57-a167-302f874700dc-123.txt'
529+ ) ;
530+ done ( ) ;
531+ } ) ;
532+ } ) ;
533+
514534 it ( 'supports files in objects without urls' , done => {
515535 var file = {
516536 __type : 'File' ,
Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ import { FilesAdapter } from '../Adapters/Files/FilesAdapter';
66import path from 'path' ;
77import mime from 'mime' ;
88
9+ 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}-.*" ) ;
10+
911export class FilesController extends AdaptableController {
1012
1113 getFileData ( config , filename ) {
@@ -59,8 +61,13 @@ export class FilesController extends AdaptableController {
5961 continue ;
6062 }
6163 let filename = fileObject [ 'name' ] ;
64+ // all filenames starting with "tfss-" should be from files.parsetfss.com
65+ // all filenames starting with a "-" seperated UUID should be from files.parse.com
66+ // all other filenames have been migrated or created from Parse Server
6267 if ( filename . indexOf ( 'tfss-' ) === 0 ) {
6368 fileObject [ 'url' ] = 'http://files.parsetfss.com/' + config . fileKey + '/' + encodeURIComponent ( filename ) ;
69+ } else if ( legacyFilesRegex . test ( filename ) ) {
70+ fileObject [ 'url' ] = 'http://files.parse.com/' + config . fileKey + '/' + encodeURIComponent ( filename ) ;
6471 } else {
6572 fileObject [ 'url' ] = this . adapter . getFileLocation ( config , filename ) ;
6673 }
You can’t perform that action at this time.
0 commit comments