Fix:Podcast episode match not properly encoding search query #3177

This commit is contained in:
advplyr 2024-07-18 16:43:00 -05:00
parent e925e9b23f
commit dbc7ad0b3b
3 changed files with 18 additions and 24 deletions

View File

@ -132,7 +132,7 @@ export default {
this.searchedTitle = this.episodeTitle this.searchedTitle = this.episodeTitle
this.isProcessing = true this.isProcessing = true
this.$axios this.$axios
.$get(`/api/podcasts/${this.libraryItem.id}/search-episode?title=${this.$encodeUriPath(this.episodeTitle)}`) .$get(`/api/podcasts/${this.libraryItem.id}/search-episode?title=${encodeURIComponent(this.episodeTitle)}`)
.then((results) => { .then((results) => {
this.episodesFound = results.episodes.map((ep) => ep.episode) this.episodesFound = results.episodes.map((ep) => ep.episode)
console.log('Episodes found', this.episodesFound) console.log('Episodes found', this.episodesFound)
@ -153,4 +153,4 @@ export default {
}, },
mounted() {} mounted() {}
} }
</script> </script>

View File

@ -6,7 +6,6 @@ import * as locale from 'date-fns/locale'
Vue.directive('click-outside', vClickOutside.directive) Vue.directive('click-outside', vClickOutside.directive)
Vue.prototype.$setDateFnsLocale = (localeString) => { Vue.prototype.$setDateFnsLocale = (localeString) => {
if (!locale[localeString]) return 0 if (!locale[localeString]) return 0
return setDefaultOptions({ locale: locale[localeString] }) return setDefaultOptions({ locale: locale[localeString] })
@ -112,14 +111,15 @@ Vue.prototype.$sanitizeSlug = (str) => {
str = str.toLowerCase() str = str.toLowerCase()
// remove accents, swap ñ for n, etc // remove accents, swap ñ for n, etc
var from = "àáäâèéëêìíïîòóöôùúüûñçěščřžýúůďťň·/,:;" var from = 'àáäâèéëêìíïîòóöôùúüûñçěščřžýúůďťň·/,:;'
var to = "aaaaeeeeiiiioooouuuuncescrzyuudtn-----" var to = 'aaaaeeeeiiiioooouuuuncescrzyuudtn-----'
for (var i = 0, l = from.length; i < l; i++) { for (var i = 0, l = from.length; i < l; i++) {
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i)) str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i))
} }
str = str.replace('.', '-') // replace a dot by a dash str = str
.replace('.', '-') // replace a dot by a dash
.replace(/[^a-z0-9 -_]/g, '') // remove invalid chars .replace(/[^a-z0-9 -_]/g, '') // remove invalid chars
.replace(/\s+/g, '-') // collapse whitespace and replace by a dash .replace(/\s+/g, '-') // collapse whitespace and replace by a dash
.replace(/-+/g, '-') // collapse dashes .replace(/-+/g, '-') // collapse dashes
@ -131,13 +131,16 @@ Vue.prototype.$sanitizeSlug = (str) => {
Vue.prototype.$copyToClipboard = (str, ctx) => { Vue.prototype.$copyToClipboard = (str, ctx) => {
return new Promise((resolve) => { return new Promise((resolve) => {
if (navigator.clipboard) { if (navigator.clipboard) {
navigator.clipboard.writeText(str).then(() => { navigator.clipboard.writeText(str).then(
if (ctx) ctx.$toast.success('Copied to clipboard') () => {
resolve(true) if (ctx) ctx.$toast.success('Copied to clipboard')
}, (err) => { resolve(true)
console.error('Clipboard copy failed', str, err) },
resolve(false) (err) => {
}) console.error('Clipboard copy failed', str, err)
resolve(false)
}
)
} else { } else {
const el = document.createElement('textarea') const el = document.createElement('textarea')
el.value = str el.value = str
@ -160,26 +163,18 @@ function xmlToJson(xml) {
for (const res of xml.matchAll(/(?:<(\w*)(?:\s[^>]*)*>)((?:(?!<\1).)*)(?:<\/\1>)|<(\w*)(?:\s*)*\/>/gm)) { for (const res of xml.matchAll(/(?:<(\w*)(?:\s[^>]*)*>)((?:(?!<\1).)*)(?:<\/\1>)|<(\w*)(?:\s*)*\/>/gm)) {
const key = res[1] || res[3] const key = res[1] || res[3]
const value = res[2] && xmlToJson(res[2]) const value = res[2] && xmlToJson(res[2])
json[key] = ((value && Object.keys(value).length) ? value : res[2]) || null json[key] = (value && Object.keys(value).length ? value : res[2]) || null
} }
return json return json
} }
Vue.prototype.$xmlToJson = xmlToJson Vue.prototype.$xmlToJson = xmlToJson
Vue.prototype.$encodeUriPath = (path) => {
return path.replace(/\\/g, '/').replace(/%/g, '%25').replace(/#/g, '%23')
}
const encode = (text) => encodeURIComponent(Buffer.from(text).toString('base64')) const encode = (text) => encodeURIComponent(Buffer.from(text).toString('base64'))
Vue.prototype.$encode = encode Vue.prototype.$encode = encode
const decode = (text) => Buffer.from(decodeURIComponent(text), 'base64').toString() const decode = (text) => Buffer.from(decodeURIComponent(text), 'base64').toString()
Vue.prototype.$decode = decode Vue.prototype.$decode = decode
export { export { encode, decode }
encode,
decode
}
export default ({ app, store }, inject) => { export default ({ app, store }, inject) => {
app.$decode = decode app.$decode = decode
app.$encode = encode app.$encode = encode

View File

@ -289,7 +289,6 @@ module.exports.findMatchingEpisodesInFeed = (feed, searchTitle) => {
const matches = [] const matches = []
feed.episodes.forEach((ep) => { feed.episodes.forEach((ep) => {
if (!ep.title) return if (!ep.title) return
const epTitle = ep.title.toLowerCase().trim() const epTitle = ep.title.toLowerCase().trim()
if (epTitle === searchTitle) { if (epTitle === searchTitle) {
matches.push({ matches.push({