mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2024-11-08 09:04:43 +01:00
Add:Cron validation api endpoint
This commit is contained in:
parent
d93d4f3236
commit
fddf850a41
@ -14,6 +14,12 @@
|
||||
</ui-tooltip>
|
||||
</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">
|
||||
<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,
|
||||
backupsToKeep: 2,
|
||||
maxBackupSize: 1,
|
||||
// cronExpression: '',
|
||||
newServerSettings: {}
|
||||
}
|
||||
},
|
||||
@ -64,6 +71,18 @@ export default {
|
||||
}
|
||||
},
|
||||
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() {
|
||||
if (isNaN(this.maxBackupSize) || this.maxBackupSize <= 0) {
|
||||
this.$toast.error('Invalid maximum backup size')
|
||||
@ -99,6 +118,7 @@ export default {
|
||||
this.backupsToKeep = this.newServerSettings.backupsToKeep || 2
|
||||
this.dailyBackups = !!this.newServerSettings.backupSchedule
|
||||
this.maxBackupSize = this.newServerSettings.maxBackupSize || 1
|
||||
// this.cronExpression = '30 1 * * *'
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
|
@ -2,7 +2,7 @@ const Path = require('path')
|
||||
const fs = require('../libs/fsExtra')
|
||||
const Logger = require('../Logger')
|
||||
const filePerms = require('../utils/filePerms')
|
||||
|
||||
const patternValidation = require('../libs/nodeCron/pattern-validation')
|
||||
const { isObject } = require('../utils/index')
|
||||
|
||||
//
|
||||
@ -263,5 +263,20 @@ class MiscController {
|
||||
})
|
||||
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()
|
@ -211,6 +211,7 @@ class ApiRouter {
|
||||
this.router.get('/search/authors', MiscController.findAuthor.bind(this))
|
||||
this.router.get('/search/chapters', MiscController.findChapters.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) {
|
||||
|
Loading…
Reference in New Issue
Block a user