aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/runners/registration-tokens.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2023-04-21 14:55:10 +0200
committerChocobozzz <chocobozzz@cpy.re>2023-05-09 08:57:34 +0200
commit0c9668f77901e7540e2c7045eb0f2974a4842a69 (patch)
tree226d3dd1565b0bb56588897af3b8530e6216e96b /server/controllers/api/runners/registration-tokens.ts
parent6bcb854cdea8688a32240bc5719c7d139806e00b (diff)
downloadPeerTube-0c9668f77901e7540e2c7045eb0f2974a4842a69.tar.gz
PeerTube-0c9668f77901e7540e2c7045eb0f2974a4842a69.tar.zst
PeerTube-0c9668f77901e7540e2c7045eb0f2974a4842a69.zip
Implement remote runner jobs in server
Move ffmpeg functions to @shared
Diffstat (limited to 'server/controllers/api/runners/registration-tokens.ts')
-rw-r--r--server/controllers/api/runners/registration-tokens.ts87
1 files changed, 87 insertions, 0 deletions
diff --git a/server/controllers/api/runners/registration-tokens.ts b/server/controllers/api/runners/registration-tokens.ts
new file mode 100644
index 000000000..5ac3773fe
--- /dev/null
+++ b/server/controllers/api/runners/registration-tokens.ts
@@ -0,0 +1,87 @@
1import express from 'express'
2import { generateRunnerRegistrationToken } from '@server/helpers/token-generator'
3import {
4 asyncMiddleware,
5 authenticate,
6 ensureUserHasRight,
7 paginationValidator,
8 runnerRegistrationTokensSortValidator,
9 setDefaultPagination,
10 setDefaultSort
11} from '@server/middlewares'
12import { deleteRegistrationTokenValidator } from '@server/middlewares/validators/runners'
13import { RunnerRegistrationTokenModel } from '@server/models/runner/runner-registration-token'
14import { HttpStatusCode, ListRunnerRegistrationTokensQuery, UserRight } from '@shared/models'
15import { logger, loggerTagsFactory } from '@server/helpers/logger'
16
17const lTags = loggerTagsFactory('api', 'runner')
18
19const runnerRegistrationTokensRouter = express.Router()
20
21runnerRegistrationTokensRouter.post('/registration-tokens/generate',
22 authenticate,
23 ensureUserHasRight(UserRight.MANAGE_RUNNERS),
24 asyncMiddleware(generateRegistrationToken)
25)
26
27runnerRegistrationTokensRouter.delete('/registration-tokens/:id',
28 authenticate,
29 ensureUserHasRight(UserRight.MANAGE_RUNNERS),
30 asyncMiddleware(deleteRegistrationTokenValidator),
31 asyncMiddleware(deleteRegistrationToken)
32)
33
34runnerRegistrationTokensRouter.get('/registration-tokens',
35 authenticate,
36 ensureUserHasRight(UserRight.MANAGE_RUNNERS),
37 paginationValidator,
38 runnerRegistrationTokensSortValidator,
39 setDefaultSort,
40 setDefaultPagination,
41 asyncMiddleware(listRegistrationTokens)
42)
43
44// ---------------------------------------------------------------------------
45
46export {
47 runnerRegistrationTokensRouter
48}
49
50// ---------------------------------------------------------------------------
51
52async function generateRegistrationToken (req: express.Request, res: express.Response) {
53 logger.info('Generating new runner registration token.', lTags())
54
55 const registrationToken = new RunnerRegistrationTokenModel({
56 registrationToken: generateRunnerRegistrationToken()
57 })
58
59 await registrationToken.save()
60
61 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
62}
63
64async function deleteRegistrationToken (req: express.Request, res: express.Response) {
65 logger.info('Removing runner registration token.', lTags())
66
67 const runnerRegistrationToken = res.locals.runnerRegistrationToken
68
69 await runnerRegistrationToken.destroy()
70
71 return res.sendStatus(HttpStatusCode.NO_CONTENT_204)
72}
73
74async function listRegistrationTokens (req: express.Request, res: express.Response) {
75 const query: ListRunnerRegistrationTokensQuery = req.query
76
77 const resultList = await RunnerRegistrationTokenModel.listForApi({
78 start: query.start,
79 count: query.count,
80 sort: query.sort
81 })
82
83 return res.json({
84 total: resultList.total,
85 data: resultList.data.map(d => d.toFormattedJSON())
86 })
87}