1 import * as express from 'express'
2 import { getFormattedObjects } from '../../helpers/utils'
4 asyncMiddleware, commonVideosFiltersValidator,
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 { buildNSFWFilter, isUserAbleToSearchRemoteURI } 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 commonVideosFiltersValidator,
40 asyncMiddleware(listAccountVideos)
43 accountsRouter.get('/:accountName/video-channels',
44 asyncMiddleware(listVideoAccountChannelsValidator),
45 asyncMiddleware(listVideoAccountChannels)
48 // ---------------------------------------------------------------------------
54 // ---------------------------------------------------------------------------
56 function getAccount (req: express.Request, res: express.Response, next: express.NextFunction) {
57 const account: AccountModel = res.locals.account
59 return res.json(account.toFormattedJSON())
62 async function listAccounts (req: express.Request, res: express.Response, next: express.NextFunction) {
63 const resultList = await AccountModel.listForApi(req.query.start, req.query.count, req.query.sort)
65 return res.json(getFormattedObjects(resultList.data, resultList.total))
68 async function listVideoAccountChannels (req: express.Request, res: express.Response, next: express.NextFunction) {
69 const resultList = await VideoChannelModel.listByAccount(res.locals.account.id)
71 return res.json(getFormattedObjects(resultList.data, resultList.total))
74 async function listAccountVideos (req: express.Request, res: express.Response, next: express.NextFunction) {
75 const account: AccountModel = res.locals.account
76 const actorId = isUserAbleToSearchRemoteURI(res) ? null : undefined
78 const resultList = await VideoModel.listForApi({
80 start: req.query.start,
81 count: req.query.count,
83 includeLocalVideos: true,
84 categoryOneOf: req.query.categoryOneOf,
85 licenceOneOf: req.query.licenceOneOf,
86 languageOneOf: req.query.languageOneOf,
87 tagsOneOf: req.query.tagsOneOf,
88 tagsAllOf: req.query.tagsAllOf,
89 nsfw: buildNSFWFilter(res, req.query.nsfw),
94 return res.json(getFormattedObjects(resultList.data, resultList.total))