Optimize download method

This commit is contained in:
welefen 2017-07-27 09:29:07 +08:00
parent 587b459a96
commit b8e5df6703

View File

@ -298,10 +298,12 @@ module.exports = {
* @param {String} filepath
* @param {String} filename
*/
download(filepath, filename) {
download(filepath, filename = path.basename(filepath)) {
assert(filepath, 'filepath can not be empty');
this.type = path.extname(filepath);
filename = filename || path.basename(filepath);
const contentType = this.response.get('Content-Type');
if (!contentType) {
this.type = path.extname(filename);
}
const contentDisposition = this.response.get('Content-Disposition');
if (!contentDisposition) {
this.attachment(filename);