aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/users.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/users.ts')
-rw-r--r--server/controllers/api/users.ts21
1 files changed, 20 insertions, 1 deletions
diff --git a/server/controllers/api/users.ts b/server/controllers/api/users.ts
index fdc9b0c87..dcd407fdf 100644
--- a/server/controllers/api/users.ts
+++ b/server/controllers/api/users.ts
@@ -30,6 +30,8 @@ import {
30} from '../../../shared' 30} from '../../../shared'
31import { createUserAuthorAndChannel } from '../../lib' 31import { createUserAuthorAndChannel } from '../../lib'
32import { UserInstance } from '../../models' 32import { UserInstance } from '../../models'
33import { videosSortValidator } from '../../middlewares/validators/sort'
34import { setVideosSort } from '../../middlewares/sort'
33 35
34const usersRouter = express.Router() 36const usersRouter = express.Router()
35 37
@@ -38,6 +40,15 @@ usersRouter.get('/me',
38 asyncMiddleware(getUserInformation) 40 asyncMiddleware(getUserInformation)
39) 41)
40 42
43usersRouter.get('/me/videos',
44 authenticate,
45 paginationValidator,
46 videosSortValidator,
47 setVideosSort,
48 setPagination,
49 asyncMiddleware(getUserVideos)
50)
51
41usersRouter.get('/me/videos/:videoId/rating', 52usersRouter.get('/me/videos/:videoId/rating',
42 authenticate, 53 authenticate,
43 usersVideoRatingValidator, 54 usersVideoRatingValidator,
@@ -101,6 +112,13 @@ export {
101 112
102// --------------------------------------------------------------------------- 113// ---------------------------------------------------------------------------
103 114
115async function getUserVideos (req: express.Request, res: express.Response, next: express.NextFunction) {
116 const user = res.locals.oauth.token.User
117 const resultList = await db.Video.listUserVideosForApi(user.id ,req.query.start, req.query.count, req.query.sort)
118
119 return res.json(getFormattedObjects(resultList.data, resultList.total))
120}
121
104async function createUserRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { 122async function createUserRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) {
105 const options = { 123 const options = {
106 arguments: [ req, res ], 124 arguments: [ req, res ],
@@ -146,13 +164,14 @@ async function registerUser (req: express.Request, res: express.Response, next:
146} 164}
147 165
148async function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) { 166async function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) {
167 // We did not load channels in res.locals.user
149 const user = await db.User.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username) 168 const user = await db.User.loadByUsernameAndPopulateChannels(res.locals.oauth.token.user.username)
150 169
151 return res.json(user.toFormattedJSON()) 170 return res.json(user.toFormattedJSON())
152} 171}
153 172
154function getUser (req: express.Request, res: express.Response, next: express.NextFunction) { 173function getUser (req: express.Request, res: express.Response, next: express.NextFunction) {
155 return res.json(res.locals.user.toFormattedJSON()) 174 return res.json(res.locals.oauth.token.User.toFormattedJSON())
156} 175}
157 176
158async function getUserVideoRating (req: express.Request, res: express.Response, next: express.NextFunction) { 177async function getUserVideoRating (req: express.Request, res: express.Response, next: express.NextFunction) {