diff --git a/admin/controller/upload.js b/admin/controller/upload.js index 510078f..e2ebbaf 100644 --- a/admin/controller/upload.js +++ b/admin/controller/upload.js @@ -34,12 +34,14 @@ class Upload extends Base const cfg_width = parseInt(this.site.img_width) || 0; const cfg_height = parseInt(this.site.img_height) || 0; + image.quality(80); + // 限制图片大小 if((cfg_width && image.getWidth() > cfg_width) || (cfg_height && image.getHeight() > cfg_height)) { if(image.getWidth() > this.site.img_width && image.getWidth() / image.getHeight() > cfg_width / cfg_height) { - await image.resize(cfg_width, jimp.AUTO); + image.resize(cfg_width, jimp.AUTO); } else { - await image.resize(jimp.AUTO, cfg_height); + image.resize(jimp.AUTO, cfg_height); } await image.writeAsync(img_path); } @@ -50,7 +52,7 @@ class Upload extends Base const thumb_height = parseInt(this.site.thumb_height) || 0; if((thumb_width && image.getWidth() > thumb_width) || (thumb_height && image.getHeight() > thumb_height)) { thumb_path = thumb_path.replace('.' + result.extname, '_lit.' + result.extname); - await image.resize(thumb_width, thumb_height); + image.cover(thumb_width, thumb_height); await image.writeAsync(thumb_path); } @@ -100,8 +102,8 @@ class Upload extends Base if(thumb_path != img_path && utils.fs.isFileSync(thumb_path)) { await utils.fs.unlink(thumb_path); } - await this.$model.upload.delete({id}); + this.$success('删除成功!', 'index'); } catch(e) { this.$error('删除失败!');