diff options
author | Chocobozzz <me@florianbigard.com> | 2018-04-17 10:56:27 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2018-04-17 10:56:27 +0200 |
commit | 7b87d2d5141d0eb48db2a3fd162208d6a79b2035 (patch) | |
tree | 6c7b40ae79671fa2cf1b8418092acca031006d07 /server/controllers | |
parent | cc1561f9f7b33d739d66b23bacae23ea49f2fa12 (diff) | |
download | PeerTube-7b87d2d5141d0eb48db2a3fd162208d6a79b2035.tar.gz PeerTube-7b87d2d5141d0eb48db2a3fd162208d6a79b2035.tar.zst PeerTube-7b87d2d5141d0eb48db2a3fd162208d6a79b2035.zip |
Handle sort in rss
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/api/users.ts | 2 | ||||
-rw-r--r-- | server/controllers/feeds.ts | 31 |
2 files changed, 20 insertions, 13 deletions
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts index abe6b3ff7..56cbf9448 100644 --- a/server/controllers/api/users.ts +++ b/server/controllers/api/users.ts | |||
@@ -161,7 +161,7 @@ export { | |||
161 | 161 | ||
162 | async function getUserVideos (req: express.Request, res: express.Response, next: express.NextFunction) { | 162 | async function getUserVideos (req: express.Request, res: express.Response, next: express.NextFunction) { |
163 | const user = res.locals.oauth.token.User as UserModel | 163 | const user = res.locals.oauth.token.User as UserModel |
164 | const resultList = await VideoModel.listUserVideosForApi(user.id ,req.query.start, req.query.count, req.query.sort) | 164 | const resultList = await VideoModel.listAccountVideosForApi(user.Account.id ,req.query.start, req.query.count, req.query.sort) |
165 | 165 | ||
166 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 166 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
167 | } | 167 | } |
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 | } |