mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-07-06 23:45:07 +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
|
@ -159,9 +159,6 @@ class Server {
|
|||
const distPath = Path.join(global.appRoot, '/client/dist')
|
||||
router.use(express.static(distPath))
|
||||
|
||||
// Metadata folder static path
|
||||
router.use('/metadata', this.authMiddleware.bind(this), express.static(global.MetadataPath))
|
||||
|
||||
// Static folder
|
||||
router.use(express.static(Path.join(global.appRoot, 'static')))
|
||||
|
||||
|
|
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ class BackupManager {
|
|||
}
|
||||
|
||||
async init() {
|
||||
var backupsDirExists = await fs.pathExists(this.BackupPath)
|
||||
const backupsDirExists = await fs.pathExists(this.BackupPath)
|
||||
if (!backupsDirExists) {
|
||||
await fs.ensureDir(this.BackupPath)
|
||||
await filePerms.setDefault(this.BackupPath)
|
||||
|
|
|
@ -196,6 +196,7 @@ class ApiRouter {
|
|||
this.router.get('/backups', BackupController.middleware.bind(this), BackupController.getAll.bind(this))
|
||||
this.router.post('/backups', BackupController.middleware.bind(this), BackupController.create.bind(this))
|
||||
this.router.delete('/backups/:id', BackupController.middleware.bind(this), BackupController.delete.bind(this))
|
||||
this.router.get('/backups/:id/download', BackupController.middleware.bind(this), BackupController.download.bind(this))
|
||||
this.router.get('/backups/:id/apply', BackupController.middleware.bind(this), BackupController.apply.bind(this))
|
||||
this.router.post('/backups/upload', BackupController.middleware.bind(this), BackupController.upload.bind(this))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue