@@ -13,6 +13,7 @@ const uploadFilters = require('../../lib/mediaBrowsing/helpers');
1313const getSensitivityFilter = uploadFilters . getSensitivityFilter ;
1414const categories = require ( '../../config/categories' ) ;
1515const logCaching = process . env . LOG_CACHING ;
16+ const RSS = require ( 'rss' ) ;
1617
1718// todo: get out of controller
1819let viewStats ;
@@ -35,10 +36,36 @@ const pageLimit = 42;
3536
3637exports . recentRssFeed = async ( req , res ) => {
3738 const uploads = await getFromCache . getRecentUploads ( 20 , 0 , 'all' , 'sensitive' , 'all' , '' ) ;
39+ const feed = new RSS ( {
40+ title : process . env . INSTANCE_BRAND_NAME ,
41+ description : process . env . META_DESCRIPTION ,
42+ feed_url : `${ process . env . DOMAIN_NAME_AND_TLD } /media/recent/rss` ,
43+ site_url : process . env . DOMAIN_NAME_AND_TLD ,
44+ image_url : process . env . META_IMAGE ,
45+ copyright : `2020 ${ process . env . INSTANCE_DOMAIN_NAME } ` ,
46+ language : 'en' ,
47+ pubDate : new Date ( ) ,
48+ ttl : '60'
49+ } ) ;
3850
39- console . log ( uploads ) ;
51+ uploads . map ( item => {
52+ const { title, category } = item ;
53+ const categories = [ category ] ;
54+ const author = item . uploader . channelName ;
55+ const url = `${ process . env . DOMAIN_NAME_AND_TLD } /user/${ author } /${ item . uniqueTag } ` ;
56+
57+ feed . item ( {
58+ title,
59+ url, // link to the item
60+ guid : item . _id , // optional - defaults to url
61+ categories, // optional - array of item categories
62+ author, // optional - defaults to feed author property
63+ date : item . createdAt // any format that js Date can parse.
64+ } ) ;
65+ } ) ;
4066
41- res . send ( uploads ) ;
67+ const xml = feed . xml ( { indent : true } ) ;
68+ res . send ( xml ) ;
4269
4370 // TOOD: incorporate rss feed here and send it as response
4471} ;
0 commit comments