Don't show videos of remote instance after unfollow
[oweals/peertube.git] / server / controllers / api / accounts.ts
1 import * as express from 'express'
2 import { getFormattedObjects } from '../../helpers/utils'
3 import { asyncMiddleware, paginationValidator, setDefaultSort, setDefaultPagination } from '../../middlewares'
4 import { accountsGetValidator, accountsSortValidator } from '../../middlewares/validators'
5 import { AccountModel } from '../../models/account/account'
6
7 const accountsRouter = express.Router()
8
9 accountsRouter.get('/',
10   paginationValidator,
11   accountsSortValidator,
12   setDefaultSort,
13   setDefaultPagination,
14   asyncMiddleware(listAccounts)
15 )
16
17 accountsRouter.get('/:id',
18   asyncMiddleware(accountsGetValidator),
19   getAccount
20 )
21
22 // ---------------------------------------------------------------------------
23
24 export {
25   accountsRouter
26 }
27
28 // ---------------------------------------------------------------------------
29
30 function getAccount (req: express.Request, res: express.Response, next: express.NextFunction) {
31   return res.json(res.locals.account.toFormattedJSON())
32 }
33
34 async function listAccounts (req: express.Request, res: express.Response, next: express.NextFunction) {
35   const resultList = await AccountModel.listForApi(req.query.start, req.query.count, req.query.sort)
36
37   return res.json(getFormattedObjects(resultList.data, resultList.total))
38 }