Skip to content

Commit

Permalink
Fix:Podcast episode match not properly encoding search query advplyr#…
Browse files Browse the repository at this point in the history
  • Loading branch information
advplyr authored and glorenzen committed Jul 24, 2024
1 parent d57d712 commit a351430
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
4 changes: 2 additions & 2 deletions client/components/modals/podcast/tabs/EpisodeMatch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export default {
this.searchedTitle = this.episodeTitle
this.isProcessing = true
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) => {
this.episodesFound = results.episodes.map((ep) => ep.episode)
console.log('Episodes found', this.episodesFound)
Expand All @@ -153,4 +153,4 @@ export default {
},
mounted() {}
}
</script>
</script>
37 changes: 16 additions & 21 deletions client/plugins/init.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import * as locale from 'date-fns/locale'

Vue.directive('click-outside', vClickOutside.directive)


Vue.prototype.$setDateFnsLocale = (localeString) => {
if (!locale[localeString]) return 0
return setDefaultOptions({ locale: locale[localeString] })
Expand Down Expand Up @@ -112,14 +111,15 @@ Vue.prototype.$sanitizeSlug = (str) => {
str = str.toLowerCase()

// remove accents, swap ñ for n, etc
var from = "àáäâèéëêìíïîòóöôùúüûñçěščřžýúůďťň·/,:;"
var to = "aaaaeeeeiiiioooouuuuncescrzyuudtn-----"
var from = 'àáäâèéëêìíïîòóöôùúüûñçěščřžýúůďťň·/,:;'
var to = 'aaaaeeeeiiiioooouuuuncescrzyuudtn-----'

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('.', '-') // replace a dot by a dash
str = str
.replace('.', '-') // replace a dot by a dash
.replace(/[^a-z0-9 -_]/g, '') // remove invalid chars
.replace(/\s+/g, '-') // collapse whitespace and replace by a dash
.replace(/-+/g, '-') // collapse dashes
Expand All @@ -131,13 +131,16 @@ Vue.prototype.$sanitizeSlug = (str) => {
Vue.prototype.$copyToClipboard = (str, ctx) => {
return new Promise((resolve) => {
if (navigator.clipboard) {
navigator.clipboard.writeText(str).then(() => {
if (ctx) ctx.$toast.success('Copied to clipboard')
resolve(true)
}, (err) => {
console.error('Clipboard copy failed', str, err)
resolve(false)
})
navigator.clipboard.writeText(str).then(
() => {
if (ctx) ctx.$toast.success('Copied to clipboard')
resolve(true)
},
(err) => {
console.error('Clipboard copy failed', str, err)
resolve(false)
}
)
} else {
const el = document.createElement('textarea')
el.value = str
Expand All @@ -160,26 +163,18 @@ function xmlToJson(xml) {
for (const res of xml.matchAll(/(?:<(\w*)(?:\s[^>]*)*>)((?:(?!<\1).)*)(?:<\/\1>)|<(\w*)(?:\s*)*\/>/gm)) {
const key = res[1] || res[3]
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
}
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'))
Vue.prototype.$encode = encode
const decode = (text) => Buffer.from(decodeURIComponent(text), 'base64').toString()
Vue.prototype.$decode = decode

export {
encode,
decode
}
export { encode, decode }
export default ({ app, store }, inject) => {
app.$decode = decode
app.$encode = encode
Expand Down
1 change: 0 additions & 1 deletion server/utils/podcastUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ module.exports.findMatchingEpisodesInFeed = (feed, searchTitle) => {
const matches = []
feed.episodes.forEach((ep) => {
if (!ep.title) return

const epTitle = ep.title.toLowerCase().trim()
if (epTitle === searchTitle) {
matches.push({
Expand Down

0 comments on commit a351430

Please sign in to comment.