Skip to content

Commit 6adbeba

Browse files
committed
Add useMasterKey option to Parse.File.destroy()
1 parent a6bbd49 commit 6adbeba

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/ParseFile.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,14 +323,23 @@ class ParseFile {
323323
* Deletes the file from the Parse cloud.
324324
* In Cloud Code and Node only with Master Key.
325325
*
326+
* @param {object} options
327+
* * Valid options are:<ul>
328+
* <li>useMasterKey: In Cloud Code and Node only, causes the Master Key to
329+
* be used for this request.
330+
* <pre>
326331
* @returns {Promise} Promise that is resolved when the delete finishes.
327332
*/
328-
destroy() {
333+
destroy(options?: FullOptions = {}) {
329334
if (!this._name) {
330335
throw new ParseError(ParseError.FILE_DELETE_UNNAMED_ERROR, 'Cannot delete an unnamed file.');
331336
}
337+
const destroyOptions = { useMasterKey: true };
338+
if (options.hasOwnProperty('useMasterKey')) {
339+
destroyOptions.useMasterKey = options.useMasterKey;
340+
}
332341
const controller = CoreManager.getFileController();
333-
return controller.deleteFile(this._name).then(() => {
342+
return controller.deleteFile(this._name, destroyOptions).then(() => {
334343
this._data = null;
335344
this._requestTask = null;
336345
return this;
@@ -540,11 +549,13 @@ const DefaultController = {
540549
});
541550
},
542551

543-
deleteFile: function (name) {
552+
deleteFile: function (name: string, options?: FullOptions) {
544553
const headers = {
545554
'X-Parse-Application-ID': CoreManager.get('APPLICATION_ID'),
546-
'X-Parse-Master-Key': CoreManager.get('MASTER_KEY'),
547555
};
556+
if (options.useMasterKey) {
557+
headers['X-Parse-Master-Key'] = CoreManager.get('MASTER_KEY');
558+
}
548559
let url = CoreManager.get('SERVER_URL');
549560
if (url[url.length - 1] !== '/') {
550561
url += '/';

0 commit comments

Comments
 (0)