mirror of
https://github.com/thinkjs/thinkjs.git
synced 2026-01-25 14:42:47 +00:00
Optimize download method
This commit is contained in:
parent
587b459a96
commit
b8e5df6703
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user