From 0c9668f77901e7540e2c7045eb0f2974a4842a69 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 21 Apr 2023 14:55:10 +0200 Subject: Implement remote runner jobs in server Move ffmpeg functions to @shared --- .../validators/runners/registration-token.ts | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 server/middlewares/validators/runners/registration-token.ts (limited to 'server/middlewares/validators/runners/registration-token.ts') diff --git a/server/middlewares/validators/runners/registration-token.ts b/server/middlewares/validators/runners/registration-token.ts new file mode 100644 index 000000000..cc31d4a7e --- /dev/null +++ b/server/middlewares/validators/runners/registration-token.ts @@ -0,0 +1,37 @@ +import express from 'express' +import { param } from 'express-validator' +import { isIdValid } from '@server/helpers/custom-validators/misc' +import { RunnerRegistrationTokenModel } from '@server/models/runner/runner-registration-token' +import { forceNumber } from '@shared/core-utils' +import { HttpStatusCode } from '@shared/models' +import { areValidationErrors } from '../shared/utils' + +const tags = [ 'runner' ] + +const deleteRegistrationTokenValidator = [ + param('id').custom(isIdValid), + + async (req: express.Request, res: express.Response, next: express.NextFunction) => { + if (areValidationErrors(req, res, { tags })) return + + const registrationToken = await RunnerRegistrationTokenModel.load(forceNumber(req.params.id)) + + if (!registrationToken) { + return res.fail({ + status: HttpStatusCode.NOT_FOUND_404, + message: 'Registration token not found', + tags + }) + } + + res.locals.runnerRegistrationToken = registrationToken + + return next() + } +] + +// --------------------------------------------------------------------------- + +export { + deleteRegistrationTokenValidator +} -- cgit v1.2.3