mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-05-26 05:11:31 +00:00
Update podcast create/update endpoints to validate autoDownloadSchedule cron expression, validate cron expression before starting in CronManager
Some checks are pending
CodeQL / Analyze (push) Waiting to run
Run Component Tests / Run Component Tests (push) Waiting to run
Build and Push Docker Image / build (push) Waiting to run
Integration Test / build and test (push) Waiting to run
Run Unit Tests / Run Unit Tests (push) Waiting to run
Some checks are pending
CodeQL / Analyze (push) Waiting to run
Run Component Tests / Run Component Tests (push) Waiting to run
Build and Push Docker Image / build (push) Waiting to run
Integration Test / build and test (push) Waiting to run
Run Unit Tests / Run Unit Tests (push) Waiting to run
This commit is contained in:
parent
d6a2e5596b
commit
7c0ca44727
6 changed files with 31 additions and 7 deletions
|
|
@ -158,6 +158,8 @@ export default {
|
||||||
this.isProcessing = true
|
this.isProcessing = true
|
||||||
var updateResult = await this.$axios.$patch(`/api/items/${this.libraryItemId}/media`, updatePayload).catch((error) => {
|
var updateResult = await this.$axios.$patch(`/api/items/${this.libraryItemId}/media`, updatePayload).catch((error) => {
|
||||||
console.error('Failed to update', error)
|
console.error('Failed to update', error)
|
||||||
|
const errorMessage = typeof error?.response?.data === 'string' ? error?.response?.data : null
|
||||||
|
this.$toast.error(errorMessage || this.$strings.ToastFailedToUpdate)
|
||||||
return false
|
return false
|
||||||
})
|
})
|
||||||
this.isProcessing = false
|
this.isProcessing = false
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
const { Request, Response, NextFunction } = require('express')
|
const { Request, Response, NextFunction } = require('express')
|
||||||
const Path = require('path')
|
const Path = require('path')
|
||||||
const fs = require('../libs/fsExtra')
|
const fs = require('../libs/fsExtra')
|
||||||
|
const cron = require('../libs/nodeCron')
|
||||||
const uaParserJs = require('../libs/uaParser')
|
const uaParserJs = require('../libs/uaParser')
|
||||||
const Logger = require('../Logger')
|
const Logger = require('../Logger')
|
||||||
const SocketAuthority = require('../SocketAuthority')
|
const SocketAuthority = require('../SocketAuthority')
|
||||||
|
|
@ -220,6 +221,11 @@ class LibraryItemController {
|
||||||
} else if (mediaPayload.autoDownloadSchedule !== undefined && req.libraryItem.media.autoDownloadSchedule !== mediaPayload.autoDownloadSchedule) {
|
} else if (mediaPayload.autoDownloadSchedule !== undefined && req.libraryItem.media.autoDownloadSchedule !== mediaPayload.autoDownloadSchedule) {
|
||||||
isPodcastAutoDownloadUpdated = true
|
isPodcastAutoDownloadUpdated = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mediaPayload.autoDownloadSchedule && !cron.validate(mediaPayload.autoDownloadSchedule)) {
|
||||||
|
Logger.error(`[LibraryItemController] Invalid auto download schedule cron expression "${mediaPayload.autoDownloadSchedule}" for library item "${req.libraryItem.media.title}"`)
|
||||||
|
return res.status(400).send('Invalid auto download schedule cron expression')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let hasUpdates = (await req.libraryItem.media.updateFromRequest(mediaPayload)) || mediaPayload.url
|
let hasUpdates = (await req.libraryItem.media.updateFromRequest(mediaPayload)) || mediaPayload.url
|
||||||
|
|
@ -659,6 +665,11 @@ class LibraryItemController {
|
||||||
const mediaPayload = updatePayload.mediaPayload
|
const mediaPayload = updatePayload.mediaPayload
|
||||||
const libraryItem = libraryItems.find((li) => li.id === updatePayload.id)
|
const libraryItem = libraryItems.find((li) => li.id === updatePayload.id)
|
||||||
|
|
||||||
|
if (libraryItem.isPodcast && mediaPayload.autoDownloadSchedule && !cron.validate(mediaPayload.autoDownloadSchedule)) {
|
||||||
|
Logger.warn(`[LibraryItemController] Invalid auto download schedule cron expression "${mediaPayload.autoDownloadSchedule}" for library item "${libraryItem.media.title}" - skipping update`)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
let hasUpdates = await libraryItem.media.updateFromRequest(mediaPayload)
|
let hasUpdates = await libraryItem.media.updateFromRequest(mediaPayload)
|
||||||
|
|
||||||
if (libraryItem.isBook && Array.isArray(mediaPayload.metadata?.series)) {
|
if (libraryItem.isBook && Array.isArray(mediaPayload.metadata?.series)) {
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ const Database = require('../Database')
|
||||||
const Watcher = require('../Watcher')
|
const Watcher = require('../Watcher')
|
||||||
|
|
||||||
const libraryItemFilters = require('../utils/queries/libraryItemFilters')
|
const libraryItemFilters = require('../utils/queries/libraryItemFilters')
|
||||||
const patternValidation = require('../libs/nodeCron/pattern-validation')
|
const cron = require('../libs/nodeCron')
|
||||||
const { isObject, getTitleIgnorePrefix } = require('../utils/index')
|
const { isObject, getTitleIgnorePrefix } = require('../utils/index')
|
||||||
const { sanitizeFilename } = require('../utils/fileUtils')
|
const { sanitizeFilename } = require('../utils/fileUtils')
|
||||||
|
|
||||||
|
|
@ -605,13 +605,11 @@ class MiscController {
|
||||||
return res.sendStatus(400)
|
return res.sendStatus(400)
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if (!cron.validate(expression)) {
|
||||||
patternValidation(expression)
|
Logger.warn(`[MiscController] Invalid cron expression ${expression}`)
|
||||||
res.sendStatus(200)
|
return res.status(400).send('Invalid cron expression')
|
||||||
} catch (error) {
|
|
||||||
Logger.warn(`[MiscController] Invalid cron expression ${expression}`, error.message)
|
|
||||||
res.status(400).send(error.message)
|
|
||||||
}
|
}
|
||||||
|
res.sendStatus(200)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ const SocketAuthority = require('../SocketAuthority')
|
||||||
const Database = require('../Database')
|
const Database = require('../Database')
|
||||||
|
|
||||||
const fs = require('../libs/fsExtra')
|
const fs = require('../libs/fsExtra')
|
||||||
|
const cron = require('../libs/nodeCron')
|
||||||
|
|
||||||
const { getPodcastFeed, findMatchingEpisodes } = require('../utils/podcastUtils')
|
const { getPodcastFeed, findMatchingEpisodes } = require('../utils/podcastUtils')
|
||||||
const { getFileTimestampsWithIno, filePathToPOSIX, isSameOrSubPath } = require('../utils/fileUtils')
|
const { getFileTimestampsWithIno, filePathToPOSIX, isSameOrSubPath } = require('../utils/fileUtils')
|
||||||
|
|
@ -46,6 +47,11 @@ class PodcastController {
|
||||||
return res.status(400).send('Invalid request body. "media" and "media.metadata" are required')
|
return res.status(400).send('Invalid request body. "media" and "media.metadata" are required')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (payload.media.autoDownloadSchedule && !cron.validate(payload.media.autoDownloadSchedule)) {
|
||||||
|
Logger.error(`[PodcastController] Invalid auto download schedule cron expression "${payload.media.autoDownloadSchedule}"`)
|
||||||
|
return res.status(400).send('Invalid auto download schedule cron expression')
|
||||||
|
}
|
||||||
|
|
||||||
const library = await Database.libraryModel.findByIdWithFolders(payload.libraryId)
|
const library = await Database.libraryModel.findByIdWithFolders(payload.libraryId)
|
||||||
if (!library) {
|
if (!library) {
|
||||||
Logger.error(`[PodcastController] Create: Library not found "${payload.libraryId}"`)
|
Logger.error(`[PodcastController] Create: Library not found "${payload.libraryId}"`)
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,11 @@ class CronManager {
|
||||||
|
|
||||||
startPodcastCron(expression, libraryItemIds) {
|
startPodcastCron(expression, libraryItemIds) {
|
||||||
try {
|
try {
|
||||||
|
if (!cron.validate(expression)) {
|
||||||
|
Logger.error(`[CronManager] Invalid auto download schedule cron expression "${expression}" - not starting podcast episode check cron`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
Logger.debug(`[CronManager] Scheduling podcast episode check cron "${expression}" for ${libraryItemIds.length} item(s)`)
|
Logger.debug(`[CronManager] Scheduling podcast episode check cron "${expression}" for ${libraryItemIds.length} item(s)`)
|
||||||
const task = cron.schedule(expression, () => {
|
const task = cron.schedule(expression, () => {
|
||||||
if (this.podcastCronExpressionsExecuting.includes(expression)) {
|
if (this.podcastCronExpressionsExecuting.includes(expression)) {
|
||||||
|
|
|
||||||
|
|
@ -78,6 +78,7 @@ class Podcast extends Model {
|
||||||
*/
|
*/
|
||||||
static async createFromRequest(payload, transaction) {
|
static async createFromRequest(payload, transaction) {
|
||||||
const title = typeof payload.metadata.title === 'string' ? payload.metadata.title : null
|
const title = typeof payload.metadata.title === 'string' ? payload.metadata.title : null
|
||||||
|
// cron expression validated in controller
|
||||||
const autoDownloadSchedule = typeof payload.autoDownloadSchedule === 'string' ? payload.autoDownloadSchedule : null
|
const autoDownloadSchedule = typeof payload.autoDownloadSchedule === 'string' ? payload.autoDownloadSchedule : null
|
||||||
const genres = Array.isArray(payload.metadata.genres) && payload.metadata.genres.every((g) => typeof g === 'string' && g.length) ? payload.metadata.genres : []
|
const genres = Array.isArray(payload.metadata.genres) && payload.metadata.genres.every((g) => typeof g === 'string' && g.length) ? payload.metadata.genres : []
|
||||||
const tags = Array.isArray(payload.tags) && payload.tags.every((t) => typeof t === 'string' && t.length) ? payload.tags : []
|
const tags = Array.isArray(payload.tags) && payload.tags.every((t) => typeof t === 'string' && t.length) ? payload.tags : []
|
||||||
|
|
@ -273,6 +274,7 @@ class Podcast extends Model {
|
||||||
hasUpdates = true
|
hasUpdates = true
|
||||||
}
|
}
|
||||||
if (typeof payload.autoDownloadSchedule === 'string' && payload.autoDownloadSchedule !== this.autoDownloadSchedule) {
|
if (typeof payload.autoDownloadSchedule === 'string' && payload.autoDownloadSchedule !== this.autoDownloadSchedule) {
|
||||||
|
// cron expression validated in controller
|
||||||
this.autoDownloadSchedule = payload.autoDownloadSchedule
|
this.autoDownloadSchedule = payload.autoDownloadSchedule
|
||||||
hasUpdates = true
|
hasUpdates = true
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue