mirror of
https://github.com/advplyr/audiobookshelf.git
synced 2026-07-14 05:11:45 +00:00
Make OPML import non-blocking
This commit is contained in:
parent
b6875a44cf
commit
0c8285a4ae
4 changed files with 40 additions and 17 deletions
|
|
@ -113,18 +113,25 @@ export default {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.$axios
|
try {
|
||||||
.$post(`/api/podcasts/opml`, { opmlText: txt })
|
this.$root.socket.on('opml_feeds', (data) => {
|
||||||
.then((data) => {
|
this.$root.socket.off('opml_feeds')
|
||||||
console.log(data)
|
this.processing = false
|
||||||
|
if (data.error) {
|
||||||
|
this.$toast.error(data.error)
|
||||||
|
return
|
||||||
|
}
|
||||||
this.opmlFeeds = data.feeds || []
|
this.opmlFeeds = data.feeds || []
|
||||||
this.showOPMLFeedsModal = true
|
this.showOPMLFeedsModal = true
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
await this.$axios.$post(`/api/podcasts/opml`, { opmlText: txt })
|
||||||
console.error('Failed', error)
|
console.log('OPML import started')
|
||||||
this.$toast.error('Failed to parse OPML file')
|
} catch (error) {
|
||||||
})
|
this.$root.socket.off('opml_feeds')
|
||||||
this.processing = false
|
this.processing = false
|
||||||
|
console.error('/api/podcasts/opml failed:', error)
|
||||||
|
this.$toast.error('Failed to start OPML import: ' + error.message)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
submit() {
|
submit() {
|
||||||
if (!this.searchInput) return
|
if (!this.searchInput) return
|
||||||
|
|
@ -222,6 +229,9 @@ export default {
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.fetchExistentPodcastsInYourLibrary()
|
this.fetchExistentPodcastsInYourLibrary()
|
||||||
|
},
|
||||||
|
beforeDestroy() {
|
||||||
|
this.$root.socket.off('opml_feeds')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -133,7 +133,7 @@ class PodcastController {
|
||||||
res.json({ podcast })
|
res.json({ podcast })
|
||||||
}
|
}
|
||||||
|
|
||||||
async getFeedsFromOPMLText(req, res) {
|
getFeedsFromOPMLText(req, res) {
|
||||||
if (!req.user.isAdminOrUp) {
|
if (!req.user.isAdminOrUp) {
|
||||||
Logger.error(`[PodcastController] Non-admin user "${req.user.username}" attempted to get feeds from opml`)
|
Logger.error(`[PodcastController] Non-admin user "${req.user.username}" attempted to get feeds from opml`)
|
||||||
return res.sendStatus(403)
|
return res.sendStatus(403)
|
||||||
|
|
@ -143,8 +143,18 @@ class PodcastController {
|
||||||
return res.sendStatus(400)
|
return res.sendStatus(400)
|
||||||
}
|
}
|
||||||
|
|
||||||
const rssFeedsData = await this.podcastManager.getOPMLFeeds(req.body.opmlText)
|
this.podcastManager
|
||||||
res.json(rssFeedsData)
|
.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) {
|
async checkNewEpisodes(req, res) {
|
||||||
|
|
|
||||||
|
|
@ -354,9 +354,7 @@ class PodcastManager {
|
||||||
var extractedFeeds = opmlParser.parse(opmlText)
|
var extractedFeeds = opmlParser.parse(opmlText)
|
||||||
if (!extractedFeeds || !extractedFeeds.length) {
|
if (!extractedFeeds || !extractedFeeds.length) {
|
||||||
Logger.error('[PodcastManager] getOPMLFeeds: No RSS feeds found in OPML')
|
Logger.error('[PodcastManager] getOPMLFeeds: No RSS feeds found in OPML')
|
||||||
return {
|
throw new Error('No RSS feeds found in OPML')
|
||||||
error: 'No RSS feeds found in OPML'
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var rssFeedData = []
|
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 {
|
return {
|
||||||
feeds: rssFeedData
|
feeds: rssFeedData
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -231,7 +231,7 @@ module.exports.getPodcastFeed = (feedUrl, excludeEpisodeMetadata = false) => {
|
||||||
return axios({
|
return axios({
|
||||||
url: feedUrl,
|
url: feedUrl,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
timeout: 12000,
|
timeout: 5000,
|
||||||
responseType: 'arraybuffer',
|
responseType: 'arraybuffer',
|
||||||
headers: {
|
headers: {
|
||||||
Accept: 'application/rss+xml, application/xhtml+xml, application/xml, */*;q=0.8',
|
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
|
return payload.podcast
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
Logger.error('[podcastUtils] getPodcastFeed Error', error)
|
Logger.error('[podcastUtils] getPodcastFeed Error:', error.message)
|
||||||
return null
|
return null
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue