From acbe2d4e0524cea43696263df3ecead278628e60 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Sun, 9 Jul 2023 20:54:16 +0200 Subject: [PATCH] improve webhook section --- .../components/details/WebhooksPanel.svelte | 18 +++--------------- .../(logged)/flows/get/[...path]/+page.svelte | 4 ++-- .../scripts/get/[...hash]/+page.svelte | 10 +++++----- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/frontend/src/lib/components/details/WebhooksPanel.svelte b/frontend/src/lib/components/details/WebhooksPanel.svelte index d5c86be7c6..331b122961 100644 --- a/frontend/src/lib/components/details/WebhooksPanel.svelte +++ b/frontend/src/lib/components/details/WebhooksPanel.svelte @@ -43,16 +43,6 @@ requestType = 'hash' } - function getProtocol(url: string) { - if (url.startsWith('localhost')) { - return 'http://' - } else if (url.startsWith('http://') || url.startsWith('https://')) { - return '' - } else { - return 'https://' - } - } - $: url = webhooks[webhookType][requestType] let token = 'YOUR_TOKEN' @@ -139,9 +129,7 @@
{#if requestType !== 'get_path'} @@ -187,7 +175,7 @@ curl -H 'Content-Type: application/json' ${ webhookType === 'sync' ? 'echo $RESPONSE' : `UUID=$(echo $RESPONSE | jq -r .uuid) -URL=${$page.url.protocol}//${$page.url.hostname}/api/w/${$workspaceStore}/jobs_u/completed/get_result_maybe/$UUID +URL=${$page.url.origin}/api/w/${$workspaceStore}/jobs_u/completed/get_result_maybe/$UUID while true; do RESULT=$(curl -H "Authorization: Bearer $TOKEN" $URL) COMPLETED=$(echo $RESULT | jq .completed) @@ -224,7 +212,7 @@ fetch(${tokenType === 'query' ? `\`${url}?token=${token}\`` : `\`${url}\``}, { ? 'console.log(data)' : `let UUID = data.uuid; let checkCompletion = setInterval(() => { - fetch(\`${$page.url.protocol}//${$page.url.hostname}/api/w/${$workspaceStore}/jobs_u/completed/get_result_maybe/\$\{UUID\}\`, { + fetch(\`${$page.url.origin}/api/w/${$workspaceStore}/jobs_u/completed/get_result_maybe/\$\{UUID\}\`, { method: 'GET', headers: { 'Authorization': 'Bearer ${token}' diff --git a/frontend/src/routes/(root)/(logged)/flows/get/[...path]/+page.svelte b/frontend/src/routes/(root)/(logged)/flows/get/[...path]/+page.svelte index f0a5cdb382..42b8e6f4b6 100644 --- a/frontend/src/routes/(root)/(logged)/flows/get/[...path]/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/flows/get/[...path]/+page.svelte @@ -104,8 +104,8 @@ can_write = canWrite(flow.path, flow.extra_perms!, $userStore) } - $: urlAsync = `${$page.url.hostname}/api/w/${$workspaceStore}/jobs/run/f/${flow?.path}` - $: urlSync = `${$page.url.hostname}/api/w/${$workspaceStore}/jobs/run_wait_result/f/${flow?.path}` + $: urlAsync = `${$page.url.origin}/api/w/${$workspaceStore}/jobs/run/f/${flow?.path}` + $: urlSync = `${$page.url.origin}/api/w/${$workspaceStore}/jobs/run_wait_result/f/${flow?.path}` let isValid = true let loading = false diff --git a/frontend/src/routes/(root)/(logged)/scripts/get/[...hash]/+page.svelte b/frontend/src/routes/(root)/(logged)/scripts/get/[...hash]/+page.svelte index 34960b0d5f..997ffecc5d 100644 --- a/frontend/src/routes/(root)/(logged)/scripts/get/[...hash]/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/scripts/get/[...hash]/+page.svelte @@ -73,13 +73,13 @@ } $: webhooks = { async: { - hash: `${$page.url.hostname}/api/w/${$workspaceStore}/jobs/run/h/${script?.hash}`, - path: `${$page.url.hostname}/api/w/${$workspaceStore}/jobs/run/p/${script?.path}` + hash: `${$page.url.origin}/api/w/${$workspaceStore}/jobs/run/h/${script?.hash}`, + path: `${$page.url.origin}/api/w/${$workspaceStore}/jobs/run/p/${script?.path}` }, sync: { - hash: `${$page.url.hostname}/api/w/${$workspaceStore}/jobs/run_wait_result/h/${script?.hash}`, - path: `${$page.url.hostname}/api/w/${$workspaceStore}/jobs/run_wait_result/p/${script?.path}`, - get_path: `${$page.url.hostname}/api/w/${$workspaceStore}/jobs/run_wait_result/p/${script?.path}` + hash: `${$page.url.origin}/api/w/${$workspaceStore}/jobs/run_wait_result/h/${script?.hash}`, + path: `${$page.url.origin}/api/w/${$workspaceStore}/jobs/run_wait_result/p/${script?.path}`, + get_path: `${$page.url.origin}/api/w/${$workspaceStore}/jobs/run_wait_result/p/${script?.path}` } }