mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2025-06-23 15:10:31 -04:00
Add:Cron validation api endpoint
This commit is contained in:
parent
d93d4f3236
commit
fddf850a41
@ -14,6 +14,12 @@
|
|||||||
</ui-tooltip>
|
</ui-tooltip>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- <div class="flex items-center py-2">
|
||||||
|
<ui-text-input v-model="cronExpression" :disabled="updatingServerSettings" class="w-32" @change="changedCronExpression" />
|
||||||
|
|
||||||
|
<p class="pl-4 text-lg">Cron expression</p>
|
||||||
|
</div> -->
|
||||||
|
|
||||||
<div class="flex items-center py-2">
|
<div class="flex items-center py-2">
|
||||||
<ui-text-input type="number" v-model="backupsToKeep" no-spinner :disabled="updatingServerSettings" :padding-x="1" text-center class="w-10" @change="updateBackupsSettings" />
|
<ui-text-input type="number" v-model="backupsToKeep" no-spinner :disabled="updatingServerSettings" :padding-x="1" text-center class="w-10" @change="updateBackupsSettings" />
|
||||||
|
|
||||||
@ -41,6 +47,7 @@ export default {
|
|||||||
dailyBackups: true,
|
dailyBackups: true,
|
||||||
backupsToKeep: 2,
|
backupsToKeep: 2,
|
||||||
maxBackupSize: 1,
|
maxBackupSize: 1,
|
||||||
|
// cronExpression: '',
|
||||||
newServerSettings: {}
|
newServerSettings: {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -64,6 +71,18 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
// changedCronExpression() {
|
||||||
|
// this.$axios
|
||||||
|
// .$post('/api/validate-cron', { expression: this.cronExpression })
|
||||||
|
// .then(() => {
|
||||||
|
// console.log('Cron is valid')
|
||||||
|
// })
|
||||||
|
// .catch((error) => {
|
||||||
|
// console.error('Cron validation failed', error)
|
||||||
|
// const msg = (error.response ? error.response.data : null) || 'Unknown cron validation error'
|
||||||
|
// this.$toast.error(msg)
|
||||||
|
// })
|
||||||
|
// },
|
||||||
updateBackupsSettings() {
|
updateBackupsSettings() {
|
||||||
if (isNaN(this.maxBackupSize) || this.maxBackupSize <= 0) {
|
if (isNaN(this.maxBackupSize) || this.maxBackupSize <= 0) {
|
||||||
this.$toast.error('Invalid maximum backup size')
|
this.$toast.error('Invalid maximum backup size')
|
||||||
@ -99,6 +118,7 @@ export default {
|
|||||||
this.backupsToKeep = this.newServerSettings.backupsToKeep || 2
|
this.backupsToKeep = this.newServerSettings.backupsToKeep || 2
|
||||||
this.dailyBackups = !!this.newServerSettings.backupSchedule
|
this.dailyBackups = !!this.newServerSettings.backupSchedule
|
||||||
this.maxBackupSize = this.newServerSettings.maxBackupSize || 1
|
this.maxBackupSize = this.newServerSettings.maxBackupSize || 1
|
||||||
|
// this.cronExpression = '30 1 * * *'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
@ -2,7 +2,7 @@ const Path = require('path')
|
|||||||
const fs = require('../libs/fsExtra')
|
const fs = require('../libs/fsExtra')
|
||||||
const Logger = require('../Logger')
|
const Logger = require('../Logger')
|
||||||
const filePerms = require('../utils/filePerms')
|
const filePerms = require('../utils/filePerms')
|
||||||
|
const patternValidation = require('../libs/nodeCron/pattern-validation')
|
||||||
const { isObject } = require('../utils/index')
|
const { isObject } = require('../utils/index')
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -263,5 +263,20 @@ class MiscController {
|
|||||||
})
|
})
|
||||||
res.json(tags)
|
res.json(tags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
validateCronExpression(req, res) {
|
||||||
|
const expression = req.body.expression
|
||||||
|
if (!expression) {
|
||||||
|
return res.sendStatus(400)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
patternValidation(expression)
|
||||||
|
res.sendStatus(200)
|
||||||
|
} catch (error) {
|
||||||
|
Logger.warn(`[MiscController] Invalid cron expression ${expression}`, error.message)
|
||||||
|
res.status(400).send(error.message)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
module.exports = new MiscController()
|
module.exports = new MiscController()
|
@ -211,6 +211,7 @@ class ApiRouter {
|
|||||||
this.router.get('/search/authors', MiscController.findAuthor.bind(this))
|
this.router.get('/search/authors', MiscController.findAuthor.bind(this))
|
||||||
this.router.get('/search/chapters', MiscController.findChapters.bind(this))
|
this.router.get('/search/chapters', MiscController.findChapters.bind(this))
|
||||||
this.router.get('/tags', MiscController.getAllTags.bind(this))
|
this.router.get('/tags', MiscController.getAllTags.bind(this))
|
||||||
|
this.router.post('/validate-cron', MiscController.validateCronExpression.bind(this))
|
||||||
}
|
}
|
||||||
|
|
||||||
async getDirectories(dir, relpath, excludedDirs, level = 0) {
|
async getDirectories(dir, relpath, excludedDirs, level = 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user