]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/controllers/api/accounts.ts
Add ability to update a video channel
[github/Chocobozzz/PeerTube.git] / server / controllers / api / accounts.ts
CommitLineData
265ba139 1import * as express from 'express'
cc918ac3 2import { getFormattedObjects } from '../../helpers/utils'
48dce1c9
C
3import {
4 asyncMiddleware,
48dce1c9
C
5 listVideoAccountChannelsValidator,
6 optionalAuthenticate,
7 paginationValidator,
8 setDefaultPagination,
cc918ac3 9 setDefaultSort
48dce1c9 10} from '../../middlewares'
0626e7af 11import { accountsGetValidator, accountsSortValidator, videosSortValidator } from '../../middlewares/validators'
265ba139 12import { AccountModel } from '../../models/account/account'
0626e7af 13import { VideoModel } from '../../models/video/video'
0626e7af 14import { isNSFWHidden } from '../../helpers/express-utils'
48dce1c9 15import { VideoChannelModel } from '../../models/video/video-channel'
265ba139
C
16
17const accountsRouter = express.Router()
18
19accountsRouter.get('/',
20 paginationValidator,
21 accountsSortValidator,
1174a847 22 setDefaultSort,
f05a1c30 23 setDefaultPagination,
265ba139
C
24 asyncMiddleware(listAccounts)
25)
26
27accountsRouter.get('/:id',
28 asyncMiddleware(accountsGetValidator),
29 getAccount
30)
31
0626e7af
C
32accountsRouter.get('/:id/videos',
33 asyncMiddleware(accountsGetValidator),
34 paginationValidator,
35 videosSortValidator,
36 setDefaultSort,
37 setDefaultPagination,
38 optionalAuthenticate,
48dce1c9
C
39 asyncMiddleware(listAccountVideos)
40)
41
42accountsRouter.get('/:accountId/video-channels',
43 asyncMiddleware(listVideoAccountChannelsValidator),
44 asyncMiddleware(listVideoAccountChannels)
45)
46
265ba139
C
47// ---------------------------------------------------------------------------
48
49export {
50 accountsRouter
51}
52
53// ---------------------------------------------------------------------------
54
55function getAccount (req: express.Request, res: express.Response, next: express.NextFunction) {
0626e7af
C
56 const account: AccountModel = res.locals.account
57
58 return res.json(account.toFormattedJSON())
265ba139
C
59}
60
61async function listAccounts (req: express.Request, res: express.Response, next: express.NextFunction) {
62 const resultList = await AccountModel.listForApi(req.query.start, req.query.count, req.query.sort)
63
64 return res.json(getFormattedObjects(resultList.data, resultList.total))
65}
0626e7af 66
48dce1c9
C
67async function listVideoAccountChannels (req: express.Request, res: express.Response, next: express.NextFunction) {
68 const resultList = await VideoChannelModel.listByAccount(res.locals.account.id)
69
70 return res.json(getFormattedObjects(resultList.data, resultList.total))
71}
72
48dce1c9 73async function listAccountVideos (req: express.Request, res: express.Response, next: express.NextFunction) {
0626e7af
C
74 const account: AccountModel = res.locals.account
75
48dce1c9
C
76 const resultList = await VideoModel.listForApi({
77 start: req.query.start,
78 count: req.query.count,
79 sort: req.query.sort,
80 hideNSFW: isNSFWHidden(res),
81 withFiles: false,
82 accountId: account.id
83 })
0626e7af
C
84
85 return res.json(getFormattedObjects(resultList.data, resultList.total))
86}