mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-07-02 21:44:56 +02:00
Update:Backups API endpoints, add get all backups route, update socket init event payload
This commit is contained in:
parent
6af5ac2be1
commit
64a8a046c1
7 changed files with 67 additions and 50 deletions
|
@ -3,32 +3,29 @@ const Logger = require('../Logger')
|
|||
class BackupController {
|
||||
constructor() { }
|
||||
|
||||
async create(req, res) {
|
||||
if (!req.user.isAdminOrUp) {
|
||||
Logger.error(`[BackupController] Non-admin user attempting to craete backup`, req.user)
|
||||
return res.sendStatus(403)
|
||||
}
|
||||
getAll(req, res) {
|
||||
res.json({
|
||||
backups: this.backupManager.backups.map(b => b.toJSON())
|
||||
})
|
||||
}
|
||||
|
||||
create(req, res) {
|
||||
this.backupManager.requestCreateBackup(res)
|
||||
}
|
||||
|
||||
async delete(req, res) {
|
||||
if (!req.user.isAdminOrUp) {
|
||||
Logger.error(`[BackupController] Non-admin user attempting to delete 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.removeBackup(backup)
|
||||
res.json(this.backupManager.backups.map(b => b.toJSON()))
|
||||
|
||||
res.json({
|
||||
backups: this.backupManager.backups.map(b => b.toJSON())
|
||||
})
|
||||
}
|
||||
|
||||
async upload(req, res) {
|
||||
if (!req.user.isAdminOrUp) {
|
||||
Logger.error(`[BackupController] Non-admin user attempting to upload backup`, req.user)
|
||||
return res.sendStatus(403)
|
||||
}
|
||||
if (!req.files.file) {
|
||||
Logger.error('[BackupController] Upload backup invalid')
|
||||
return res.sendStatus(500)
|
||||
|
@ -37,10 +34,6 @@ class BackupController {
|
|||
}
|
||||
|
||||
async apply(req, res) {
|
||||
if (!req.user.isAdminOrUp) {
|
||||
Logger.error(`[BackupController] Non-admin 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)
|
||||
|
@ -48,5 +41,13 @@ class BackupController {
|
|||
await this.backupManager.requestApplyBackup(backup)
|
||||
res.sendStatus(200)
|
||||
}
|
||||
|
||||
middleware(req, res, next) {
|
||||
if (!req.user.isAdminOrUp) {
|
||||
Logger.error(`[BackupController] Non-admin user attempting to access backups`, req.user)
|
||||
return res.sendStatus(403)
|
||||
}
|
||||
next()
|
||||
}
|
||||
}
|
||||
module.exports = new BackupController()
|
Loading…
Add table
Add a link
Reference in a new issue