mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-20 06:29:07 +00:00
Revert "split url and searchParams allow for post option"
This reverts commit 54ab8d4ffe.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import { Control, useFieldArray, UseFormRegister } from 'react-hook-form';
|
import { Control, useFieldArray, UseFormRegister } from 'react-hook-form';
|
||||||
import { Button, IconButton, Input, Select, Switch } from '@chakra-ui/react';
|
import { Button, IconButton, Input, Switch } from '@chakra-ui/react';
|
||||||
import { FiChevronUp } from '@react-icons/all-files/fi/FiChevronUp';
|
import { FiChevronUp } from '@react-icons/all-files/fi/FiChevronUp';
|
||||||
import { IoRemove } from '@react-icons/all-files/io5/IoRemove';
|
import { IoRemove } from '@react-icons/all-files/io5/IoRemove';
|
||||||
import { HttpSettings, TimerLifeCycle } from 'ontime-types';
|
import { HttpSettings, TimerLifeCycle } from 'ontime-types';
|
||||||
@@ -40,10 +40,8 @@ export default function SubscriptionRow(props: SubscriptionRowProps) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
append({
|
append({
|
||||||
url: '',
|
message: '',
|
||||||
options: '',
|
|
||||||
enabled: false,
|
enabled: false,
|
||||||
method: 'GET',
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -72,26 +70,10 @@ export default function SubscriptionRow(props: SubscriptionRowProps) {
|
|||||||
size='xs'
|
size='xs'
|
||||||
variant='ontime-filled-on-light'
|
variant='ontime-filled-on-light'
|
||||||
autoComplete='off'
|
autoComplete='off'
|
||||||
{...register(`subscriptions.${cycle}.${index}.url`, {
|
{...register(`subscriptions.${cycle}.${index}.message`, {
|
||||||
pattern: { value: startsWithHttpOrS, message: 'Request address must start with http://' },
|
pattern: { value: startsWithHttpOrS, message: 'Request address must start with http://' },
|
||||||
})}
|
})}
|
||||||
/>
|
/>
|
||||||
<Input
|
|
||||||
placeholder='test=testtext'
|
|
||||||
size='xs'
|
|
||||||
variant='ontime-filled-on-light'
|
|
||||||
autoComplete='off'
|
|
||||||
{...register(`subscriptions.${cycle}.${index}.options`)}
|
|
||||||
/>
|
|
||||||
<Select
|
|
||||||
variant='ontime-on-light'
|
|
||||||
size='xs'
|
|
||||||
width='6em'
|
|
||||||
{...register(`subscriptions.${cycle}.${index}.method`)}
|
|
||||||
>
|
|
||||||
<option>GET</option>
|
|
||||||
<option>POST</option>
|
|
||||||
</Select>
|
|
||||||
<Switch variant='ontime-on-light' {...register(`subscriptions.${cycle}.${index}.enabled`)} />
|
<Switch variant='ontime-on-light' {...register(`subscriptions.${cycle}.${index}.enabled`)} />
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|||||||
@@ -79,15 +79,14 @@ export class HttpIntegration implements IIntegration<HttpSubscriptionOptions> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check subscriptions for action
|
// check subscriptions for action
|
||||||
const eventSubscriptions = (this.subscriptions?.[action] as HttpSubscriptionOptions[]) || [];
|
const eventSubscriptions = this.subscriptions?.[action] || [];
|
||||||
|
|
||||||
eventSubscriptions.forEach((sub) => {
|
eventSubscriptions.forEach((sub) => {
|
||||||
const { enabled, url, options, method } = sub;
|
const { enabled, message } = sub;
|
||||||
if (enabled && url) {
|
if (enabled && message) {
|
||||||
const templateUrl = parseTemplateNested(url, state || {});
|
const parsedMessage = parseTemplateNested(message, state || {});
|
||||||
const templateOptions = parseTemplateNested(options, state || {});
|
|
||||||
try {
|
try {
|
||||||
const parsedUrl = new globalThis.URL(templateUrl);
|
const parsedUrl = new globalThis.URL(parsedMessage);
|
||||||
// if (parsedUrl.protocol != 'http:') {
|
// if (parsedUrl.protocol != 'http:') {
|
||||||
// logger.error(LogOrigin.Tx, `HTTP Integration: Only HTTP allowed, got ${parsedUrl.protocol}`);
|
// logger.error(LogOrigin.Tx, `HTTP Integration: Only HTTP allowed, got ${parsedUrl.protocol}`);
|
||||||
// return {
|
// return {
|
||||||
@@ -95,7 +94,7 @@ export class HttpIntegration implements IIntegration<HttpSubscriptionOptions> {
|
|||||||
// message: `Only HTTP allowed, got ${parsedUrl.protocol}`,
|
// message: `Only HTTP allowed, got ${parsedUrl.protocol}`,
|
||||||
// };
|
// };
|
||||||
// }
|
// }
|
||||||
this.emit(templateUrl, templateOptions, method);
|
this.emit(parsedUrl);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(LogOrigin.Tx, `HTTP Integration: ${err}`);
|
logger.error(LogOrigin.Tx, `HTTP Integration: ${err}`);
|
||||||
return {
|
return {
|
||||||
@@ -107,18 +106,11 @@ export class HttpIntegration implements IIntegration<HttpSubscriptionOptions> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async emit(path: string, options: string, method: 'GET' | 'POST') {
|
async emit(path: globalThis.URL) {
|
||||||
try {
|
try {
|
||||||
if (method === 'GET') {
|
await got.get(path, {
|
||||||
await got.get(path, {
|
retry: { limit: this.retryCount },
|
||||||
searchParams: options,
|
});
|
||||||
retry: { limit: this.retryCount },
|
|
||||||
});
|
|
||||||
} else if (method === 'POST') {
|
|
||||||
await got.post(path, {
|
|
||||||
retry: { limit: this.retryCount },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(LogOrigin.Tx, `HTTP integration: ${err}`);
|
logger.error(LogOrigin.Tx, `HTTP integration: ${err}`);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -227,15 +227,9 @@ export const parseOsc = (data: { osc?: Partial<OSCSettings> }): OSCSettings => {
|
|||||||
*/
|
*/
|
||||||
export const validateHttpSubscriptionCycle = (data: HttpSubscriptionOptions[]): boolean => {
|
export const validateHttpSubscriptionCycle = (data: HttpSubscriptionOptions[]): boolean => {
|
||||||
for (const subscriptionOption of data) {
|
for (const subscriptionOption of data) {
|
||||||
const isHttp = subscriptionOption.url?.startsWith('http://') || subscriptionOption.url?.startsWith('https://');
|
const isHttp =
|
||||||
const ishttpMethod = subscriptionOption.method == 'GET' || subscriptionOption.method == 'POST';
|
subscriptionOption.message?.startsWith('http://') || subscriptionOption.message?.startsWith('https://');
|
||||||
if (
|
if (typeof subscriptionOption.message !== 'string' || !isHttp || typeof subscriptionOption.enabled !== 'boolean') {
|
||||||
typeof subscriptionOption.url !== 'string' ||
|
|
||||||
typeof subscriptionOption.options !== 'string' ||
|
|
||||||
!isHttp ||
|
|
||||||
!ishttpMethod ||
|
|
||||||
typeof subscriptionOption.enabled !== 'boolean'
|
|
||||||
) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import { Subscription } from './Subscription.type.js';
|
import { Subscription } from './Subscription.type.js';
|
||||||
|
|
||||||
type httpMethod = 'GET' | 'POST';
|
export type HttpSubscriptionOptions = { message: string; enabled: boolean };
|
||||||
export type HttpSubscriptionOptions = { url: string; options: string; enabled: boolean; method: httpMethod };
|
|
||||||
export type HttpSubscription = Subscription<HttpSubscriptionOptions>;
|
export type HttpSubscription = Subscription<HttpSubscriptionOptions>;
|
||||||
|
|
||||||
export interface HttpSettings {
|
export interface HttpSettings {
|
||||||
|
|||||||
Reference in New Issue
Block a user