Skip to content
This repository has been archived by the owner on Jun 27, 2024. It is now read-only.

Commit

Permalink
Fix download issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Akkadius committed Jan 1, 2023
1 parent c318cf3 commit a2e035d
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions app/routes/api/backup/backup.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ router.get('/:download', async function (req, res, next) {
const dateFileString = now.getFullYear() + '-' + now.getMonth() + '-' + now.getDate();
const archiveName = slugify(
util.format('(%s)-%s-%s.zip', download, dateFileString, serverLongName.toLowerCase()),
{ remove : /[*+~()'"!:@]/g }
{ remove: /[*+~()'"!:@]/g }
)

let requestedDownloadPath = '';
Expand All @@ -41,7 +41,7 @@ router.get('/:download', async function (req, res, next) {
requestedDownloadPath = './';
break;
default:
res.json({ error : 'Invalid download requested' })
res.json({ error: 'Invalid download requested' })
}

if (download === 'database') {
Expand All @@ -53,15 +53,14 @@ router.get('/:download', async function (req, res, next) {
zip.outputStream.pipe(
fs.createWriteStream(zipFile)
).on('close', function () {

if (fs.existsSync(dumpFile)) {
fs.unlinkSync(dumpFile);
}
try {
fs.unlinkSync(dumpFile);
} catch (e) {}

res.download(zipFile, path.basename(zipFile), function (err) {
if (fs.existsSync(zipFile)) {
fs.unlinkSync(zipFile);
}
try {
fs.unlinkSync(zipFile);
} catch (e) {}
});
});

Expand Down Expand Up @@ -120,20 +119,21 @@ router.get('/:download', async function (req, res, next) {
console.debug('zip file downloaded: ' + zipFile);

res.download(zipFile, path.basename(zipFile), function (err) {
if (fs.existsSync(zipFile)) {
try {
fs.unlinkSync(zipFile);
} catch (e) {
}

if (download === 'full') {
if (fs.existsSync(mysqldump.getBackupFullSqlFilePath())) {
try {
fs.unlinkSync(mysqldump.getBackupFullSqlFilePath());
} catch (e) {
}
}
});

zip.end();
});

zip.end();

}
});

Expand Down

0 comments on commit a2e035d

Please sign in to comment.