@@ -13,6 +13,7 @@ const uploadFilters = require('../../lib/mediaBrowsing/helpers');
13
13
const getSensitivityFilter = uploadFilters . getSensitivityFilter ;
14
14
const categories = require ( '../../config/categories' ) ;
15
15
const logCaching = process . env . LOG_CACHING ;
16
+ const RSS = require ( 'rss' ) ;
16
17
17
18
// todo: get out of controller
18
19
let viewStats ;
@@ -35,10 +36,36 @@ const pageLimit = 42;
35
36
36
37
exports . recentRssFeed = async ( req , res ) => {
37
38
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
+ } ) ;
38
50
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
+ } ) ;
40
66
41
- res . send ( uploads ) ;
67
+ const xml = feed . xml ( { indent : true } ) ;
68
+ res . send ( xml ) ;
42
69
43
70
// TOOD: incorporate rss feed here and send it as response
44
71
} ;
0 commit comments