improve webhook section

This commit is contained in:
Ruben Fiszel
2023-07-09 20:54:16 +02:00
parent 3618f8037b
commit acbe2d4e05
3 changed files with 10 additions and 22 deletions
@@ -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 @@
<div class="flex flex-col gap-2">
<ClipboardPanel
title="Url"
content={tokenType === 'query'
? `${getProtocol(url)}${url}?token=${token}`
: `${getProtocol(url)}${url}`}
content={tokenType === 'query' ? `${url}?token=${token}` : url}
/>
{#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}'
@@ -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
@@ -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}`
}
}