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

Add pod list endpoint with pagination, sort...

This commit is contained in:
Chocobozzz 2017-10-19 09:43:01 +02:00
parent 9fd540562c
commit 8a02bd0433
No known key found for this signature in database
GPG key ID: 583A612D890159BE
19 changed files with 232 additions and 94 deletions

View file

@ -1,39 +1,33 @@
import * as express from 'express'
import { database as db } from '../../initializers/database'
import { CONFIG } from '../../initializers'
import { logger, getFormattedObjects } from '../../helpers'
import {
logger,
getMyPublicCert,
getFormattedObjects
} from '../../helpers'
import {
sendOwnedVideosToPod,
makeFriends,
quitFriends,
removeFriend
} from '../../lib'
import {
podsAddValidator,
authenticate,
ensureIsAdmin,
makeFriendsValidator,
setBodyHostPort,
setBodyHostsPort,
podRemoveValidator
podRemoveValidator,
paginationValidator,
setPagination,
setPodsSort,
podsSortValidator
} from '../../middlewares'
import {
PodInstance
} from '../../models'
import { Pod as FormattedPod } from '../../../shared'
import { PodInstance } from '../../models'
const podsRouter = express.Router()
podsRouter.get('/', listPods)
podsRouter.post('/',
setBodyHostPort, // We need to modify the host before running the validator!
podsAddValidator,
addPods
podsRouter.get('/',
paginationValidator,
podsSortValidator,
setPodsSort,
setPagination,
listPods
)
podsRouter.post('/make-friends',
authenticate,
@ -62,26 +56,9 @@ export {
// ---------------------------------------------------------------------------
function addPods (req: express.Request, res: express.Response, next: express.NextFunction) {
const informations = req.body
const pod = db.Pod.build(informations)
pod.save()
.then(podCreated => {
return sendOwnedVideosToPod(podCreated.id)
})
.then(() => {
return getMyPublicCert()
})
.then(cert => {
return res.json({ cert: cert, email: CONFIG.ADMIN.EMAIL })
})
.catch(err => next(err))
}
function listPods (req: express.Request, res: express.Response, next: express.NextFunction) {
db.Pod.list()
.then(podsList => res.json(getFormattedObjects<FormattedPod, PodInstance>(podsList, podsList.length)))
db.Pod.listForApi(req.query.start, req.query.count, req.query.sort)
.then(resultList => res.json(getFormattedObjects(resultList.data, resultList.total)))
.catch(err => next(err))
}