diff options
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/api/accounts.ts | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/server/controllers/api/accounts.ts b/server/controllers/api/accounts.ts index adbf69781..aa01ea1eb 100644 --- a/server/controllers/api/accounts.ts +++ b/server/controllers/api/accounts.ts | |||
@@ -1,16 +1,25 @@ | |||
1 | import * as express from 'express' | 1 | import * as express from 'express' |
2 | import { getFormattedObjects, getServerActor } from '../../helpers/utils' | 2 | import { getFormattedObjects, getServerActor } from '../../helpers/utils' |
3 | import { | 3 | import { |
4 | authenticate, | ||
4 | asyncMiddleware, | 5 | asyncMiddleware, |
5 | commonVideosFiltersValidator, | 6 | commonVideosFiltersValidator, |
7 | videoRatingValidator, | ||
6 | optionalAuthenticate, | 8 | optionalAuthenticate, |
7 | paginationValidator, | 9 | paginationValidator, |
8 | setDefaultPagination, | 10 | setDefaultPagination, |
9 | setDefaultSort, | 11 | setDefaultSort, |
10 | videoPlaylistsSortValidator | 12 | videoPlaylistsSortValidator, |
13 | videoRatesSortValidator | ||
11 | } from '../../middlewares' | 14 | } from '../../middlewares' |
12 | import { accountNameWithHostGetValidator, accountsSortValidator, videosSortValidator } from '../../middlewares/validators' | 15 | import { |
16 | accountNameWithHostGetValidator, | ||
17 | accountsSortValidator, | ||
18 | videosSortValidator, | ||
19 | ensureAuthUserOwnsAccountValidator | ||
20 | } from '../../middlewares/validators' | ||
13 | import { AccountModel } from '../../models/account/account' | 21 | import { AccountModel } from '../../models/account/account' |
22 | import { AccountVideoRateModel } from '../../models/account/account-video-rate' | ||
14 | import { VideoModel } from '../../models/video/video' | 23 | import { VideoModel } from '../../models/video/video' |
15 | import { buildNSFWFilter, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' | 24 | import { buildNSFWFilter, isUserAbleToSearchRemoteURI } from '../../helpers/express-utils' |
16 | import { VideoChannelModel } from '../../models/video/video-channel' | 25 | import { VideoChannelModel } from '../../models/video/video-channel' |
@@ -61,6 +70,18 @@ accountsRouter.get('/:accountName/video-playlists', | |||
61 | asyncMiddleware(listAccountPlaylists) | 70 | asyncMiddleware(listAccountPlaylists) |
62 | ) | 71 | ) |
63 | 72 | ||
73 | accountsRouter.get('/:accountName/ratings', | ||
74 | authenticate, | ||
75 | asyncMiddleware(accountNameWithHostGetValidator), | ||
76 | ensureAuthUserOwnsAccountValidator, | ||
77 | paginationValidator, | ||
78 | videoRatesSortValidator, | ||
79 | setDefaultSort, | ||
80 | setDefaultPagination, | ||
81 | videoRatingValidator, | ||
82 | asyncMiddleware(listAccountRatings) | ||
83 | ) | ||
84 | |||
64 | // --------------------------------------------------------------------------- | 85 | // --------------------------------------------------------------------------- |
65 | 86 | ||
66 | export { | 87 | export { |
@@ -138,3 +159,16 @@ async function listAccountVideos (req: express.Request, res: express.Response) { | |||
138 | 159 | ||
139 | return res.json(getFormattedObjects(resultList.data, resultList.total)) | 160 | return res.json(getFormattedObjects(resultList.data, resultList.total)) |
140 | } | 161 | } |
162 | |||
163 | async function listAccountRatings (req: express.Request, res: express.Response) { | ||
164 | const account = res.locals.account | ||
165 | |||
166 | const resultList = await AccountVideoRateModel.listByAccountForApi({ | ||
167 | accountId: account.id, | ||
168 | start: req.query.start, | ||
169 | count: req.query.count, | ||
170 | sort: req.query.sort, | ||
171 | type: req.query.rating | ||
172 | }) | ||
173 | return res.json(getFormattedObjects(resultList.rows, resultList.count)) | ||
174 | } | ||