Fix:Sanitize new podcast folder names and ensure feedUrl is in feed metadata #589

This commit is contained in:
advplyr 2022-05-13 17:13:58 -05:00
parent 578a946ca5
commit 113026ce13
4 changed files with 17 additions and 5 deletions

View File

@ -151,7 +151,7 @@ export default {
this.fullPath = '' this.fullPath = ''
return return
} }
this.fullPath = Path.join(this.selectedFolderPath, this.podcast.title) this.fullPath = Path.join(this.selectedFolderPath, this.$sanitizeFilename(this.podcast.title))
}, },
submit() { submit() {
const podcastPayload = { const podcastPayload = {

View File

@ -114,10 +114,11 @@ Vue.prototype.$calculateTextSize = (text, styles = {}) => {
} }
} }
Vue.prototype.$sanitizeFilename = (input, replacement = '') => { Vue.prototype.$sanitizeFilename = (input, colonReplacement = ' - ') => {
if (typeof input !== 'string') { if (typeof input !== 'string') {
return false return false
} }
var replacement = ''
var illegalRe = /[\/\?<>\\:\*\|"]/g; var illegalRe = /[\/\?<>\\:\*\|"]/g;
var controlRe = /[\x00-\x1f\x80-\x9f]/g; var controlRe = /[\x00-\x1f\x80-\x9f]/g;
var reservedRe = /^\.+$/; var reservedRe = /^\.+$/;
@ -125,6 +126,7 @@ Vue.prototype.$sanitizeFilename = (input, replacement = '') => {
var windowsTrailingRe = /[\. ]+$/; var windowsTrailingRe = /[\. ]+$/;
var sanitized = input var sanitized = input
.replace(':', colonReplacement) // Replace first occurrence of a colon
.replace(illegalRe, replacement) .replace(illegalRe, replacement)
.replace(controlRe, replacement) .replace(controlRe, replacement)
.replace(reservedRe, replacement) .replace(reservedRe, replacement)

View File

@ -1,9 +1,10 @@
const axios = require('axios') const axios = require('axios')
const fs = require('fs-extra') const fs = require('fs-extra')
const Path = require('path')
const Logger = require('../Logger') const Logger = require('../Logger')
const { parsePodcastRssFeedXml } = require('../utils/podcastUtils') const { parsePodcastRssFeedXml } = require('../utils/podcastUtils')
const LibraryItem = require('../objects/LibraryItem') const LibraryItem = require('../objects/LibraryItem')
const { getFileTimestampsWithIno } = require('../utils/fileUtils') const { getFileTimestampsWithIno, sanitizeFilename } = require('../utils/fileUtils')
const filePerms = require('../utils/filePerms') const filePerms = require('../utils/filePerms')
class PodcastController { class PodcastController {
@ -107,6 +108,12 @@ class PodcastController {
if (!payload) { if (!payload) {
return res.status(500).send('Invalid podcast RSS feed') return res.status(500).send('Invalid podcast RSS feed')
} }
if (!payload.podcast.metadata.feedUrl) {
// Not every RSS feed will put the feed url in their metadata
payload.podcast.metadata.feedUrl = url
}
res.json(payload) res.json(payload)
}).catch((error) => { }).catch((error) => {
console.error('Failed', error) console.error('Failed', error)

View File

@ -176,17 +176,20 @@ module.exports.downloadFile = async (url, filepath) => {
}) })
} }
module.exports.sanitizeFilename = (filename, replacement = '') => { module.exports.sanitizeFilename = (filename, colonReplacement = ' - ') => {
if (typeof filename !== 'string') { if (typeof filename !== 'string') {
return false return false
} }
var replacement = ''
var illegalRe = /[\/\?<>\\:\*\|"]/g; var illegalRe = /[\/\?<>\\:\*\|"]/g;
var controlRe = /[\x00-\x1f\x80-\x9f]/g; var controlRe = /[\x00-\x1f\x80-\x9f]/g;
var reservedRe = /^\.+$/; var reservedRe = /^\.+$/;
var windowsReservedRe = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i; var windowsReservedRe = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i;
var windowsTrailingRe = /[\. ]+$/; var windowsTrailingRe = /[\. ]+$/;
var sanitized = filename sanitized = filename
.replace(':', colonReplacement) // Replace first occurrence of a colon
.replace(illegalRe, replacement) .replace(illegalRe, replacement)
.replace(controlRe, replacement) .replace(controlRe, replacement)
.replace(reservedRe, replacement) .replace(reservedRe, replacement)