mirror of
https://github.com/cpvalente/ontime.git
synced 2026-09-10 00:29:41 +00:00
refactor: improve async handling
This commit is contained in:
committed by
Carlos Valente
parent
c65761448d
commit
891bda6661
@@ -55,15 +55,14 @@ export default function GSheetSetup(props: GSheetSetupProps) {
|
|||||||
setLoading('');
|
setLoading('');
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCancelFlow = async () => {
|
const handleCancelFlow = () => {
|
||||||
onCancel();
|
onCancel();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets file from input
|
* Gets file from input
|
||||||
* @param event
|
|
||||||
*/
|
*/
|
||||||
const handleClientSecret = async (event: ChangeEvent<HTMLInputElement>) => {
|
const handleClientSecret = (event: ChangeEvent<HTMLInputElement>) => {
|
||||||
if (!event.target.files?.length) {
|
if (!event.target.files?.length) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,43 +40,43 @@ afterAll(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('addTrigger()', () => {
|
describe('addTrigger()', () => {
|
||||||
beforeEach(() => {
|
beforeEach(async () => {
|
||||||
deleteAllTriggers();
|
await deleteAllTriggers();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should accept a valid automation', () => {
|
it('should accept a valid trigger', async () => {
|
||||||
const testData: TriggerDTO = {
|
const testData: TriggerDTO = {
|
||||||
title: 'test',
|
title: 'test',
|
||||||
trigger: TimerLifeCycle.onLoad,
|
trigger: TimerLifeCycle.onLoad,
|
||||||
automationId: 'test-automation-id',
|
automationId: 'test-automation-id',
|
||||||
};
|
};
|
||||||
|
|
||||||
const trigger = addTrigger(testData);
|
const trigger = await addTrigger(testData);
|
||||||
expect(trigger).toMatchObject(testData);
|
expect(trigger).toMatchObject(testData);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('editTrigger()', () => {
|
describe('editTrigger()', () => {
|
||||||
beforeEach(() => {
|
beforeEach(async () => {
|
||||||
deleteAllTriggers();
|
await deleteAllTriggers();
|
||||||
addTrigger({
|
await addTrigger({
|
||||||
title: 'test-osc',
|
title: 'test-osc',
|
||||||
trigger: TimerLifeCycle.onLoad,
|
trigger: TimerLifeCycle.onLoad,
|
||||||
automationId: 'test-osc-automation',
|
automationId: 'test-osc-automation',
|
||||||
});
|
});
|
||||||
addTrigger({
|
await addTrigger({
|
||||||
title: 'test-http',
|
title: 'test-http',
|
||||||
trigger: TimerLifeCycle.onFinish,
|
trigger: TimerLifeCycle.onFinish,
|
||||||
automationId: 'test-http-automation',
|
automationId: 'test-http-automation',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should edit the contents of an automation', () => {
|
it('should edit the contents of a trigger', async () => {
|
||||||
const triggers = getAutomationTriggers();
|
const triggers = getAutomationTriggers();
|
||||||
const fistTrigger = triggers[0];
|
const fistTrigger = triggers[0];
|
||||||
expect(fistTrigger).toMatchObject({ id: expect.any(String), title: 'test-osc' });
|
expect(fistTrigger).toMatchObject({ id: expect.any(String), title: 'test-osc' });
|
||||||
|
|
||||||
const editedOSC = editTrigger(fistTrigger.id, {
|
const editedOSC = await editTrigger(fistTrigger.id, {
|
||||||
title: 'edited-title',
|
title: 'edited-title',
|
||||||
trigger: TimerLifeCycle.onDanger,
|
trigger: TimerLifeCycle.onDanger,
|
||||||
automationId: 'test-osc-automation',
|
automationId: 'test-osc-automation',
|
||||||
@@ -92,9 +92,9 @@ describe('editTrigger()', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('deleteTrigger()', () => {
|
describe('deleteTrigger()', () => {
|
||||||
beforeEach(() => {
|
beforeEach(async () => {
|
||||||
deleteAllTriggers();
|
await deleteAllTriggers();
|
||||||
addTrigger({
|
await addTrigger({
|
||||||
title: 'test-osc',
|
title: 'test-osc',
|
||||||
trigger: TimerLifeCycle.onLoad,
|
trigger: TimerLifeCycle.onLoad,
|
||||||
automationId: 'test-osc-automation',
|
automationId: 'test-osc-automation',
|
||||||
@@ -106,13 +106,13 @@ describe('deleteTrigger()', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should remove an automation from the list', () => {
|
it('should remove an automation from the list', async () => {
|
||||||
const triggers = getAutomationTriggers();
|
const triggers = getAutomationTriggers();
|
||||||
expect(triggers.length).toEqual(2);
|
expect(triggers.length).toEqual(2);
|
||||||
const fistTrigger = triggers[0];
|
const fistTrigger = triggers[0];
|
||||||
expect(fistTrigger).toMatchObject({ id: expect.any(String), title: 'test-osc' });
|
expect(fistTrigger).toMatchObject({ id: expect.any(String), title: 'test-osc' });
|
||||||
|
|
||||||
deleteTrigger(fistTrigger.id);
|
await deleteTrigger(fistTrigger.id);
|
||||||
const removed = getAutomationTriggers();
|
const removed = getAutomationTriggers();
|
||||||
expect(removed.length).toEqual(1);
|
expect(removed.length).toEqual(1);
|
||||||
expect(removed[0].title).not.toEqual('test-osc');
|
expect(removed[0].title).not.toEqual('test-osc');
|
||||||
@@ -120,11 +120,11 @@ describe('deleteTrigger()', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe('addAutomation()', () => {
|
describe('addAutomation()', () => {
|
||||||
beforeEach(() => {
|
beforeEach(async () => {
|
||||||
deleteAll();
|
await deleteAll();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should accept a valid automation', () => {
|
it('should accept a valid automation', async () => {
|
||||||
const testData: AutomationDTO = {
|
const testData: AutomationDTO = {
|
||||||
title: 'test',
|
title: 'test',
|
||||||
filterRule: 'all',
|
filterRule: 'all',
|
||||||
@@ -132,24 +132,24 @@ describe('addAutomation()', () => {
|
|||||||
outputs: [makeOSCAction(), makeHTTPAction()],
|
outputs: [makeOSCAction(), makeHTTPAction()],
|
||||||
};
|
};
|
||||||
|
|
||||||
const automation = addAutomation(testData);
|
const automation = await addAutomation(testData);
|
||||||
const automations = getAutomations();
|
const automations = getAutomations();
|
||||||
expect(automations[automation.id]).toMatchObject(testData);
|
expect(automations[automation.id]).toMatchObject(testData);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('editAutomation()', () => {
|
describe('editAutomation()', async () => {
|
||||||
// saving the ID of the added automation
|
// saving the ID of the added automation
|
||||||
let firstAutomation: Automation;
|
let firstAutomation: Automation;
|
||||||
beforeEach(() => {
|
beforeEach(async () => {
|
||||||
deleteAll();
|
await deleteAll();
|
||||||
firstAutomation = addAutomation({
|
firstAutomation = await addAutomation({
|
||||||
title: 'test-osc',
|
title: 'test-osc',
|
||||||
filterRule: 'all',
|
filterRule: 'all',
|
||||||
filters: [],
|
filters: [],
|
||||||
outputs: [],
|
outputs: [],
|
||||||
});
|
});
|
||||||
addAutomation({
|
await addAutomation({
|
||||||
title: 'test-http',
|
title: 'test-http',
|
||||||
filterRule: 'all',
|
filterRule: 'all',
|
||||||
filters: [],
|
filters: [],
|
||||||
@@ -157,7 +157,7 @@ describe('editAutomation()', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should edit the contents of an automation', () => {
|
it('should edit the contents of an automation', async () => {
|
||||||
const automations = getAutomations();
|
const automations = getAutomations();
|
||||||
expect(Object.keys(automations).length).toEqual(2);
|
expect(Object.keys(automations).length).toEqual(2);
|
||||||
expect(automations[firstAutomation.id]).toMatchObject({
|
expect(automations[firstAutomation.id]).toMatchObject({
|
||||||
@@ -168,7 +168,7 @@ describe('editAutomation()', () => {
|
|||||||
outputs: expect.any(Array),
|
outputs: expect.any(Array),
|
||||||
});
|
});
|
||||||
|
|
||||||
const editedOSC = editAutomation(firstAutomation.id, {
|
const editedOSC = await editAutomation(firstAutomation.id, {
|
||||||
title: 'edited-title',
|
title: 'edited-title',
|
||||||
filterRule: 'any',
|
filterRule: 'any',
|
||||||
filters: [],
|
filters: [],
|
||||||
@@ -188,9 +188,9 @@ describe('editAutomation()', () => {
|
|||||||
describe('deleteAutomation()', () => {
|
describe('deleteAutomation()', () => {
|
||||||
// saving the ID of the added automation
|
// saving the ID of the added automation
|
||||||
let firstAutomation: Automation;
|
let firstAutomation: Automation;
|
||||||
beforeEach(() => {
|
beforeEach(async () => {
|
||||||
deleteAll();
|
await deleteAll();
|
||||||
firstAutomation = addAutomation({
|
firstAutomation = await addAutomation({
|
||||||
title: 'test-osc',
|
title: 'test-osc',
|
||||||
filterRule: 'all',
|
filterRule: 'all',
|
||||||
filters: [],
|
filters: [],
|
||||||
@@ -198,18 +198,18 @@ describe('deleteAutomation()', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should remove m automation from the list', () => {
|
it('should remove m automation from the list', async () => {
|
||||||
const automations = getAutomations();
|
const automations = getAutomations();
|
||||||
expect(Object.keys(automations).length).toEqual(1);
|
expect(Object.keys(automations).length).toEqual(1);
|
||||||
|
|
||||||
deleteAutomation(Object.keys(automations)[0]);
|
await deleteAutomation(Object.keys(automations)[0]);
|
||||||
const removed = getAutomations();
|
const removed = getAutomations();
|
||||||
expect(Object.keys(removed).length).toEqual(0);
|
expect(Object.keys(removed).length).toEqual(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not remove an automation which is in use', () => {
|
it('should not remove an automation which is in use', async () => {
|
||||||
const automations = getAutomations();
|
const automations = getAutomations();
|
||||||
addTrigger({
|
await addTrigger({
|
||||||
title: 'test-automation',
|
title: 'test-automation',
|
||||||
trigger: TimerLifeCycle.onLoad,
|
trigger: TimerLifeCycle.onLoad,
|
||||||
automationId: firstAutomation.id,
|
automationId: firstAutomation.id,
|
||||||
@@ -227,6 +227,6 @@ describe('deleteAutomation()', () => {
|
|||||||
outputs: expect.any(Array),
|
outputs: expect.any(Array),
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(() => deleteAutomation(automationId)).toThrowError();
|
await expect(deleteAutomation(automationId)).rejects.toThrowError();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -39,29 +39,29 @@ describe('triggerAction()', () => {
|
|||||||
let oscSpy = vi.spyOn(oscClient, 'emitOSC');
|
let oscSpy = vi.spyOn(oscClient, 'emitOSC');
|
||||||
let httpSpy = vi.spyOn(httpClient, 'emitHTTP');
|
let httpSpy = vi.spyOn(httpClient, 'emitHTTP');
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(async () => {
|
||||||
oscSpy = vi.spyOn(oscClient, 'emitOSC').mockImplementation(() => {});
|
oscSpy = vi.spyOn(oscClient, 'emitOSC').mockImplementation(() => {});
|
||||||
httpSpy = vi.spyOn(httpClient, 'emitHTTP').mockImplementation(() => {});
|
httpSpy = vi.spyOn(httpClient, 'emitHTTP').mockImplementation(() => {});
|
||||||
|
|
||||||
deleteAllTriggers();
|
await deleteAllTriggers();
|
||||||
const oscAutomation = addAutomation({
|
const oscAutomation = await addAutomation({
|
||||||
title: 'test-osc',
|
title: 'test-osc',
|
||||||
filterRule: 'all',
|
filterRule: 'all',
|
||||||
filters: [],
|
filters: [],
|
||||||
outputs: [makeOSCAction()],
|
outputs: [makeOSCAction()],
|
||||||
});
|
});
|
||||||
const httpAutomation = addAutomation({
|
const httpAutomation = await addAutomation({
|
||||||
title: 'test-http',
|
title: 'test-http',
|
||||||
filterRule: 'any',
|
filterRule: 'any',
|
||||||
filters: [],
|
filters: [],
|
||||||
outputs: [makeHTTPAction()],
|
outputs: [makeHTTPAction()],
|
||||||
});
|
});
|
||||||
addTrigger({
|
await addTrigger({
|
||||||
title: 'test-osc',
|
title: 'test-osc',
|
||||||
trigger: TimerLifeCycle.onLoad,
|
trigger: TimerLifeCycle.onLoad,
|
||||||
automationId: oscAutomation.id,
|
automationId: oscAutomation.id,
|
||||||
});
|
});
|
||||||
addTrigger({
|
await addTrigger({
|
||||||
title: 'test-http',
|
title: 'test-http',
|
||||||
trigger: TimerLifeCycle.onFinish,
|
trigger: TimerLifeCycle.onFinish,
|
||||||
automationId: httpAutomation.id,
|
automationId: httpAutomation.id,
|
||||||
|
|||||||
@@ -11,10 +11,10 @@ export function getAutomationSettings(_req: Request, res: Response<AutomationSet
|
|||||||
res.json(automationDao.getAutomationSettings());
|
res.json(automationDao.getAutomationSettings());
|
||||||
}
|
}
|
||||||
|
|
||||||
export function postAutomationSettings(req: Request, res: Response<AutomationSettings | ErrorResponse>) {
|
export async function postAutomationSettings(req: Request, res: Response<AutomationSettings | ErrorResponse>) {
|
||||||
try {
|
try {
|
||||||
// body payload is a patch object that must contain root properties
|
// body payload is a patch object that must contain root properties
|
||||||
const automationSettings = automationDao.editAutomationSettings({
|
const automationSettings = await automationDao.editAutomationSettings({
|
||||||
enabledAutomations: req.body.enabledAutomations,
|
enabledAutomations: req.body.enabledAutomations,
|
||||||
enabledOscIn: req.body.enabledOscIn,
|
enabledOscIn: req.body.enabledOscIn,
|
||||||
oscPortIn: req.body.oscPortIn,
|
oscPortIn: req.body.oscPortIn,
|
||||||
@@ -33,9 +33,9 @@ export function postAutomationSettings(req: Request, res: Response<AutomationSet
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function postTrigger(req: Request, res: Response<Trigger | ErrorResponse>) {
|
export async function postTrigger(req: Request, res: Response<Trigger | ErrorResponse>) {
|
||||||
try {
|
try {
|
||||||
const automation = automationDao.addTrigger({
|
const automation = await automationDao.addTrigger({
|
||||||
title: req.body.title,
|
title: req.body.title,
|
||||||
trigger: req.body.trigger,
|
trigger: req.body.trigger,
|
||||||
automationId: req.body.automationId,
|
automationId: req.body.automationId,
|
||||||
@@ -47,10 +47,10 @@ export function postTrigger(req: Request, res: Response<Trigger | ErrorResponse>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function putTrigger(req: Request, res: Response<Trigger | ErrorResponse>) {
|
export async function putTrigger(req: Request, res: Response<Trigger | ErrorResponse>) {
|
||||||
try {
|
try {
|
||||||
// body payload is a patch object
|
// body payload is a patch object
|
||||||
const automation = automationDao.editTrigger(req.params.id, {
|
const automation = await automationDao.editTrigger(req.params.id, {
|
||||||
title: req.body.title ?? undefined,
|
title: req.body.title ?? undefined,
|
||||||
trigger: req.body.trigger ?? undefined,
|
trigger: req.body.trigger ?? undefined,
|
||||||
automationId: req.body.automationId ?? undefined,
|
automationId: req.body.automationId ?? undefined,
|
||||||
@@ -62,9 +62,9 @@ export function putTrigger(req: Request, res: Response<Trigger | ErrorResponse>)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteTrigger(req: Request, res: Response<void | ErrorResponse>) {
|
export async function deleteTrigger(req: Request, res: Response<void | ErrorResponse>) {
|
||||||
try {
|
try {
|
||||||
automationDao.deleteTrigger(req.params.id);
|
await automationDao.deleteTrigger(req.params.id);
|
||||||
res.status(204).send();
|
res.status(204).send();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = getErrorMessage(error);
|
const message = getErrorMessage(error);
|
||||||
@@ -72,9 +72,9 @@ export function deleteTrigger(req: Request, res: Response<void | ErrorResponse>)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function postAutomation(req: Request, res: Response<Automation | ErrorResponse>) {
|
export async function postAutomation(req: Request, res: Response<Automation | ErrorResponse>) {
|
||||||
try {
|
try {
|
||||||
const newAutomation = automationDao.addAutomation({
|
const newAutomation = await automationDao.addAutomation({
|
||||||
title: req.body.title,
|
title: req.body.title,
|
||||||
filterRule: req.body.filterRule,
|
filterRule: req.body.filterRule,
|
||||||
filters: req.body.filters,
|
filters: req.body.filters,
|
||||||
@@ -87,9 +87,9 @@ export function postAutomation(req: Request, res: Response<Automation | ErrorRes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function editAutomation(req: Request, res: Response<Automation | ErrorResponse>) {
|
export async function editAutomation(req: Request, res: Response<Automation | ErrorResponse>) {
|
||||||
try {
|
try {
|
||||||
const newAutomation = automationDao.editAutomation(req.params.id, {
|
const newAutomation = await automationDao.editAutomation(req.params.id, {
|
||||||
title: req.body.title,
|
title: req.body.title,
|
||||||
filterRule: req.body.filterRule,
|
filterRule: req.body.filterRule,
|
||||||
filters: req.body.filters,
|
filters: req.body.filters,
|
||||||
@@ -102,9 +102,9 @@ export function editAutomation(req: Request, res: Response<Automation | ErrorRes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deleteAutomation(req: Request, res: Response<void | ErrorResponse>) {
|
export async function deleteAutomation(req: Request, res: Response<void | ErrorResponse>) {
|
||||||
try {
|
try {
|
||||||
automationDao.deleteAutomation(req.params.id);
|
await automationDao.deleteAutomation(req.params.id);
|
||||||
res.status(204).send();
|
res.status(204).send();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const message = getErrorMessage(error);
|
const message = getErrorMessage(error);
|
||||||
|
|||||||
@@ -1,4 +1,11 @@
|
|||||||
import type { Automation, AutomationDTO, AutomationSettings, NormalisedAutomation, Trigger, TriggerDTO } from 'ontime-types';
|
import type {
|
||||||
|
Automation,
|
||||||
|
AutomationDTO,
|
||||||
|
AutomationSettings,
|
||||||
|
NormalisedAutomation,
|
||||||
|
Trigger,
|
||||||
|
TriggerDTO,
|
||||||
|
} from 'ontime-types';
|
||||||
import { deleteAtIndex, generateId } from 'ontime-utils';
|
import { deleteAtIndex, generateId } from 'ontime-utils';
|
||||||
|
|
||||||
import { getDataProvider } from '../../classes/data-provider/DataProvider.js';
|
import { getDataProvider } from '../../classes/data-provider/DataProvider.js';
|
||||||
@@ -34,27 +41,27 @@ export function getAutomations(): NormalisedAutomation {
|
|||||||
/**
|
/**
|
||||||
* Patches the automation settings object
|
* Patches the automation settings object
|
||||||
*/
|
*/
|
||||||
export function editAutomationSettings(settings: Partial<AutomationSettings>): AutomationSettings {
|
export async function editAutomationSettings(settings: Partial<AutomationSettings>): Promise<AutomationSettings> {
|
||||||
saveChanges(settings);
|
await saveChanges(settings);
|
||||||
return getAutomationSettings();
|
return getAutomationSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a validated automation to the store
|
* Adds a validated automation to the store
|
||||||
*/
|
*/
|
||||||
export function addTrigger(newTrigger: TriggerDTO): Trigger {
|
export async function addTrigger(newTrigger: TriggerDTO): Promise<Trigger> {
|
||||||
const triggers = getAutomationTriggers();
|
const triggers = getAutomationTriggers();
|
||||||
const id = getUniqueTriggerId(triggers);
|
const id = getUniqueTriggerId(triggers);
|
||||||
const trigger = { ...newTrigger, id };
|
const trigger = { ...newTrigger, id };
|
||||||
triggers.push(trigger);
|
triggers.push(trigger);
|
||||||
saveChanges({ triggers });
|
await saveChanges({ triggers });
|
||||||
return trigger;
|
return trigger;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Patches an existing automation trigger
|
* Patches an existing automation trigger
|
||||||
*/
|
*/
|
||||||
export function editTrigger(id: string, newTrigger: TriggerDTO): Trigger {
|
export async function editTrigger(id: string, newTrigger: TriggerDTO): Promise<Trigger> {
|
||||||
const triggers = getAutomationTriggers();
|
const triggers = getAutomationTriggers();
|
||||||
const index = triggers.findIndex((trigger) => trigger.id === id);
|
const index = triggers.findIndex((trigger) => trigger.id === id);
|
||||||
|
|
||||||
@@ -63,14 +70,14 @@ export function editTrigger(id: string, newTrigger: TriggerDTO): Trigger {
|
|||||||
}
|
}
|
||||||
|
|
||||||
triggers[index] = { ...triggers[index], ...newTrigger };
|
triggers[index] = { ...triggers[index], ...newTrigger };
|
||||||
saveChanges({ triggers });
|
await saveChanges({ triggers });
|
||||||
return triggers[index];
|
return triggers[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes an automation trigger given its ID
|
* Deletes an automation trigger given its ID
|
||||||
*/
|
*/
|
||||||
export function deleteTrigger(id: string): void {
|
export async function deleteTrigger(id: string): Promise<void> {
|
||||||
let triggers = getAutomationTriggers();
|
let triggers = getAutomationTriggers();
|
||||||
const index = triggers.findIndex((trigger) => trigger.id === id);
|
const index = triggers.findIndex((trigger) => trigger.id === id);
|
||||||
|
|
||||||
@@ -79,53 +86,53 @@ export function deleteTrigger(id: string): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
triggers = deleteAtIndex(index, triggers);
|
triggers = deleteAtIndex(index, triggers);
|
||||||
saveChanges({ triggers });
|
await saveChanges({ triggers });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes all project automation triggers
|
* Deletes all project automation triggers
|
||||||
*/
|
*/
|
||||||
export function deleteAllTriggers(): void {
|
export async function deleteAllTriggers(): Promise<void> {
|
||||||
saveChanges({ triggers: [] });
|
await saveChanges({ triggers: [] });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes all project automation triggers and automations
|
* Deletes all project automation triggers and automations
|
||||||
* We do this together to avoid issues with missing references
|
* We do this together to avoid issues with missing references
|
||||||
*/
|
*/
|
||||||
export function deleteAll(): void {
|
export async function deleteAll() {
|
||||||
saveChanges({ triggers: [], automations: {} });
|
await saveChanges({ triggers: [], automations: {} });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a validated automation to the store
|
* Adds a validated automation to the store
|
||||||
*/
|
*/
|
||||||
export function addAutomation(newAutomation: AutomationDTO): Automation {
|
export async function addAutomation(newAutomation: AutomationDTO): Promise<Automation> {
|
||||||
const automations = getAutomations();
|
const automations = getAutomations();
|
||||||
const id = getUniqueAutomationId(automations);
|
const id = getUniqueAutomationId(automations);
|
||||||
automations[id] = { ...newAutomation, id };
|
automations[id] = { ...newAutomation, id };
|
||||||
saveChanges({ automations });
|
await saveChanges({ automations });
|
||||||
return automations[id];
|
return automations[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates an existing automation with a new entry
|
* Updates an existing automation with a new entry
|
||||||
*/
|
*/
|
||||||
export function editAutomation(id: string, newAutomation: AutomationDTO): Automation {
|
export async function editAutomation(id: string, newAutomation: AutomationDTO): Promise<Automation> {
|
||||||
const automations = getAutomations();
|
const automations = getAutomations();
|
||||||
if (!Object.hasOwn(automations, id)) {
|
if (!Object.hasOwn(automations, id)) {
|
||||||
throw new Error(`Automation with id ${id} not found`);
|
throw new Error(`Automation with id ${id} not found`);
|
||||||
}
|
}
|
||||||
|
|
||||||
automations[id] = { ...newAutomation, id };
|
automations[id] = { ...newAutomation, id };
|
||||||
saveChanges({ automations });
|
await saveChanges({ automations });
|
||||||
return automations[id];
|
return automations[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a automation given its ID
|
* Deletes a automation given its ID
|
||||||
*/
|
*/
|
||||||
export function deleteAutomation(id: string): void {
|
export async function deleteAutomation(id: string): Promise<void> {
|
||||||
const automations = getAutomations();
|
const automations = getAutomations();
|
||||||
// ignore request if automation does not exist
|
// ignore request if automation does not exist
|
||||||
if (!Object.hasOwn(automations, id)) {
|
if (!Object.hasOwn(automations, id)) {
|
||||||
@@ -140,7 +147,7 @@ export function deleteAutomation(id: string): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete automations[id];
|
delete automations[id];
|
||||||
saveChanges({ automations });
|
await saveChanges({ automations });
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ export const initAssets = async () => {
|
|||||||
checkStart(OntimeStartOrder.InitAssets);
|
checkStart(OntimeStartOrder.InitAssets);
|
||||||
await clearUploadfolder();
|
await clearUploadfolder();
|
||||||
populateStyles();
|
populateStyles();
|
||||||
populateDemo();
|
await populateDemo();
|
||||||
const project = await initialiseProject();
|
const project = await initialiseProject();
|
||||||
logger.info(LogOrigin.Server, `Initialised Ontime with ${project}`);
|
logger.info(LogOrigin.Server, `Initialised Ontime with ${project}`);
|
||||||
};
|
};
|
||||||
@@ -200,7 +200,7 @@ export const startServer = async (
|
|||||||
// initialise rundown service
|
// initialise rundown service
|
||||||
const persistedRundown = getDataProvider().getRundown();
|
const persistedRundown = getDataProvider().getRundown();
|
||||||
const persistedCustomFields = getDataProvider().getCustomFields();
|
const persistedCustomFields = getDataProvider().getCustomFields();
|
||||||
initRundown(persistedRundown, persistedCustomFields);
|
await initRundown(persistedRundown, persistedCustomFields);
|
||||||
|
|
||||||
// initialise message service
|
// initialise message service
|
||||||
messageService.init(eventStore.set, eventStore.get);
|
messageService.init(eventStore.set, eventStore.get);
|
||||||
|
|||||||
@@ -114,18 +114,13 @@ async function getDeviceCodes(clientSecret: ClientSecret): Promise<CodesResponse
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets credentials from Google Auth server
|
* Gets credentials from Google Auth server
|
||||||
* @param clientSecret
|
|
||||||
* @param device_code
|
|
||||||
* @param interval
|
|
||||||
* @param expires_in
|
|
||||||
* @param postAction
|
|
||||||
*/
|
*/
|
||||||
function verifyConnection(
|
function verifyConnection(
|
||||||
clientSecret: ClientSecret,
|
clientSecret: ClientSecret,
|
||||||
device_code: string,
|
device_code: string,
|
||||||
interval: number,
|
interval: number,
|
||||||
expires_in: number,
|
expires_in: number,
|
||||||
postAction: () => void,
|
postAction: () => Promise<any>,
|
||||||
) {
|
) {
|
||||||
// create poller to check for auth
|
// create poller to check for auth
|
||||||
pollInterval = setInterval(pollForAuth, interval * 1000);
|
pollInterval = setInterval(pollForAuth, interval * 1000);
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ import { publicDir, publicFiles, srcDir, srcFiles } from './index.js';
|
|||||||
/**
|
/**
|
||||||
* @description ensures directories exist and populates demo folder
|
* @description ensures directories exist and populates demo folder
|
||||||
*/
|
*/
|
||||||
export const populateDemo = () => {
|
export async function populateDemo() {
|
||||||
ensureDirectory(publicDir.demoDir);
|
ensureDirectory(publicDir.demoDir);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
copyFileSync(srcFiles.externalReadme, publicFiles.externalReadme);
|
copyFileSync(srcFiles.externalReadme, publicFiles.externalReadme);
|
||||||
// even if demo exist we want to use startup demo
|
// even if demo exist we want to use startup demo
|
||||||
copyDirectory(srcDir.demoDir, publicDir.demoDir);
|
await copyDirectory(srcDir.demoDir, publicDir.demoDir);
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
/* we do not handle this */
|
/* we do not handle this */
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user