diff options
Diffstat (limited to 'server/controllers/feeds.ts')
-rw-r--r-- | server/controllers/feeds.ts | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/server/controllers/feeds.ts b/server/controllers/feeds.ts index b9d4c5d50..700c50ec8 100644 --- a/server/controllers/feeds.ts +++ b/server/controllers/feeds.ts | |||
@@ -1,6 +1,12 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { CONFIG } from '../initializers' | 2 | import { CONFIG } from '../initializers' |
3 | import { asyncMiddleware, feedsValidator } from '../middlewares' | 3 | import { |
4 | asyncMiddleware, | ||
5 | feedsValidator, | ||
6 | setDefaultPagination, | ||
7 | setDefaultSort, | ||
8 | videosSortValidator | ||
9 | } from '../middlewares' | ||
4 | import { VideoModel } from '../models/video/video' | 10 | import { VideoModel } from '../models/video/video' |
5 | import * as Feed from 'pfeed' | 11 | import * as Feed from 'pfeed' |
6 | import { ResultList } from '../../shared/models' | 12 | import { ResultList } from '../../shared/models' |
@@ -9,6 +15,8 @@ import { AccountModel } from '../models/account/account' | |||
9 | const feedsRouter = express.Router() | 15 | const feedsRouter = express.Router() |
10 | 16 | ||
11 | feedsRouter.get('/feeds/videos.:format', | 17 | feedsRouter.get('/feeds/videos.:format', |
18 | videosSortValidator, | ||
19 | setDefaultSort, | ||
12 | asyncMiddleware(feedsValidator), | 20 | asyncMiddleware(feedsValidator), |
13 | asyncMiddleware(generateFeed) | 21 | asyncMiddleware(generateFeed) |
14 | ) | 22 | ) |
@@ -23,26 +31,25 @@ export { | |||
23 | 31 | ||
24 | async function generateFeed (req: express.Request, res: express.Response, next: express.NextFunction) { | 32 | async function generateFeed (req: express.Request, res: express.Response, next: express.NextFunction) { |
25 | let feed = initFeed() | 33 | let feed = initFeed() |
26 | let feedStart = 0 | 34 | const paginationStart = 0 |
27 | let feedCount = 10 | 35 | const paginationCount = 20 |
28 | let feedSort = '-createdAt' | ||
29 | 36 | ||
30 | let resultList: ResultList<VideoModel> | 37 | let resultList: ResultList<VideoModel> |
31 | const account: AccountModel = res.locals.account | 38 | const account: AccountModel = res.locals.account |
32 | 39 | ||
33 | if (account) { | 40 | if (account) { |
34 | resultList = await VideoModel.listUserVideosForApi( | 41 | resultList = await VideoModel.listAccountVideosForApi( |
35 | account.id, | 42 | account.id, |
36 | feedStart, | 43 | paginationStart, |
37 | feedCount, | 44 | paginationCount, |
38 | feedSort, | 45 | req.query.sort, |
39 | true | 46 | true |
40 | ) | 47 | ) |
41 | } else { | 48 | } else { |
42 | resultList = await VideoModel.listForApi( | 49 | resultList = await VideoModel.listForApi( |
43 | feedStart, | 50 | paginationStart, |
44 | feedCount, | 51 | paginationCount, |
45 | feedSort, | 52 | req.query.sort, |
46 | req.query.filter, | 53 | req.query.filter, |
47 | true | 54 | true |
48 | ) | 55 | ) |
@@ -100,7 +107,7 @@ function initFeed () { | |||
100 | rss: `${webserverUrl}/feeds/videos.xml` | 107 | rss: `${webserverUrl}/feeds/videos.xml` |
101 | }, | 108 | }, |
102 | author: { | 109 | author: { |
103 | name: 'instance admin of ' + CONFIG.INSTANCE.NAME, | 110 | name: 'Instance admin of ' + CONFIG.INSTANCE.NAME, |
104 | email: CONFIG.ADMIN.EMAIL, | 111 | email: CONFIG.ADMIN.EMAIL, |
105 | link: `${webserverUrl}/about` | 112 | link: `${webserverUrl}/about` |
106 | } | 113 | } |