PeerTube/server/controllers/api/pods.ts

48 lines
1.7 KiB
TypeScript
Raw Normal View History

2017-06-05 21:53:49 +02:00
import * as express from 'express'
2017-11-10 17:27:49 +01:00
import { getFormattedObjects } from '../../helpers'
2017-11-13 17:39:41 +01:00
import { getApplicationAccount } from '../../helpers/utils'
2017-05-22 20:58:25 +02:00
import { database as db } from '../../initializers/database'
2017-11-13 17:39:41 +01:00
import { asyncMiddleware, paginationValidator, setFollowersSort, setPagination } from '../../middlewares'
import { setFollowingSort } from '../../middlewares/sort'
import { followersSortValidator, followingSortValidator } from '../../middlewares/validators/sort'
2017-05-15 22:22:03 +02:00
const podsRouter = express.Router()
2017-11-13 17:39:41 +01:00
podsRouter.get('/following',
paginationValidator,
2017-11-13 17:39:41 +01:00
followingSortValidator,
setFollowingSort,
setPagination,
2017-11-13 17:39:41 +01:00
asyncMiddleware(listFollowing)
)
podsRouter.get('/followers',
paginationValidator,
followersSortValidator,
setFollowersSort,
setPagination,
asyncMiddleware(listFollowers)
2017-05-15 22:22:03 +02:00
)
// ---------------------------------------------------------------------------
export {
podsRouter
}
// ---------------------------------------------------------------------------
2017-11-13 17:39:41 +01:00
async function listFollowing (req: express.Request, res: express.Response, next: express.NextFunction) {
const applicationAccount = await getApplicationAccount()
const resultList = await db.Account.listFollowingForApi(applicationAccount.id, req.query.start, req.query.count, req.query.sort)
return res.json(getFormattedObjects(resultList.data, resultList.total))
}
async function listFollowers (req: express.Request, res: express.Response, next: express.NextFunction) {
const applicationAccount = await getApplicationAccount()
const resultList = await db.Account.listFollowersForApi(applicationAccount.id, req.query.start, req.query.count, req.query.sort)
2017-10-25 11:55:06 +02:00
return res.json(getFormattedObjects(resultList.data, resultList.total))
2017-05-15 22:22:03 +02:00
}