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:
parent
9fd540562c
commit
8a02bd0433
19 changed files with 232 additions and 94 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue