aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/accounts.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/accounts.ts')
-rw-r--r--server/controllers/api/accounts.ts37
1 files changed, 34 insertions, 3 deletions
diff --git a/server/controllers/api/accounts.ts b/server/controllers/api/accounts.ts
index 4dc0cc16d..06ab04033 100644
--- a/server/controllers/api/accounts.ts
+++ b/server/controllers/api/accounts.ts
@@ -1,8 +1,11 @@
1import * as express from 'express' 1import * as express from 'express'
2import { getFormattedObjects } from '../../helpers/utils' 2import { getFormattedObjects } from '../../helpers/utils'
3import { asyncMiddleware, paginationValidator, setDefaultSort, setDefaultPagination } from '../../middlewares' 3import { asyncMiddleware, optionalAuthenticate, paginationValidator, setDefaultPagination, setDefaultSort } from '../../middlewares'
4import { accountsGetValidator, accountsSortValidator } from '../../middlewares/validators' 4import { accountsGetValidator, accountsSortValidator, videosSortValidator } from '../../middlewares/validators'
5import { AccountModel } from '../../models/account/account' 5import { AccountModel } from '../../models/account/account'
6import { VideoModel } from '../../models/video/video'
7import { VideoSortField } from '../../../client/src/app/shared/video/sort-field.type'
8import { isNSFWHidden } from '../../helpers/express-utils'
6 9
7const accountsRouter = express.Router() 10const accountsRouter = express.Router()
8 11
@@ -19,6 +22,16 @@ accountsRouter.get('/:id',
19 getAccount 22 getAccount
20) 23)
21 24
25accountsRouter.get('/:id/videos',
26 asyncMiddleware(accountsGetValidator),
27 paginationValidator,
28 videosSortValidator,
29 setDefaultSort,
30 setDefaultPagination,
31 optionalAuthenticate,
32 asyncMiddleware(getAccountVideos)
33)
34
22// --------------------------------------------------------------------------- 35// ---------------------------------------------------------------------------
23 36
24export { 37export {
@@ -28,7 +41,9 @@ export {
28// --------------------------------------------------------------------------- 41// ---------------------------------------------------------------------------
29 42
30function getAccount (req: express.Request, res: express.Response, next: express.NextFunction) { 43function getAccount (req: express.Request, res: express.Response, next: express.NextFunction) {
31 return res.json(res.locals.account.toFormattedJSON()) 44 const account: AccountModel = res.locals.account
45
46 return res.json(account.toFormattedJSON())
32} 47}
33 48
34async function listAccounts (req: express.Request, res: express.Response, next: express.NextFunction) { 49async function listAccounts (req: express.Request, res: express.Response, next: express.NextFunction) {
@@ -36,3 +51,19 @@ async function listAccounts (req: express.Request, res: express.Response, next:
36 51
37 return res.json(getFormattedObjects(resultList.data, resultList.total)) 52 return res.json(getFormattedObjects(resultList.data, resultList.total))
38} 53}
54
55async function getAccountVideos (req: express.Request, res: express.Response, next: express.NextFunction) {
56 const account: AccountModel = res.locals.account
57
58 const resultList = await VideoModel.listForApi(
59 req.query.start as number,
60 req.query.count as number,
61 req.query.sort as VideoSortField,
62 isNSFWHidden(res),
63 null,
64 false,
65 account.id
66 )
67
68 return res.json(getFormattedObjects(resultList.data, resultList.total))
69}