aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers')
-rw-r--r--server/controllers/feeds.ts55
1 files changed, 45 insertions, 10 deletions
diff --git a/server/controllers/feeds.ts b/server/controllers/feeds.ts
index cb82bfc6d..bfcd3fe36 100644
--- a/server/controllers/feeds.ts
+++ b/server/controllers/feeds.ts
@@ -27,6 +27,7 @@ feedsRouter.get('/feeds/video-comments.:format',
27 'Content-Type' 27 'Content-Type'
28 ] 28 ]
29 })(ROUTE_CACHE_LIFETIME.FEEDS)), 29 })(ROUTE_CACHE_LIFETIME.FEEDS)),
30 asyncMiddleware(videoFeedsValidator),
30 asyncMiddleware(videoCommentsFeedsValidator), 31 asyncMiddleware(videoCommentsFeedsValidator),
31 asyncMiddleware(generateVideoCommentsFeed) 32 asyncMiddleware(generateVideoCommentsFeed)
32) 33)
@@ -58,13 +59,36 @@ async function generateVideoCommentsFeed (req: express.Request, res: express.Res
58 const start = 0 59 const start = 0
59 60
60 const video = res.locals.videoAll 61 const video = res.locals.videoAll
61 const videoId: number = video ? video.id : undefined 62 const account = res.locals.account
63 const videoChannel = res.locals.videoChannel
62 64
63 const comments = await VideoCommentModel.listForFeed(start, FEEDS.COUNT, videoId) 65 const comments = await VideoCommentModel.listForFeed({
66 start,
67 count: FEEDS.COUNT,
68 videoId: video ? video.id : undefined,
69 accountId: account ? account.id : undefined,
70 videoChannelId: videoChannel ? videoChannel.id : undefined
71 })
64 72
65 const name = video ? video.name : CONFIG.INSTANCE.NAME 73 let name: string
66 const description = video ? video.description : CONFIG.INSTANCE.DESCRIPTION 74 let description: string
67 const feed = initFeed(name, description) 75
76 if (videoChannel) {
77 name = videoChannel.getDisplayName()
78 description = videoChannel.description
79 } else if (account) {
80 name = account.getDisplayName()
81 description = account.description
82 } else {
83 name = video ? video.name : CONFIG.INSTANCE.NAME
84 description = video ? video.description : CONFIG.INSTANCE.DESCRIPTION
85 }
86 const feed = initFeed({
87 name,
88 description,
89 resourceType: 'video-comments',
90 queryString: new URL(WEBSERVER.URL + req.originalUrl).search
91 })
68 92
69 // Adding video items to the feed, one at a time 93 // Adding video items to the feed, one at a time
70 for (const comment of comments) { 94 for (const comment of comments) {
@@ -116,7 +140,12 @@ async function generateVideoFeed (req: express.Request, res: express.Response) {
116 description = CONFIG.INSTANCE.DESCRIPTION 140 description = CONFIG.INSTANCE.DESCRIPTION
117 } 141 }
118 142
119 const feed = initFeed(name, description) 143 const feed = initFeed({
144 name,
145 description,
146 resourceType: 'videos',
147 queryString: new URL(WEBSERVER.URL + req.url).search
148 })
120 149
121 const resultList = await VideoModel.listForApi({ 150 const resultList = await VideoModel.listForApi({
122 start, 151 start,
@@ -207,8 +236,14 @@ async function generateVideoFeed (req: express.Request, res: express.Response) {
207 return sendFeed(feed, req, res) 236 return sendFeed(feed, req, res)
208} 237}
209 238
210function initFeed (name: string, description: string) { 239function initFeed (parameters: {
240 name: string
241 description: string
242 resourceType?: 'videos' | 'video-comments'
243 queryString?: string
244}) {
211 const webserverUrl = WEBSERVER.URL 245 const webserverUrl = WEBSERVER.URL
246 const { name, description, resourceType, queryString } = parameters
212 247
213 return new Feed({ 248 return new Feed({
214 title: name, 249 title: name,
@@ -222,9 +257,9 @@ function initFeed (name: string, description: string) {
222 ` and potential licenses granted by each content's rightholder.`, 257 ` and potential licenses granted by each content's rightholder.`,
223 generator: `Toraifōsu`, // ^.~ 258 generator: `Toraifōsu`, // ^.~
224 feedLinks: { 259 feedLinks: {
225 json: `${webserverUrl}/feeds/videos.json`, 260 json: `${webserverUrl}/feeds/${resourceType}.json${queryString}`,
226 atom: `${webserverUrl}/feeds/videos.atom`, 261 atom: `${webserverUrl}/feeds/${resourceType}.atom${queryString}`,
227 rss: `${webserverUrl}/feeds/videos.xml` 262 rss: `${webserverUrl}/feeds/${resourceType}.xml${queryString}`
228 }, 263 },
229 author: { 264 author: {
230 name: 'Instance admin of ' + CONFIG.INSTANCE.NAME, 265 name: 'Instance admin of ' + CONFIG.INSTANCE.NAME,