diff options
author | Chocobozzz <me@florianbigard.com> | 2023-04-21 14:55:10 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2023-05-09 08:57:34 +0200 |
commit | 0c9668f77901e7540e2c7045eb0f2974a4842a69 (patch) | |
tree | 226d3dd1565b0bb56588897af3b8530e6216e96b /server/controllers/api/runners/registration-tokens.ts | |
parent | 6bcb854cdea8688a32240bc5719c7d139806e00b (diff) | |
download | PeerTube-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.ts | 87 |
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 @@ | |||
1 | import express from 'express' | ||
2 | import { generateRunnerRegistrationToken } from '@server/helpers/token-generator' | ||
3 | import { | ||
4 | asyncMiddleware, | ||
5 | authenticate, | ||
6 | ensureUserHasRight, | ||
7 | paginationValidator, | ||
8 | runnerRegistrationTokensSortValidator, | ||
9 | setDefaultPagination, | ||
10 | setDefaultSort | ||
11 | } from '@server/middlewares' | ||
12 | import { deleteRegistrationTokenValidator } from '@server/middlewares/validators/runners' | ||
13 | import { RunnerRegistrationTokenModel } from '@server/models/runner/runner-registration-token' | ||
14 | import { HttpStatusCode, ListRunnerRegistrationTokensQuery, UserRight } from '@shared/models' | ||
15 | import { logger, loggerTagsFactory } from '@server/helpers/logger' | ||
16 | |||
17 | const lTags = loggerTagsFactory('api', 'runner') | ||
18 | |||
19 | const runnerRegistrationTokensRouter = express.Router() | ||
20 | |||
21 | runnerRegistrationTokensRouter.post('/registration-tokens/generate', | ||
22 | authenticate, | ||
23 | ensureUserHasRight(UserRight.MANAGE_RUNNERS), | ||
24 | asyncMiddleware(generateRegistrationToken) | ||
25 | ) | ||
26 | |||
27 | runnerRegistrationTokensRouter.delete('/registration-tokens/:id', | ||
28 | authenticate, | ||
29 | ensureUserHasRight(UserRight.MANAGE_RUNNERS), | ||
30 | asyncMiddleware(deleteRegistrationTokenValidator), | ||
31 | asyncMiddleware(deleteRegistrationToken) | ||
32 | ) | ||
33 | |||
34 | runnerRegistrationTokensRouter.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 | |||
46 | export { | ||
47 | runnerRegistrationTokensRouter | ||
48 | } | ||
49 | |||
50 | // --------------------------------------------------------------------------- | ||
51 | |||
52 | async 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 | |||
64 | async 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 | |||
74 | async 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 | } | ||