Merge pull request #57 from Disre/patch-3

Delete thumbnails when file deletes
This commit is contained in:
Kana 2017-10-02 03:03:29 -03:00 committed by GitHub
commit 84a8449d37

View File

@ -232,17 +232,26 @@ uploadsController.delete = function(req, res) {
}
uploadsController.deleteFile = function(file) {
const ext = path.extname(file).toLowerCase()
return new Promise(function(resolve, reject) {
fs.stat(path.join(__dirname, '..', config.uploads.folder, file), function(err, stats) {
if (err) { return reject(err) }
fs.unlink(path.join(__dirname, '..', config.uploads.folder, file), function(err) {
if (err) { return reject(err) }
return resolve()
if(!utils.imageExtensions.includes(ext) && !utils.videoExtensions.includes(ext)) {
return resolve()
}
file = file.substr(0, file.lastIndexOf(".")) + ".png"
fs.stat(path.join(__dirname, '..', config.uploads.folder, "thumbs/", file), function(err, stats) {
if (err) { return reject(err) }
fs.unlink(path.join(__dirname, '..', config.uploads.folder, "thumbs/", file), function(err) {
if (err) { return reject(err) }
return resolve()
})
})
})
})
})
}
uploadsController.list = function(req, res) {