aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-30 10:51:13 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-30 10:55:06 +0100
commit5cd80545422bba855cc9a730a2e13cc9d982c34b (patch)
tree9a60cd7c9218c296a1460938d11e3bce784f7cc0 /server/controllers/api
parent1f3e9feca2caf68024168b0ea9ed39d8438fa235 (diff)
downloadPeerTube-5cd80545422bba855cc9a730a2e13cc9d982c34b.tar.gz
PeerTube-5cd80545422bba855cc9a730a2e13cc9d982c34b.tar.zst
PeerTube-5cd80545422bba855cc9a730a2e13cc9d982c34b.zip
Add ability to list jobs
Diffstat (limited to 'server/controllers/api')
-rw-r--r--server/controllers/api/index.ts2
-rw-r--r--server/controllers/api/jobs.ts34
2 files changed, 36 insertions, 0 deletions
diff --git a/server/controllers/api/index.ts b/server/controllers/api/index.ts
index b00fb7467..737ea4602 100644
--- a/server/controllers/api/index.ts
+++ b/server/controllers/api/index.ts
@@ -7,6 +7,7 @@ import { configRouter } from './config'
7import { serverRouter } from './server' 7import { serverRouter } from './server'
8import { usersRouter } from './users' 8import { usersRouter } from './users'
9import { videosRouter } from './videos' 9import { videosRouter } from './videos'
10import { jobsRouter } from './jobs'
10 11
11const apiRouter = express.Router() 12const apiRouter = express.Router()
12 13
@@ -15,6 +16,7 @@ apiRouter.use('/oauth-clients', oauthClientsRouter)
15apiRouter.use('/config', configRouter) 16apiRouter.use('/config', configRouter)
16apiRouter.use('/users', usersRouter) 17apiRouter.use('/users', usersRouter)
17apiRouter.use('/videos', videosRouter) 18apiRouter.use('/videos', videosRouter)
19apiRouter.use('/jobs', jobsRouter)
18apiRouter.use('/ping', pong) 20apiRouter.use('/ping', pong)
19apiRouter.use('/*', badRequest) 21apiRouter.use('/*', badRequest)
20 22
diff --git a/server/controllers/api/jobs.ts b/server/controllers/api/jobs.ts
new file mode 100644
index 000000000..f6fbff369
--- /dev/null
+++ b/server/controllers/api/jobs.ts
@@ -0,0 +1,34 @@
1import * as express from 'express'
2import { asyncMiddleware, jobsSortValidator, setJobsSort, setPagination } from '../../middlewares'
3import { paginationValidator } from '../../middlewares/validators/pagination'
4import { database as db } from '../../initializers'
5import { getFormattedObjects } from '../../helpers/utils'
6import { authenticate } from '../../middlewares/oauth'
7import { ensureUserHasRight } from '../../middlewares/user-right'
8import { UserRight } from '../../../shared/models/users/user-right.enum'
9
10const jobsRouter = express.Router()
11
12jobsRouter.get('/',
13 authenticate,
14 ensureUserHasRight(UserRight.MANAGE_JOBS),
15 paginationValidator,
16 jobsSortValidator,
17 setJobsSort,
18 setPagination,
19 asyncMiddleware(listJobs)
20)
21
22// ---------------------------------------------------------------------------
23
24export {
25 jobsRouter
26}
27
28// ---------------------------------------------------------------------------
29
30async function listJobs (req: express.Request, res: express.Response, next: express.NextFunction) {
31 const resultList = await db.Job.listForApi(req.query.start, req.query.count, req.query.sort)
32
33 return res.json(getFormattedObjects(resultList.data, resultList.total))
34}