diff --git a/components/modals/PodcastEpisodesFeedModal.vue b/components/modals/PodcastEpisodesFeedModal.vue index 91005ce9..502f5554 100644 --- a/components/modals/PodcastEpisodesFeedModal.vue +++ b/components/modals/PodcastEpisodesFeedModal.vue @@ -6,14 +6,14 @@
-
+
- Download Episodes + {{ episodesSelected.length ? `Add ${episodesSelected.length} Episode(s) to Server` : 'No Episodes Selected' }}
@@ -43,7 +43,10 @@ export default { } }, data() { - return {} + return { + processing: false, + selectedEpisodes: {} + } }, watch: { show: { @@ -62,6 +65,12 @@ export default { this.$emit('input', val) } }, + allDownloaded() { + return !this.episodes.some((episode) => !this.itemEpisodeMap[episode.enclosure.url]) + }, + episodesSelected() { + return Object.keys(this.selectedEpisodes).filter((key) => !!this.selectedEpisodes[key]) + }, itemEpisodes() { if (!this.libraryItem) return [] return this.libraryItem.media.episodes || [] @@ -75,8 +84,44 @@ export default { } }, methods: { + downloadEpisodes() { + const episodesToDownload = this.episodesSelected.map((episodeIndex) => this.episodes[Number(episodeIndex)]) + + const payloadSize = JSON.stringify(episodesToDownload).length + const sizeInMb = payloadSize / 1024 / 1024 + const sizeInMbPretty = sizeInMb.toFixed(2) + 'MB' + console.log('Request size', sizeInMb) + if (sizeInMb > 4.99) { + return this.$toast.error(`Request is too large (${sizeInMbPretty}) should be < 5Mb`) + } + + this.processing = true + this.$axios + .$post(`/api/podcasts/${this.libraryItem.id}/download-episodes`, episodesToDownload) + .then(() => { + this.processing = false + this.$toast.success('Started downloading episodes on server') + this.show = false + }) + .catch((error) => { + var errorMsg = error.response && error.response.data ? error.response.data : 'Failed to download episodes' + console.error('Failed to download episodes', error) + this.processing = false + this.$toast.error(errorMsg) + + this.selectedEpisodes = {} + }) + }, + selectEpisode(episode, index) { + if (this.itemEpisodeMap[episode.enclosure.url]) return + this.selectedEpisodes[String(index)] = !this.selectedEpisodes[String(index)] + }, init() { this.episodes.sort((a, b) => (a.publishedAt < b.publishedAt ? 1 : -1)) + for (let i = 0; i < this.episodes.length; i++) { + // this.selectedEpisodes[String(i)] = false + this.$set(this.selectedEpisodes, String(i), false) + } } }, mounted() {} diff --git a/components/tables/podcast/EpisodeRow.vue b/components/tables/podcast/EpisodeRow.vue index 45eb8987..262d6387 100644 --- a/components/tables/podcast/EpisodeRow.vue +++ b/components/tables/podcast/EpisodeRow.vue @@ -66,6 +66,9 @@ export default { } }, computed: { + isAdminOrUp() { + return this.$store.getters['user/getIsAdminOrUp'] + }, isIos() { return this.$platform === 'ios' }, diff --git a/components/tables/podcast/EpisodesTable.vue b/components/tables/podcast/EpisodesTable.vue index 80553154..6d5a53b9 100644 --- a/components/tables/podcast/EpisodesTable.vue +++ b/components/tables/podcast/EpisodesTable.vue @@ -1,5 +1,22 @@ \ No newline at end of file diff --git a/pages/item/_id.vue b/pages/item/_id.vue index a14468f8..8f6e4bb4 100644 --- a/pages/item/_id.vue +++ b/pages/item/_id.vue @@ -143,7 +143,6 @@ import { Dialog } from '@capacitor/dialog' import { AbsFileSystem, AbsDownloader } from '@/plugins/capacitor' - export default { async asyncData({ store, params, redirect, app }) { var libraryItemId = params.id @@ -637,12 +636,12 @@ export default { mounted() { this.$eventBus.$on('library-changed', this.libraryChanged) this.$eventBus.$on('new-local-library-item', this.newLocalLibraryItem) - this.$socket.on('item_updated', this.itemUpdated) + this.$socket.$on('item_updated', this.itemUpdated) }, beforeDestroy() { this.$eventBus.$off('library-changed', this.libraryChanged) this.$eventBus.$off('new-local-library-item', this.newLocalLibraryItem) - this.$socket.off('item_updated', this.itemUpdated) + this.$socket.$off('item_updated', this.itemUpdated) } }