diff --git a/api/routes/users.js b/api/routes/users.js index f8942ef..948b879 100644 --- a/api/routes/users.js +++ b/api/routes/users.js @@ -259,11 +259,13 @@ users.route('/:id') // check if signature exists and delete compressed and uncompressed file const fileMinified = __dirname + '/../resource/signature/' + req.params.id + '.png'; if (fs.existsSync(fileMinified)) { - fs.unlink(fileMinified); + fs.unlink(fileMinified, (err) => { + }); } const file = __dirname + '/../resource/signature/big/' + req.params.id + '.png'; if (fs.existsSync(file)) { - fs.unlink(file); + fs.unlink(file, (err) => { + }); } // we don't set res.locals.items and thus it will send a 204 (no content) at the end. see last handler user.use(..) diff --git a/api/routes/wars.js b/api/routes/wars.js index ecb4d8d..a7e2b7d 100644 --- a/api/routes/wars.js +++ b/api/routes/wars.js @@ -137,11 +137,26 @@ wars.route('/:id') return next(err); } - //TODO: add removal of resource files - - // delete players with this war ID as foreign key + // delete players having this war ID as foreign key PlayerModel.find({warId: item._id}).remove().exec(); + // check if logfiles exist and delete from fs + const warDir = __dirname + '/../resource/logs/' + req.params.id; + + if (fs.existsSync(warDir)) { + const cleanLog = warDir + '/clean.log'; + if (fs.existsSync(cleanLog)) { + fs.unlink(cleanLog, (err) => { + }); + } + const sourceLog = warDir + '/war.log'; + if (fs.existsSync(sourceLog)) { + fs.unlink(sourceLog, (err) => { + }); + } + fs.rmdir(warDir, (err) => { + }); + } // we don't set res.locals.items and thus it will send a 204 (no content) at the end. see last handler user.use(..) res.locals.processed = true; next();