mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-21 06:59:09 +00:00
unify osc and http validateSubscriptionEntry
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { body, check, validationResult } from 'express-validator';
|
import { body, check, validationResult } from 'express-validator';
|
||||||
import { validateOscObject, validateOscSubscriptionEntry } from '../utils/parserFunctions.js';
|
import { validateOscObject, validateSubscriptionEntry } from '../utils/parserFunctions.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description Validates object for POST /ontime/views
|
* @description Validates object for POST /ontime/views
|
||||||
@@ -93,25 +93,25 @@ export const validateOSC = [
|
|||||||
/**
|
/**
|
||||||
* @description Validates object for POST /ontime/osc-subscriptions
|
* @description Validates object for POST /ontime/osc-subscriptions
|
||||||
*/
|
*/
|
||||||
export const validateOscSubscription = [
|
export const validateSubscription = [
|
||||||
body('onLoad')
|
body('onLoad')
|
||||||
.isArray()
|
.isArray()
|
||||||
.custom((value) => validateOscSubscriptionEntry(value)),
|
.custom((value) => validateSubscriptionEntry(value)),
|
||||||
body('onStart')
|
body('onStart')
|
||||||
.isArray()
|
.isArray()
|
||||||
.custom((value) => validateOscSubscriptionEntry(value)),
|
.custom((value) => validateSubscriptionEntry(value)),
|
||||||
body('onPause')
|
body('onPause')
|
||||||
.isArray()
|
.isArray()
|
||||||
.custom((value) => validateOscSubscriptionEntry(value)),
|
.custom((value) => validateSubscriptionEntry(value)),
|
||||||
body('onStop')
|
body('onStop')
|
||||||
.isArray()
|
.isArray()
|
||||||
.custom((value) => validateOscSubscriptionEntry(value)),
|
.custom((value) => validateSubscriptionEntry(value)),
|
||||||
body('onUpdate')
|
body('onUpdate')
|
||||||
.isArray()
|
.isArray()
|
||||||
.custom((value) => validateOscSubscriptionEntry(value)),
|
.custom((value) => validateSubscriptionEntry(value)),
|
||||||
body('onFinish')
|
body('onFinish')
|
||||||
.isArray()
|
.isArray()
|
||||||
.custom((value) => validateOscSubscriptionEntry(value)),
|
.custom((value) => validateSubscriptionEntry(value)),
|
||||||
(req, res, next) => {
|
(req, res, next) => {
|
||||||
const errors = validationResult(req);
|
const errors = validationResult(req);
|
||||||
if (!errors.isEmpty()) return res.status(422).json({ errors: errors.array() });
|
if (!errors.isEmpty()) return res.status(422).json({ errors: errors.array() });
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
validateAliases,
|
validateAliases,
|
||||||
validateOSC,
|
validateOSC,
|
||||||
validateOscSubscription,
|
validateSubscription,
|
||||||
validateSettings,
|
validateSettings,
|
||||||
validateUserFields,
|
validateUserFields,
|
||||||
viewValidator,
|
viewValidator,
|
||||||
@@ -74,7 +74,7 @@ router.get('/osc', getOSC);
|
|||||||
router.post('/osc', validateOSC, postOSC);
|
router.post('/osc', validateOSC, postOSC);
|
||||||
|
|
||||||
// create route between controller and '/ontime/osc-subscriptions' endpoint
|
// create route between controller and '/ontime/osc-subscriptions' endpoint
|
||||||
router.post('/osc-subscriptions', validateOscSubscription, postOscSubscriptions);
|
router.post('/osc-subscriptions', validateSubscription, postOscSubscriptions);
|
||||||
|
|
||||||
// create route between controller and '/ontime/new' endpoint
|
// create route between controller and '/ontime/new' endpoint
|
||||||
router.post('/new', projectSanitiser, postNew);
|
router.post('/new', projectSanitiser, postNew);
|
||||||
|
|||||||
@@ -191,7 +191,7 @@ export const parseViewSettings = (data, enforce): ViewSettings => {
|
|||||||
* Parses and validates subscription entry
|
* Parses and validates subscription entry
|
||||||
* @param data
|
* @param data
|
||||||
*/
|
*/
|
||||||
export const validateOscSubscriptionEntry = (data: SubscriptionOptions): boolean => {
|
export const validateSubscriptionEntry = (data: SubscriptionOptions): boolean => {
|
||||||
for (const subscription in data) {
|
for (const subscription in data) {
|
||||||
if (typeof data[subscription].message !== 'string' || typeof data[subscription].enabled !== 'boolean') {
|
if (typeof data[subscription].message !== 'string' || typeof data[subscription].enabled !== 'boolean') {
|
||||||
return false;
|
return false;
|
||||||
@@ -253,19 +253,6 @@ export const parseOsc = (
|
|||||||
} else return {};
|
} else return {};
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Parses and validates subscription entry
|
|
||||||
* @param data
|
|
||||||
*/
|
|
||||||
export const validateHttpSubscriptionEntry = (data: SubscriptionOptions): boolean => {
|
|
||||||
for (const subscription in data) {
|
|
||||||
if (typeof data[subscription].message !== 'string' || typeof data[subscription].enabled !== 'boolean') {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses and validates subscription object
|
* Parses and validates subscription object
|
||||||
* @param data
|
* @param data
|
||||||
@@ -309,10 +296,6 @@ export const parseHttp = (
|
|||||||
: dbModel.http.subscriptions;
|
: dbModel.http.subscriptions;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
portIn: loadedConfig.portIn ?? dbModel.http.portIn,
|
|
||||||
portOut: loadedConfig.portOut ?? dbModel.http.portOut,
|
|
||||||
targetIP: loadedConfig.targetIP ?? dbModel.http.targetIP,
|
|
||||||
enabledIn: loadedConfig.enabledIn ?? dbModel.http.enabledIn,
|
|
||||||
enabledOut: loadedConfig.enabledOut ?? dbModel.http.enabledOut,
|
enabledOut: loadedConfig.enabledOut ?? dbModel.http.enabledOut,
|
||||||
subscriptions: validatedSubscriptions,
|
subscriptions: validatedSubscriptions,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user