1 import * as express from 'express'
2 import { getFormattedObjects } from '../../helpers/utils'
5 listVideoAccountChannelsValidator,
10 } from '../../middlewares'
11 import { accountsNameWithHostGetValidator, accountsSortValidator, videosSortValidator } from '../../middlewares/validators'
12 import { AccountModel } from '../../models/account/account'
13 import { VideoModel } from '../../models/video/video'
14 import { isNSFWHidden } from '../../helpers/express-utils'
15 import { VideoChannelModel } from '../../models/video/video-channel'
17 const accountsRouter = express.Router()
19 accountsRouter.get('/',
21 accountsSortValidator,
24 asyncMiddleware(listAccounts)
27 accountsRouter.get('/:accountName',
28 asyncMiddleware(accountsNameWithHostGetValidator),
32 accountsRouter.get('/:accountName/videos',
33 asyncMiddleware(accountsNameWithHostGetValidator),
39 asyncMiddleware(listAccountVideos)
42 accountsRouter.get('/:accountName/video-channels',
43 asyncMiddleware(listVideoAccountChannelsValidator),
44 asyncMiddleware(listVideoAccountChannels)
47 // ---------------------------------------------------------------------------
53 // ---------------------------------------------------------------------------
55 function getAccount (req: express.Request, res: express.Response, next: express.NextFunction) {
56 const account: AccountModel = res.locals.account
58 return res.json(account.toFormattedJSON())
61 async 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)
64 return res.json(getFormattedObjects(resultList.data, resultList.total))
67 async function listVideoAccountChannels (req: express.Request, res: express.Response, next: express.NextFunction) {
68 const resultList = await VideoChannelModel.listByAccount(res.locals.account.id)
70 return res.json(getFormattedObjects(resultList.data, resultList.total))
73 async function listAccountVideos (req: express.Request, res: express.Response, next: express.NextFunction) {
74 const account: AccountModel = res.locals.account
76 const resultList = await VideoModel.listForApi({
77 start: req.query.start,
78 count: req.query.count,
80 hideNSFW: isNSFWHidden(res),
85 return res.json(getFormattedObjects(resultList.data, resultList.total))