mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-04 10:19:35 +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,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))
|
||||
}
|
||||
|
||||
|
|
|
@ -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