mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-06-24 09:49:24 +02:00
Add new api route for downloading backup, remove static metadata route
This commit is contained in:
parent
5b0d105e21
commit
aeba7674f8
5 changed files with 33 additions and 17 deletions
|
@ -14,18 +14,14 @@ class BackupController {
|
|||
}
|
||||
|
||||
async delete(req, res) {
|
||||
var backup = this.backupManager.backups.find(b => b.id === req.params.id)
|
||||
if (!backup) {
|
||||
return res.sendStatus(404)
|
||||
}
|
||||
await this.backupManager.removeBackup(backup)
|
||||
await this.backupManager.removeBackup(req.backup)
|
||||
|
||||
res.json({
|
||||
backups: this.backupManager.backups.map(b => b.toJSON())
|
||||
})
|
||||
}
|
||||
|
||||
async upload(req, res) {
|
||||
upload(req, res) {
|
||||
if (!req.files.file) {
|
||||
Logger.error('[BackupController] Upload backup invalid')
|
||||
return res.sendStatus(500)
|
||||
|
@ -33,12 +29,22 @@ class BackupController {
|
|||
this.backupManager.uploadBackup(req, res)
|
||||
}
|
||||
|
||||
async apply(req, res) {
|
||||
var backup = this.backupManager.backups.find(b => b.id === req.params.id)
|
||||
if (!backup) {
|
||||
return res.sendStatus(404)
|
||||
/**
|
||||
* api/backups/:id/download
|
||||
*
|
||||
* @param {*} req
|
||||
* @param {*} res
|
||||
*/
|
||||
download(req, res) {
|
||||
if (global.XAccel) {
|
||||
Logger.debug(`Use X-Accel to serve static file ${req.backup.fullPath}`)
|
||||
return res.status(204).header({ 'X-Accel-Redirect': global.XAccel + req.backup.fullPath }).send()
|
||||
}
|
||||
await this.backupManager.requestApplyBackup(backup)
|
||||
res.sendFile(req.backup.fullPath)
|
||||
}
|
||||
|
||||
async apply(req, res) {
|
||||
await this.backupManager.requestApplyBackup(req.backup)
|
||||
res.sendStatus(200)
|
||||
}
|
||||
|
||||
|
@ -47,6 +53,14 @@ class BackupController {
|
|||
Logger.error(`[BackupController] Non-admin user attempting to access backups`, req.user)
|
||||
return res.sendStatus(403)
|
||||
}
|
||||
|
||||
if (req.params.id) {
|
||||
req.backup = this.backupManager.backups.find(b => b.id === req.params.id)
|
||||
if (!req.backup) {
|
||||
return res.sendStatus(404)
|
||||
}
|
||||
}
|
||||
|
||||
next()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue