Fixing issue with automation webhook URL being undefined.

This commit is contained in:
mike12345567 2021-06-23 20:11:05 +01:00
parent 1dbc56adf4
commit 6e0f18de87
3 changed files with 33 additions and 19 deletions

View File

@ -16,11 +16,13 @@
$: automation = $automationStore.selectedAutomation?.automation $: automation = $automationStore.selectedAutomation?.automation
onMount(async () => { onMount(async () => {
if (!automation?.definition?.trigger?.inputs.schemaUrl) {
// save the automation initially // save the automation initially
await automationStore.actions.save({ await automationStore.actions.save({
instanceId, instanceId,
automation, automation,
}) })
}
interval = setInterval(async () => { interval = setInterval(async () => {
await automationStore.actions.fetch() await automationStore.actions.fetch()
const outputs = automation?.definition?.trigger.schema.outputs?.properties const outputs = automation?.definition?.trigger.schema.outputs?.properties

View File

@ -9,6 +9,9 @@
$: appUrl = $hostingStore.appUrl $: appUrl = $hostingStore.appUrl
function fullWebhookURL(uri) { function fullWebhookURL(uri) {
if (!uri) {
return ""
}
if (production) { if (production) {
return `${appUrl}/${uri}` return `${appUrl}/${uri}`
} else { } else {

View File

@ -88,6 +88,8 @@ async function checkForCronTriggers({ appId, oldAuto, newAuto }) {
async function checkForWebhooks({ appId, oldAuto, newAuto }) { async function checkForWebhooks({ appId, oldAuto, newAuto }) {
const oldTrigger = oldAuto ? oldAuto.definition.trigger : null const oldTrigger = oldAuto ? oldAuto.definition.trigger : null
const newTrigger = newAuto ? newAuto.definition.trigger : null const newTrigger = newAuto ? newAuto.definition.trigger : null
const triggerChanged =
oldTrigger && newTrigger && oldTrigger.id !== newTrigger.id
function isWebhookTrigger(auto) { function isWebhookTrigger(auto) {
return ( return (
auto && auto &&
@ -98,9 +100,10 @@ async function checkForWebhooks({ appId, oldAuto, newAuto }) {
// need to delete webhook // need to delete webhook
if ( if (
isWebhookTrigger(oldAuto) && isWebhookTrigger(oldAuto) &&
!isWebhookTrigger(newAuto) && (!isWebhookTrigger(newAuto) || triggerChanged) &&
oldTrigger.webhookId oldTrigger.webhookId
) { ) {
try {
let db = new CouchDB(appId) let db = new CouchDB(appId)
// need to get the webhook to get the rev // need to get the webhook to get the rev
const webhook = await db.get(oldTrigger.webhookId) const webhook = await db.get(oldTrigger.webhookId)
@ -114,9 +117,15 @@ async function checkForWebhooks({ appId, oldAuto, newAuto }) {
newTrigger.inputs = {} newTrigger.inputs = {}
} }
await webhooks.destroy(ctx) await webhooks.destroy(ctx)
} catch (err) {
// don't worry about not being able to delete, if it doesn't exist all good
}
} }
// need to create webhook // need to create webhook
else if (!isWebhookTrigger(oldAuto) && isWebhookTrigger(newAuto)) { if (
(!isWebhookTrigger(oldAuto) || triggerChanged) &&
isWebhookTrigger(newAuto)
) {
const ctx = { const ctx = {
appId, appId,
request: { request: {