diff options
Diffstat (limited to 'server/controllers/api/users.ts')
-rw-r--r-- | server/controllers/api/users.ts | 21 |
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' |
31 | import { createUserAuthorAndChannel } from '../../lib' | 31 | import { createUserAuthorAndChannel } from '../../lib' |
32 | import { UserInstance } from '../../models' | 32 | import { UserInstance } from '../../models' |
33 | import { videosSortValidator } from '../../middlewares/validators/sort' | ||
34 | import { setVideosSort } from '../../middlewares/sort' | ||
33 | 35 | ||
34 | const usersRouter = express.Router() | 36 | const usersRouter = express.Router() |
35 | 37 | ||
@@ -38,6 +40,15 @@ usersRouter.get('/me', | |||
38 | asyncMiddleware(getUserInformation) | 40 | asyncMiddleware(getUserInformation) |
39 | ) | 41 | ) |
40 | 42 | ||
43 | usersRouter.get('/me/videos', | ||
44 | authenticate, | ||
45 | paginationValidator, | ||
46 | videosSortValidator, | ||
47 | setVideosSort, | ||
48 | setPagination, | ||
49 | asyncMiddleware(getUserVideos) | ||
50 | ) | ||
51 | |||
41 | usersRouter.get('/me/videos/:videoId/rating', | 52 | usersRouter.get('/me/videos/:videoId/rating', |
42 | authenticate, | 53 | authenticate, |
43 | usersVideoRatingValidator, | 54 | usersVideoRatingValidator, |
@@ -101,6 +112,13 @@ export { | |||
101 | 112 | ||
102 | // --------------------------------------------------------------------------- | 113 | // --------------------------------------------------------------------------- |
103 | 114 | ||
115 | async 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 | |||
104 | async function createUserRetryWrapper (req: express.Request, res: express.Response, next: express.NextFunction) { | 122 | async 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 | ||
148 | async function getUserInformation (req: express.Request, res: express.Response, next: express.NextFunction) { | 166 | async 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 | ||
154 | function getUser (req: express.Request, res: express.Response, next: express.NextFunction) { | 173 | function 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 | ||
158 | async function getUserVideoRating (req: express.Request, res: express.Response, next: express.NextFunction) { | 177 | async function getUserVideoRating (req: express.Request, res: express.Response, next: express.NextFunction) { |