aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/feeds.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-06-13 15:07:25 +0200
committerChocobozzz <me@florianbigard.com>2018-06-13 15:07:45 +0200
commit749c7247ae9042a74d132afda0c7eefab66a0428 (patch)
tree73ceea2408c5aea13e2c936951e7ece3cf98b9aa /server/controllers/feeds.ts
parentbcec136ee62ee9fcc0f0177e9dd0ac191a2cf5ee (diff)
downloadPeerTube-749c7247ae9042a74d132afda0c7eefab66a0428.tar.gz
PeerTube-749c7247ae9042a74d132afda0c7eefab66a0428.tar.zst
PeerTube-749c7247ae9042a74d132afda0c7eefab66a0428.zip
Fix bad RSS descriptions when filtering videos by account or channel
Diffstat (limited to 'server/controllers/feeds.ts')
-rw-r--r--server/controllers/feeds.ts33
1 files changed, 26 insertions, 7 deletions
diff --git a/server/controllers/feeds.ts b/server/controllers/feeds.ts
index c928dfacb..ece5dc067 100644
--- a/server/controllers/feeds.ts
+++ b/server/controllers/feeds.ts
@@ -1,6 +1,6 @@
1import * as express from 'express' 1import * as express from 'express'
2import { CONFIG, FEEDS, ROUTE_CACHE_LIFETIME } from '../initializers/constants' 2import { CONFIG, FEEDS, ROUTE_CACHE_LIFETIME } from '../initializers/constants'
3import { asyncMiddleware, videoFeedsValidator, setDefaultSort, videosSortValidator, videoCommentsFeedsValidator } from '../middlewares' 3import { asyncMiddleware, setDefaultSort, videoCommentsFeedsValidator, videoFeedsValidator, videosSortValidator } from '../middlewares'
4import { VideoModel } from '../models/video/video' 4import { VideoModel } from '../models/video/video'
5import * as Feed from 'pfeed' 5import * as Feed from 'pfeed'
6import { AccountModel } from '../models/account/account' 6import { AccountModel } from '../models/account/account'
@@ -33,13 +33,17 @@ export {
33// --------------------------------------------------------------------------- 33// ---------------------------------------------------------------------------
34 34
35async function generateVideoCommentsFeed (req: express.Request, res: express.Response, next: express.NextFunction) { 35async function generateVideoCommentsFeed (req: express.Request, res: express.Response, next: express.NextFunction) {
36 let feed = initFeed()
37 const start = 0 36 const start = 0
38 37
39 const videoId: number = res.locals.video ? res.locals.video.id : undefined 38 const video = res.locals.video as VideoModel
39 const videoId: number = video ? video.id : undefined
40 40
41 const comments = await VideoCommentModel.listForFeed(start, FEEDS.COUNT, videoId) 41 const comments = await VideoCommentModel.listForFeed(start, FEEDS.COUNT, videoId)
42 42
43 const name = video ? video.name : CONFIG.INSTANCE.NAME
44 const description = video ? video.description : CONFIG.INSTANCE.DESCRIPTION
45 const feed = initFeed(name, description)
46
43 // Adding video items to the feed, one at a time 47 // Adding video items to the feed, one at a time
44 comments.forEach(comment => { 48 comments.forEach(comment => {
45 feed.addItem({ 49 feed.addItem({
@@ -62,13 +66,28 @@ async function generateVideoCommentsFeed (req: express.Request, res: express.Res
62} 66}
63 67
64async function generateVideoFeed (req: express.Request, res: express.Response, next: express.NextFunction) { 68async function generateVideoFeed (req: express.Request, res: express.Response, next: express.NextFunction) {
65 let feed = initFeed()
66 const start = 0 69 const start = 0
67 70
68 const account: AccountModel = res.locals.account 71 const account: AccountModel = res.locals.account
69 const videoChannel: VideoChannelModel = res.locals.videoChannel 72 const videoChannel: VideoChannelModel = res.locals.videoChannel
70 const hideNSFW = CONFIG.INSTANCE.DEFAULT_NSFW_POLICY === 'do_not_list' 73 const hideNSFW = CONFIG.INSTANCE.DEFAULT_NSFW_POLICY === 'do_not_list'
71 74
75 let name: string
76 let description: string
77
78 if (videoChannel) {
79 name = videoChannel.getDisplayName()
80 description = videoChannel.description
81 } else if (account) {
82 name = account.getDisplayName()
83 description = account.description
84 } else {
85 name = CONFIG.INSTANCE.NAME
86 description = CONFIG.INSTANCE.DESCRIPTION
87 }
88
89 const feed = initFeed(name, description)
90
72 const resultList = await VideoModel.listForApi({ 91 const resultList = await VideoModel.listForApi({
73 start, 92 start,
74 count: FEEDS.COUNT, 93 count: FEEDS.COUNT,
@@ -112,12 +131,12 @@ async function generateVideoFeed (req: express.Request, res: express.Response, n
112 return sendFeed(feed, req, res) 131 return sendFeed(feed, req, res)
113} 132}
114 133
115function initFeed () { 134function initFeed (name: string, description: string) {
116 const webserverUrl = CONFIG.WEBSERVER.URL 135 const webserverUrl = CONFIG.WEBSERVER.URL
117 136
118 return new Feed({ 137 return new Feed({
119 title: CONFIG.INSTANCE.NAME, 138 title: name,
120 description: CONFIG.INSTANCE.DESCRIPTION, 139 description,
121 // updated: TODO: somehowGetLatestUpdate, // optional, default = today 140 // updated: TODO: somehowGetLatestUpdate, // optional, default = today
122 id: webserverUrl, 141 id: webserverUrl,
123 link: webserverUrl, 142 link: webserverUrl,