1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-04 10:19:35 +02:00

Add account view

This commit is contained in:
Chocobozzz 2018-04-24 15:10:54 +02:00
parent b4d1af3dd8
commit 0626e7af82
No known key found for this signature in database
GPG key ID: 583A612D890159BE
33 changed files with 563 additions and 149 deletions

View file

@ -1,8 +1,11 @@
import * as express from 'express'
import { getFormattedObjects } from '../../helpers/utils'
import { asyncMiddleware, paginationValidator, setDefaultSort, setDefaultPagination } from '../../middlewares'
import { accountsGetValidator, accountsSortValidator } from '../../middlewares/validators'
import { asyncMiddleware, optionalAuthenticate, paginationValidator, setDefaultPagination, setDefaultSort } from '../../middlewares'
import { accountsGetValidator, accountsSortValidator, videosSortValidator } from '../../middlewares/validators'
import { AccountModel } from '../../models/account/account'
import { VideoModel } from '../../models/video/video'
import { VideoSortField } from '../../../client/src/app/shared/video/sort-field.type'
import { isNSFWHidden } from '../../helpers/express-utils'
const accountsRouter = express.Router()
@ -19,6 +22,16 @@ accountsRouter.get('/:id',
getAccount
)
accountsRouter.get('/:id/videos',
asyncMiddleware(accountsGetValidator),
paginationValidator,
videosSortValidator,
setDefaultSort,
setDefaultPagination,
optionalAuthenticate,
asyncMiddleware(getAccountVideos)
)
// ---------------------------------------------------------------------------
export {
@ -28,7 +41,9 @@ export {
// ---------------------------------------------------------------------------
function getAccount (req: express.Request, res: express.Response, next: express.NextFunction) {
return res.json(res.locals.account.toFormattedJSON())
const account: AccountModel = res.locals.account
return res.json(account.toFormattedJSON())
}
async function listAccounts (req: express.Request, res: express.Response, next: express.NextFunction) {
@ -36,3 +51,19 @@ async function listAccounts (req: express.Request, res: express.Response, next:
return res.json(getFormattedObjects(resultList.data, resultList.total))
}
async function getAccountVideos (req: express.Request, res: express.Response, next: express.NextFunction) {
const account: AccountModel = res.locals.account
const resultList = await VideoModel.listForApi(
req.query.start as number,
req.query.count as number,
req.query.sort as VideoSortField,
isNSFWHidden(res),
null,
false,
account.id
)
return res.json(getFormattedObjects(resultList.data, resultList.total))
}