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,18 +1,34 @@
import * as express from 'express'
import { database as db } from '../../../initializers/database'
import { checkSignature, signatureValidator } from '../../../middlewares'
import { PodSignature } from '../../../../shared'
import {
checkSignature,
signatureValidator,
setBodyHostPort,
remotePodsAddValidator
} from '../../../middlewares'
import { sendOwnedVideosToPod } from '../../../lib'
import { getMyPublicCert, getFormattedObjects } from '../../../helpers'
import { CONFIG } from '../../../initializers'
import { PodInstance } from '../../../models'
import { PodSignature, Pod as FormattedPod } from '../../../../shared'
const remotePodsRouter = express.Router()
// Post because this is a secured request
remotePodsRouter.post('/remove',
signatureValidator,
checkSignature,
removePods
)
remotePodsRouter.post('/list', remotePodsList)
remotePodsRouter.post('/add',
setBodyHostPort, // We need to modify the host before running the validator!
remotePodsAddValidator,
addPods
)
// ---------------------------------------------------------------------------
export {
@ -21,6 +37,29 @@ export {
// ---------------------------------------------------------------------------
function addPods (req: express.Request, res: express.Response, next: express.NextFunction) {
const information = req.body
const pod = db.Pod.build(information)
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 remotePodsList (req: express.Request, res: express.Response, next: express.NextFunction) {
db.Pod.list()
.then(podsList => res.json(getFormattedObjects<FormattedPod, PodInstance>(podsList, podsList.length)))
.catch(err => next(err))
}
function removePods (req: express.Request, res: express.Response, next: express.NextFunction) {
const signature: PodSignature = req.body.signature
const host = signature.host