file DELETE support

This commit is contained in:
Wes Thomas
2016-02-10 18:42:21 -05:00
parent c66cc8d7bc
commit a75376523c
5 changed files with 142 additions and 0 deletions

View File

@@ -74,6 +74,26 @@ export class FilesController {
};
}
deleteHandler() {
return (req, res, next) => {
// enforce use of master key for file deletions
if(!req.auth.isMaster){
next(new Parse.Error(Parse.Error.OPERATION_FORBIDDEN,
'Master key required for file deletion.'));
return;
}
this._filesAdapter.deleteFile(req.config, req.params.filename).then(() => {
res.status(200);
// TODO: return useful JSON here?
res.end();
}).catch((error) => {
next(new Parse.Error(Parse.Error.FILE_DELETE_ERROR,
'Could not delete file.'));
});
};
}
/**
* Find file references in REST-format object and adds the url key
* with the current mount point and app id.
@@ -119,6 +139,12 @@ export class FilesController {
this.createHandler()
);
router.delete('/files/:filename',
Middlewares.allowCrossDomain,
Middlewares.handleParseHeaders,
this.deleteHandler()
);
return router;
}
}