mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-14 03:43:50 +00:00
v2:feat (#231)
* style: element relationship * feat: utility to add first element * refactor: organise dir * ux: deleting element closes drawer * fix: issue with escaped characters * fix: issue with overflow in events list * fix: prevent event timer from receiving non event * style: prevent small shift on class change * style: visually detach event editor * fix: entry block knows last event * fix: skip event timer updates on non events * fix: prevent electron OPENGL error * style: cleanup text styles * style: unify input styles * refactor: simplify style and composition * refactor: tweaks on style + ts * refactor: add validation to events post * fix: handle non events in event timer * refactor: cleanup unused
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import { body, validationResult } from 'express-validator';
|
||||
|
||||
export const eventSanitizer = [
|
||||
body('title').optional().isString().trim().escape(),
|
||||
body('url').optional().isString().trim().escape(),
|
||||
body('publicInfo').optional().isString().trim().escape(),
|
||||
body('backstageInfo').optional().isString().trim().escape(),
|
||||
body('endMessage').optional().isString().trim().escape(),
|
||||
body('title').optional().isString().trim(),
|
||||
body('url').optional().isString().trim(),
|
||||
body('publicInfo').optional().isString().trim(),
|
||||
body('backstageInfo').optional().isString().trim(),
|
||||
body('endMessage').optional().isString().trim(),
|
||||
(req, res, next) => {
|
||||
const errors = validationResult(req);
|
||||
if (!errors.isEmpty()) return res.status(422).json({ errors: errors.array() });
|
||||
|
||||
@@ -14,17 +14,20 @@ import { socketProvider } from '../classes/socket/SocketController.js';
|
||||
const socket = socketProvider;
|
||||
|
||||
async function _insertAndSync(newEvent) {
|
||||
if (newEvent.order) {
|
||||
const events = DataProvider.getEvents();
|
||||
await DataProvider.insertEventAt(newEvent, newEvent.order);
|
||||
const previousId = events?.[newEvent.order - 1]?.id;
|
||||
_insertEventInTimerAfterId(newEvent, previousId);
|
||||
} else if (newEvent.after) {
|
||||
await DataProvider.insertEventAfterId(newEvent, newEvent.after);
|
||||
_insertEventInTimerAfterId(newEvent, newEvent.after);
|
||||
} else {
|
||||
const afterId = newEvent?.after;
|
||||
if (typeof afterId === 'undefined') {
|
||||
await DataProvider.insertEventAt(newEvent, 0);
|
||||
_insertEventInTimerAfterId(newEvent);
|
||||
if (newEvent.type === 'event') {
|
||||
_insertEventInTimerAfterId(newEvent);
|
||||
}
|
||||
} else {
|
||||
delete newEvent.after;
|
||||
await DataProvider.insertEventAfterId(newEvent, afterId);
|
||||
if (newEvent.type === 'event') {
|
||||
const events = DataProvider.getEvents();
|
||||
const { id } = getPreviousPlayable(events, newEvent.id);
|
||||
_insertEventInTimerAfterId(newEvent, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,14 +54,10 @@ function _updateTimers() {
|
||||
* @private
|
||||
*/
|
||||
function _insertEventInTimerAfterId(event, previousId) {
|
||||
if (typeof previousId === 'undefined') {
|
||||
global.timer.insertEventAtStart(event);
|
||||
} else {
|
||||
try {
|
||||
global.timer.insertEventAfterId(event, previousId);
|
||||
} catch (error) {
|
||||
socket.error('SERVER', `Unable to update object: ${error}`);
|
||||
}
|
||||
try {
|
||||
global.timer.insertEventAfterId(event, previousId);
|
||||
} catch (error) {
|
||||
socket.error('SERVER', `Unable to update object: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,28 +146,29 @@ export const eventsPut = async (req, res) => {
|
||||
|
||||
const eventDataFromRequest = req.body;
|
||||
const eventId = eventDataFromRequest.id;
|
||||
const event = DataProvider.getEventById(eventId);
|
||||
const eventInMemory = DataProvider.getEventById(eventId);
|
||||
|
||||
if (typeof event === 'undefined') {
|
||||
if (typeof eventInMemory === 'undefined') {
|
||||
res.status(400).send(`No event with ID found`);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const newData = await DataProvider.updateEventById(eventId, eventDataFromRequest);
|
||||
const patchedObject = await DataProvider.updateEventById(eventId, eventDataFromRequest);
|
||||
|
||||
if (newData.skip) {
|
||||
_deleteTimerId(eventId);
|
||||
// if it is a skip, make sure it is deleted from timer
|
||||
// event id might already not exist
|
||||
} else {
|
||||
try {
|
||||
_updateTimersSingle(newData.id, eventDataFromRequest);
|
||||
} catch (error) {
|
||||
if (error === 'Event not found') {
|
||||
if (patchedObject.type === 'event') {
|
||||
if (patchedObject.skip) {
|
||||
// if it is a skip, make sure it is deleted from timer
|
||||
_deleteTimerId(patchedObject.id);
|
||||
} else {
|
||||
if (eventInMemory.skip) {
|
||||
// if it was skipped before we add it to the timer
|
||||
const events = DataProvider.getEvents();
|
||||
const { id: previousId } = getPreviousPlayable(events, newData.id);
|
||||
_insertEventInTimerAfterId(newData, previousId);
|
||||
const { id } = getPreviousPlayable(events, patchedObject.id);
|
||||
_insertEventInTimerAfterId(patchedObject, id);
|
||||
} else {
|
||||
// otherwise update as normal
|
||||
_updateTimersSingle(patchedObject.id, patchedObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
import { body, param, validationResult } from 'express-validator';
|
||||
|
||||
export const eventsPostValidator = [
|
||||
body('type').isString().exists().isIn(['event', 'delay', 'block']),
|
||||
(req, res, next) => {
|
||||
const errors = validationResult(req);
|
||||
if (!errors.isEmpty()) return res.status(422).json({ errors: errors.array() });
|
||||
next();
|
||||
},
|
||||
];
|
||||
|
||||
export const eventsPutValidator = [
|
||||
body('id').isString().exists(),
|
||||
(req, res, next) => {
|
||||
|
||||
@@ -56,7 +56,7 @@ const uploadAndParse = async (file, req, res, options) => {
|
||||
} else {
|
||||
await DataProvider.mergeIntoData(result.data);
|
||||
}
|
||||
global.timer.setupWithEventList(newEvents);
|
||||
global.timer.setupWithEventList(newEvents.filter((entry) => entry.type === 'event'));
|
||||
}
|
||||
res.sendStatus(200);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user