File tree 2 files changed +28
-1
lines changed
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', () => {
491
491
} ) ;
492
492
} ) ;
493
493
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 => {
495
495
var file = {
496
496
__type : 'File' ,
497
497
url : 'http://irrelevant.elephant/' ,
@@ -511,6 +511,26 @@ describe('Parse.File testing', () => {
511
511
} ) ;
512
512
} ) ;
513
513
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
+
514
534
it ( 'supports files in objects without urls' , done => {
515
535
var file = {
516
536
__type : 'File' ,
Original file line number Diff line number Diff line change @@ -6,6 +6,8 @@ import { FilesAdapter } from '../Adapters/Files/FilesAdapter';
6
6
import path from 'path' ;
7
7
import mime from 'mime' ;
8
8
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
+
9
11
export class FilesController extends AdaptableController {
10
12
11
13
getFileData ( config , filename ) {
@@ -59,8 +61,13 @@ export class FilesController extends AdaptableController {
59
61
continue ;
60
62
}
61
63
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
62
67
if ( filename . indexOf ( 'tfss-' ) === 0 ) {
63
68
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 ) ;
64
71
} else {
65
72
fileObject [ 'url' ] = this . adapter . getFileLocation ( config , filename ) ;
66
73
}
You can’t perform that action at this time.
0 commit comments