mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2025-01-31 15:21:33 +00:00
Merge pull request #57 from Disre/patch-3
Delete thumbnails when file deletes
This commit is contained in:
commit
84a8449d37
@ -232,17 +232,26 @@ uploadsController.delete = function(req, res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uploadsController.deleteFile = function(file) {
|
uploadsController.deleteFile = function(file) {
|
||||||
|
const ext = path.extname(file).toLowerCase()
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
fs.stat(path.join(__dirname, '..', config.uploads.folder, file), function(err, stats) {
|
fs.stat(path.join(__dirname, '..', config.uploads.folder, file), function(err, stats) {
|
||||||
if (err) { return reject(err) }
|
if (err) { return reject(err) }
|
||||||
fs.unlink(path.join(__dirname, '..', config.uploads.folder, file), function(err) {
|
fs.unlink(path.join(__dirname, '..', config.uploads.folder, file), function(err) {
|
||||||
|
if (err) { return reject(err) }
|
||||||
|
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) }
|
if (err) { return reject(err) }
|
||||||
return resolve()
|
return resolve()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
uploadsController.list = function(req, res) {
|
uploadsController.list = function(req, res) {
|
||||||
|
Loading…
Reference in New Issue
Block a user