Make OPML import non-blocking

This commit is contained in:
mikiher 2024-07-14 23:11:06 +03:00
parent b6875a44cf
commit 0c8285a4ae
4 changed files with 40 additions and 17 deletions

View file

@ -113,18 +113,25 @@ export default {
return
}
await this.$axios
.$post(`/api/podcasts/opml`, { opmlText: txt })
.then((data) => {
console.log(data)
try {
this.$root.socket.on('opml_feeds', (data) => {
this.$root.socket.off('opml_feeds')
this.processing = false
if (data.error) {
this.$toast.error(data.error)
return
}
this.opmlFeeds = data.feeds || []
this.showOPMLFeedsModal = true
})
.catch((error) => {
console.error('Failed', error)
this.$toast.error('Failed to parse OPML file')
})
this.processing = false
await this.$axios.$post(`/api/podcasts/opml`, { opmlText: txt })
console.log('OPML import started')
} catch (error) {
this.$root.socket.off('opml_feeds')
this.processing = false
console.error('/api/podcasts/opml failed:', error)
this.$toast.error('Failed to start OPML import: ' + error.message)
}
},
submit() {
if (!this.searchInput) return
@ -222,6 +229,9 @@ export default {
},
mounted() {
this.fetchExistentPodcastsInYourLibrary()
},
beforeDestroy() {
this.$root.socket.off('opml_feeds')
}
}
</script>

View file

@ -133,7 +133,7 @@ class PodcastController {
res.json({ podcast })
}
async getFeedsFromOPMLText(req, res) {
getFeedsFromOPMLText(req, res) {
if (!req.user.isAdminOrUp) {
Logger.error(`[PodcastController] Non-admin user "${req.user.username}" attempted to get feeds from opml`)
return res.sendStatus(403)
@ -143,8 +143,18 @@ class PodcastController {
return res.sendStatus(400)
}
const rssFeedsData = await this.podcastManager.getOPMLFeeds(req.body.opmlText)
res.json(rssFeedsData)
this.podcastManager
.getOPMLFeeds(req.body.opmlText)
.then((rssFeedsData) => {
Logger.info('[PodcastController] getOPMLFeeds finished successfully')
SocketAuthority.emitter('opml_feeds', rssFeedsData)
})
.catch((error) => {
Logger.error('[PodcastController] getOPMLFeeds error:', error)
SocketAuthority.emitter('opml_feeds', { error: error.message })
})
Logger.info('[PodcastController] getOPMLFeeds started')
res.sendStatus(200)
}
async checkNewEpisodes(req, res) {

View file

@ -354,9 +354,7 @@ class PodcastManager {
var extractedFeeds = opmlParser.parse(opmlText)
if (!extractedFeeds || !extractedFeeds.length) {
Logger.error('[PodcastManager] getOPMLFeeds: No RSS feeds found in OPML')
return {
error: 'No RSS feeds found in OPML'
}
throw new Error('No RSS feeds found in OPML')
}
var rssFeedData = []
@ -369,6 +367,11 @@ class PodcastManager {
}
}
if (!rssFeedData.length) {
Logger.error('[PodcastManager] getOPMLFeeds: No valid RSS feeds found in OPML')
throw new Error('No valid RSS feeds found in OPML')
}
return {
feeds: rssFeedData
}

View file

@ -231,7 +231,7 @@ module.exports.getPodcastFeed = (feedUrl, excludeEpisodeMetadata = false) => {
return axios({
url: feedUrl,
method: 'GET',
timeout: 12000,
timeout: 5000,
responseType: 'arraybuffer',
headers: {
Accept: 'application/rss+xml, application/xhtml+xml, application/xml, */*;q=0.8',
@ -266,7 +266,7 @@ module.exports.getPodcastFeed = (feedUrl, excludeEpisodeMetadata = false) => {
return payload.podcast
})
.catch((error) => {
Logger.error('[podcastUtils] getPodcastFeed Error', error)
Logger.error('[podcastUtils] getPodcastFeed Error:', error.message)
return null
})
}