From 4c38207a151d7cdf0d908d0d7fa6faa5bc8d6a1a Mon Sep 17 00:00:00 2001 From: arc-alex Date: Sat, 4 Nov 2023 20:34:08 +0100 Subject: [PATCH] add necessary endpoint for http subscription --- .../src/classes/data-provider/DataProvider.ts | 9 +++++ .../src/controllers/ontimeController.ts | 34 +++++++++++++++++-- apps/server/src/routes/ontimeRouter.ts | 8 +++++ 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/apps/server/src/classes/data-provider/DataProvider.ts b/apps/server/src/classes/data-provider/DataProvider.ts index f155ba374..b53121597 100644 --- a/apps/server/src/classes/data-provider/DataProvider.ts +++ b/apps/server/src/classes/data-provider/DataProvider.ts @@ -54,6 +54,10 @@ export class DataProvider { return data.osc; } + static getHttp() { + return data.http; + } + static getAliases() { return data.aliases; } @@ -86,6 +90,11 @@ export class DataProvider { await this.persist(); } + static async setHttp(newData) { + data.http = { ...newData }; + await this.persist(); + } + static getRundown() { return [...data.rundown]; } diff --git a/apps/server/src/controllers/ontimeController.ts b/apps/server/src/controllers/ontimeController.ts index 8a35ec09c..696e012e6 100644 --- a/apps/server/src/controllers/ontimeController.ts +++ b/apps/server/src/controllers/ontimeController.ts @@ -12,6 +12,7 @@ import { PlaybackService } from '../services/PlaybackService.js'; import { eventStore } from '../stores/EventStore.js'; import { isDocker, resolveDbPath } from '../setup.js'; import { oscIntegration } from '../services/integration-service/OscIntegration.js'; +import { httpIntegration } from '../services/integration-service/HttpIntegration.js'; import { logger } from '../classes/Logger.js'; import { deleteAllEvents, forceReset } from '../services/rundown-service/RundownService.js'; @@ -282,15 +283,23 @@ export const getOSC = async (req, res) => { res.status(200).send(osc); }; +// Create controller for GET request to '/ontime/http' +// Returns - +export const getHTTP = async (req, res) => { + const http = DataProvider.getHttp(); + console.log('get http', http) + res.status(200).send(http); +}; + export const postOscSubscriptions = async (req, res) => { if (failEmptyObjects(req.body, res)) { return; } try { - const oscSubscriptions = req.body; + const subscriptions = req.body; const oscSettings = DataProvider.getOsc(); - oscSettings.subscriptions = oscSubscriptions; + oscSettings.subscriptions = subscriptions; await DataProvider.setOsc(oscSettings); // TODO: this update could be more granular, checking that relevant data was changed @@ -303,6 +312,27 @@ export const postOscSubscriptions = async (req, res) => { } }; +export const postHttpSubscriptions = async (req, res) => { + console.log('http post sub') + if (failEmptyObjects(req.body, res)) { + return; + } + + try { + const subscriptions = req.body; + const httpSettings = DataProvider.getHttp(); + httpSettings.subscriptions = subscriptions; + await DataProvider.setHttp(httpSettings); + + const { message } = httpIntegration.init(httpSettings); + logger.info(LogOrigin.Tx, message); + + res.send(httpSettings).status(200); + } catch (error) { + res.status(400).send(error); + } +}; + // Create controller for POST request to '/ontime/osc' // Returns ACK message export const postOSC = async (req, res) => { diff --git a/apps/server/src/routes/ontimeRouter.ts b/apps/server/src/routes/ontimeRouter.ts index 11450bb36..0dde847de 100644 --- a/apps/server/src/routes/ontimeRouter.ts +++ b/apps/server/src/routes/ontimeRouter.ts @@ -6,6 +6,7 @@ import { getAliases, getInfo, getOSC, + getHTTP, getSettings, getUserFields, getViewSettings, @@ -14,6 +15,7 @@ import { postNew, postOSC, postOscSubscriptions, + postHttpSubscriptions, postSettings, postUserFields, postViewSettings, @@ -76,5 +78,11 @@ router.post('/osc', validateOSC, postOSC); // create route between controller and '/ontime/osc-subscriptions' endpoint router.post('/osc-subscriptions', validateSubscription, postOscSubscriptions); +// create route between controller and '/ontime/http' endpoint +router.get('/http', getHTTP); + +// create route between controller and '/ontime/osc-subscriptions' endpoint +router.post('/http-subscriptions', validateSubscription, postHttpSubscriptions); + // create route between controller and '/ontime/new' endpoint router.post('/new', projectSanitiser, postNew);