File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change @@ -134,10 +134,19 @@ export default class ParseFile {
134
134
* Gets the url of the file. It is only available after you save the file or
135
135
* after you get the file from a Parse.Object.
136
136
* @method url
137
+ * @param {Object } options An object to specify url options
137
138
* @return {String }
138
139
*/
139
- url ( ) : ?string {
140
- return this . _url ;
140
+ url ( options ?: { forceSecure ?: boolean } ) : ?string {
141
+ options = options || { } ;
142
+ if ( ! this . _url ) {
143
+ return ;
144
+ }
145
+ if ( options . forceSecure ) {
146
+ return this . _url . replace ( / ^ h t t p : \/ \/ / i, 'https://' ) ;
147
+ } else {
148
+ return this . _url ;
149
+ }
141
150
}
142
151
143
152
/**
Original file line number Diff line number Diff line change @@ -78,6 +78,20 @@ describe('ParseFile', () => {
78
78
} ) . toThrow ( 'Cannot create a Parse.File with that data.' ) ;
79
79
} ) ;
80
80
81
+ it ( 'returns secure url when specified' , ( ) => {
82
+ var file = new ParseFile ( 'parse.txt' , { base64 : 'ParseA==' } ) ;
83
+ file . save ( ) . then ( function ( result ) {
84
+ expect ( result ) . toBe ( file ) ;
85
+ expect ( result . url ( { forceSecure : true } ) )
86
+ . toBe ( 'https://files.parsetfss.com/a/parse.txt' ) ;
87
+ } ) ;
88
+ } ) ;
89
+
90
+ it ( 'returns undefined when there is no url' , ( ) => {
91
+ var file = new ParseFile ( 'parse.txt' , { base64 : 'ParseA==' } ) ;
92
+ expect ( file . url ( { forceSecure : true } ) ) . toBeUndefined ( ) ;
93
+ } ) ;
94
+
81
95
it ( 'updates fields when saved' , ( ) => {
82
96
var file = new ParseFile ( 'parse.txt' , { base64 : 'ParseA==' } ) ;
83
97
expect ( file . name ( ) ) . toBe ( 'parse.txt' ) ;
You can’t perform that action at this time.
0 commit comments