2021-11-22 03:00:40 +01:00
|
|
|
const Logger = require('../Logger')
|
|
|
|
|
|
|
|
class BackupController {
|
|
|
|
constructor() { }
|
|
|
|
|
2022-03-18 19:44:29 +01:00
|
|
|
async create(req, res) {
|
|
|
|
if (!req.user.isRoot) {
|
|
|
|
Logger.error(`[BackupController] Non-Root user attempting to craete backup`, req.user)
|
|
|
|
return res.sendStatus(403)
|
|
|
|
}
|
|
|
|
this.backupManager.requestCreateBackup(res)
|
|
|
|
}
|
|
|
|
|
2021-11-22 03:00:40 +01:00
|
|
|
async delete(req, res) {
|
|
|
|
if (!req.user.isRoot) {
|
2022-03-18 01:10:47 +01:00
|
|
|
Logger.error(`[BackupController] Non-Root user attempting to delete backup`, req.user)
|
2021-11-22 03:00:40 +01:00
|
|
|
return res.sendStatus(403)
|
|
|
|
}
|
|
|
|
var backup = this.backupManager.backups.find(b => b.id === req.params.id)
|
|
|
|
if (!backup) {
|
|
|
|
return res.sendStatus(404)
|
|
|
|
}
|
|
|
|
await this.backupManager.removeBackup(backup)
|
|
|
|
res.json(this.backupManager.backups.map(b => b.toJSON()))
|
|
|
|
}
|
|
|
|
|
|
|
|
async upload(req, res) {
|
|
|
|
if (!req.user.isRoot) {
|
2022-03-18 01:10:47 +01:00
|
|
|
Logger.error(`[BackupController] Non-Root user attempting to upload backup`, req.user)
|
2021-11-22 03:00:40 +01:00
|
|
|
return res.sendStatus(403)
|
|
|
|
}
|
|
|
|
if (!req.files.file) {
|
2022-03-18 01:10:47 +01:00
|
|
|
Logger.error('[BackupController] Upload backup invalid')
|
2021-11-22 03:00:40 +01:00
|
|
|
return res.sendStatus(500)
|
|
|
|
}
|
|
|
|
this.backupManager.uploadBackup(req, res)
|
|
|
|
}
|
2022-03-18 19:44:29 +01:00
|
|
|
|
|
|
|
async apply(req, res) {
|
|
|
|
if (!req.user.isRoot) {
|
|
|
|
Logger.error(`[BackupController] Non-Root user attempting to apply backup`, req.user)
|
|
|
|
return res.sendStatus(403)
|
|
|
|
}
|
|
|
|
var backup = this.backupManager.backups.find(b => b.id === req.params.id)
|
|
|
|
if (!backup) {
|
|
|
|
return res.sendStatus(404)
|
|
|
|
}
|
|
|
|
await this.backupManager.requestApplyBackup(backup)
|
|
|
|
res.sendStatus(200)
|
|
|
|
}
|
2021-11-22 03:00:40 +01:00
|
|
|
}
|
|
|
|
module.exports = new BackupController()
|