Skip to content

Commit 222efeb

Browse files
committed
Merge pull request #192 from jsonmaur/master
Option to specify https for Parse.File url()
2 parents 0b3f7ad + f859c76 commit 222efeb

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

src/ParseFile.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,19 @@ export default class ParseFile {
134134
* Gets the url of the file. It is only available after you save the file or
135135
* after you get the file from a Parse.Object.
136136
* @method url
137+
* @param {Object} options An object to specify url options
137138
* @return {String}
138139
*/
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(/^http:\/\//i, 'https://');
147+
} else {
148+
return this._url;
149+
}
141150
}
142151

143152
/**

src/__tests__/ParseFile-test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,20 @@ describe('ParseFile', () => {
7878
}).toThrow('Cannot create a Parse.File with that data.');
7979
});
8080

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+
8195
it('updates fields when saved', () => {
8296
var file = new ParseFile('parse.txt', { base64: 'ParseA==' });
8397
expect(file.name()).toBe('parse.txt');

0 commit comments

Comments
 (0)