diff options
author | Chocobozzz <me@florianbigard.com> | 2018-06-08 20:34:37 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-06-08 20:34:37 +0200 |
commit | fe3a55b071c99b346e9e9ab786f5d219e5a064cd (patch) | |
tree | 55c6d0e9a253b20df738fd82820eb931044828e6 /server/controllers/feeds.ts | |
parent | 4a7591e1a8ec5ffdff85580c6be4b18d8b85b4d4 (diff) | |
download | PeerTube-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.ts | 44 |
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 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { CONFIG, FEEDS, ROUTE_CACHE_LIFETIME } from '../initializers/constants' | 2 | import { CONFIG, FEEDS, ROUTE_CACHE_LIFETIME } from '../initializers/constants' |
3 | import { asyncMiddleware, feedsValidator, setDefaultSort, videosSortValidator } from '../middlewares' | 3 | import { asyncMiddleware, videoFeedsValidator, setDefaultSort, videosSortValidator, videoCommentsFeedsValidator } from '../middlewares' |
4 | import { VideoModel } from '../models/video/video' | 4 | import { VideoModel } from '../models/video/video' |
5 | import * as Feed from 'pfeed' | 5 | import * as Feed from 'pfeed' |
6 | import { AccountModel } from '../models/account/account' | 6 | import { AccountModel } from '../models/account/account' |
7 | import { cacheRoute } from '../middlewares/cache' | 7 | import { cacheRoute } from '../middlewares/cache' |
8 | import { VideoChannelModel } from '../models/video/video-channel' | 8 | import { VideoChannelModel } from '../models/video/video-channel' |
9 | import { VideoCommentModel } from '../models/video/video-comment' | ||
9 | 10 | ||
10 | const feedsRouter = express.Router() | 11 | const feedsRouter = express.Router() |
11 | 12 | ||
13 | feedsRouter.get('/feeds/video-comments.:format', | ||
14 | asyncMiddleware(cacheRoute(ROUTE_CACHE_LIFETIME.FEEDS)), | ||
15 | asyncMiddleware(videoCommentsFeedsValidator), | ||
16 | asyncMiddleware(generateVideoCommentsFeed) | ||
17 | ) | ||
18 | |||
12 | feedsRouter.get('/feeds/videos.:format', | 19 | feedsRouter.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 | ||
28 | async function generateFeed (req: express.Request, res: express.Response, next: express.NextFunction) { | 35 | async 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 | |||
64 | async 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 | ||