aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/feeds.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-04-17 10:56:27 +0200
committerChocobozzz <me@florianbigard.com>2018-04-17 10:56:27 +0200
commit7b87d2d5141d0eb48db2a3fd162208d6a79b2035 (patch)
tree6c7b40ae79671fa2cf1b8418092acca031006d07 /server/controllers/feeds.ts
parentcc1561f9f7b33d739d66b23bacae23ea49f2fa12 (diff)
downloadPeerTube-7b87d2d5141d0eb48db2a3fd162208d6a79b2035.tar.gz
PeerTube-7b87d2d5141d0eb48db2a3fd162208d6a79b2035.tar.zst
PeerTube-7b87d2d5141d0eb48db2a3fd162208d6a79b2035.zip
Handle sort in rss
Diffstat (limited to 'server/controllers/feeds.ts')
-rw-r--r--server/controllers/feeds.ts31
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 @@
1import * as express from 'express' 1import * as express from 'express'
2import { CONFIG } from '../initializers' 2import { CONFIG } from '../initializers'
3import { asyncMiddleware, feedsValidator } from '../middlewares' 3import {
4 asyncMiddleware,
5 feedsValidator,
6 setDefaultPagination,
7 setDefaultSort,
8 videosSortValidator
9} from '../middlewares'
4import { VideoModel } from '../models/video/video' 10import { VideoModel } from '../models/video/video'
5import * as Feed from 'pfeed' 11import * as Feed from 'pfeed'
6import { ResultList } from '../../shared/models' 12import { ResultList } from '../../shared/models'
@@ -9,6 +15,8 @@ import { AccountModel } from '../models/account/account'
9const feedsRouter = express.Router() 15const feedsRouter = express.Router()
10 16
11feedsRouter.get('/feeds/videos.:format', 17feedsRouter.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
24async function generateFeed (req: express.Request, res: express.Response, next: express.NextFunction) { 32async 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 }