aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/feeds.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-06-08 20:34:37 +0200
committerChocobozzz <me@florianbigard.com>2018-06-08 20:34:37 +0200
commitfe3a55b071c99b346e9e9ab786f5d219e5a064cd (patch)
tree55c6d0e9a253b20df738fd82820eb931044828e6 /server/controllers/feeds.ts
parent4a7591e1a8ec5ffdff85580c6be4b18d8b85b4d4 (diff)
downloadPeerTube-fe3a55b071c99b346e9e9ab786f5d219e5a064cd.tar.gz
PeerTube-fe3a55b071c99b346e9e9ab786f5d219e5a064cd.tar.zst
PeerTube-fe3a55b071c99b346e9e9ab786f5d219e5a064cd.zip
Add video comments RSS
Diffstat (limited to 'server/controllers/feeds.ts')
-rw-r--r--server/controllers/feeds.ts44
1 files changed, 40 insertions, 4 deletions
diff --git a/server/controllers/feeds.ts b/server/controllers/feeds.ts
index 3a2b5ecca..c928dfacb 100644
--- a/server/controllers/feeds.ts
+++ b/server/controllers/feeds.ts
@@ -1,20 +1,27 @@
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, feedsValidator, setDefaultSort, videosSortValidator } from '../middlewares' 3import { asyncMiddleware, videoFeedsValidator, setDefaultSort, videosSortValidator, videoCommentsFeedsValidator } 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'
7import { cacheRoute } from '../middlewares/cache' 7import { cacheRoute } from '../middlewares/cache'
8import { VideoChannelModel } from '../models/video/video-channel' 8import { VideoChannelModel } from '../models/video/video-channel'
9import { VideoCommentModel } from '../models/video/video-comment'
9 10
10const feedsRouter = express.Router() 11const feedsRouter = express.Router()
11 12
13feedsRouter.get('/feeds/video-comments.:format',
14 asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.FEEDS)),
15 asyncMiddleware(videoCommentsFeedsValidator),
16 asyncMiddleware(generateVideoCommentsFeed)
17)
18
12feedsRouter.get('/feeds/videos.:format', 19feedsRouter.get('/feeds/videos.:format',
13 videosSortValidator, 20 videosSortValidator,
14 setDefaultSort, 21 setDefaultSort,
15 asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.FEEDS)), 22 asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.FEEDS)),
16 asyncMiddleware(feedsValidator), 23 asyncMiddleware(videoFeedsValidator),
17 asyncMiddleware(generateFeed) 24 asyncMiddleware(generateVideoFeed)
18) 25)
19 26
20// --------------------------------------------------------------------------- 27// ---------------------------------------------------------------------------
@@ -25,7 +32,36 @@ export {
25 32
26// --------------------------------------------------------------------------- 33// ---------------------------------------------------------------------------
27 34
28async function generateFeed (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
38
39 const videoId: number = res.locals.video ? res.locals.video.id : undefined
40
41 const comments = await VideoCommentModel.listForFeed(start, FEEDS.COUNT, videoId)
42
43 // Adding video items to the feed, one at a time
44 comments.forEach(comment => {
45 feed.addItem({
46 title: `${comment.Video.name} - ${comment.Account.getDisplayName()}`,
47 id: comment.url,
48 link: comment.url,
49 content: comment.text,
50 author: [
51 {
52 name: comment.Account.getDisplayName(),
53 link: comment.Account.Actor.url
54 }
55 ],
56 date: comment.createdAt
57 })
58 })
59
60 // Now the feed generation is done, let's send it!
61 return sendFeed(feed, req, res)
62}
63
64async function generateVideoFeed (req: express.Request, res: express.Response, next: express.NextFunction) {
29 let feed = initFeed() 65 let feed = initFeed()
30 const start = 0 66 const start = 0
31 67