1+ import axios from 'axios' ;
12import { toXML } from 'jstoxml' ;
3+ import xml2js from 'xml2js' ;
24import { cloneDeep } from 'lodash' ;
35import moment from 'moment' ;
46import config from '../../config/config' ;
57import CronItem from '../helpers/cronItem.helper' ;
6- import { getAdFreeMp3 } from '../helpers/mp3.helper' ;
78import app from '../../config/express' ;
89import Post from '../models/post.model' ;
910
11+ const PRIVATE_RSS_URL = 'https://feeds.megaphone.fm/SED2675996583' ;
12+
13+ async function getPrivateFeed ( ) {
14+ const builder = new xml2js . Builder ( { cdata : true } ) ;
15+ const parser = new xml2js . Parser ( { explicitArray : false } ) ;
16+ let parsedResult = { } ;
17+ try {
18+ const feedResult = await axios . get ( PRIVATE_RSS_URL ) ;
19+ if ( feedResult . status === 200 ) {
20+ parser . parseString ( feedResult . data , ( err , result ) => {
21+ if ( err ) {
22+ throw err ;
23+ }
24+ parsedResult = result ;
25+ } ) ;
26+ }
27+ } catch ( error ) {
28+ console . log ( error ) ; // eslint-disable-line
29+ }
30+ return builder . buildObject ( parsedResult ) ;
31+ }
32+
1033const itunesImage = toXML ( {
1134 _name : 'itunes:image' ,
1235 _attrs : {
@@ -88,7 +111,7 @@ async function callback() {
88111
89112 const publicFeedAllConfig = cloneDeep ( rawFeedConfig ) ;
90113 const publicFeedConfig = cloneDeep ( rawFeedConfig ) ;
91- const privateFeedConfig = cloneDeep ( rawFeedConfig ) ;
114+ const privateFeedConfig = await getPrivateFeed ( ) ;
92115 const lastPost = posts [ posts . length - 1 ] ;
93116
94117 let episode = posts . length + 1 ;
@@ -138,12 +161,6 @@ async function callback() {
138161
139162 // RSS item for each episode
140163 publicFeedConfig . _content . channel . push ( { item } ) ;
141-
142- const privateMp3 = post . adFreeMp3 || getAdFreeMp3 ( post . mp3 ) ;
143- const privateItem = cloneDeep ( item ) ;
144-
145- privateItem [ 0 ] . _attrs . url = privateMp3 ;
146- privateFeedConfig . _content . channel . push ( { item : privateItem } ) ;
147164 } ) ;
148165
149166 publicFeedAllConfig . _content . channel = publicFeedConfig . _content . channel ;
@@ -156,7 +173,7 @@ async function callback() {
156173
157174 app . set ( 'rssFeedPublicAll' , toXML ( publicFeedAllConfig , xmlOptions ) ) ;
158175 app . set ( 'rssFeedPublic' , toXML ( publicFeedConfig , xmlOptions ) ) ;
159- app . set ( 'rssFeedPrivate' , toXML ( privateFeedConfig , xmlOptions ) ) ;
176+ app . set ( 'rssFeedPrivate' , privateFeedConfig ) ;
160177}
161178
162179const rssFeed = {
0 commit comments