From 17337cb370eb13decaa766cf51fb071fd8d9bdc1 Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Sat, 20 May 2023 02:50:18 +0200 Subject: [PATCH] improve CURL helps --- .../(logged)/flows/get/[...path]/+page.svelte | 78 ++++++++++++------- .../scripts/get/[...hash]/+page.svelte | 68 ++++++++-------- 2 files changed, 84 insertions(+), 62 deletions(-) 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 1eda42f160..5ca070fea6 100644 --- a/frontend/src/routes/(root)/(logged)/flows/get/[...path]/+page.svelte +++ b/frontend/src/routes/(root)/(logged)/flows/get/[...path]/+page.svelte @@ -2,7 +2,7 @@ import { page } from '$app/stores' import { FlowService, JobService, ScheduleService, type Flow, type Schedule } from '$lib/gen' import { - canWrite, + canWrite, copyToClipboard, defaultIfEmptyString, displayDaysAgo, @@ -25,7 +25,7 @@ import { goto } from '$app/navigation' import CenteredPage from '$lib/components/CenteredPage.svelte' - import { Alert, Badge, Button, Skeleton } from '$lib/components/common' + import { Alert, Badge, Button, Skeleton, Tab, TabContent, Tabs } from '$lib/components/common' import CronInput from '$lib/components/CronInput.svelte' import FlowViewer from '$lib/components/FlowViewer.svelte' import JobArgs from '$lib/components/JobArgs.svelte' @@ -135,11 +135,14 @@ let viewWebhookCommand = false let args = undefined - $: curlCommand = `curl -H 'Content-Type: application/json' -H "Authorization: Bearer $TOKEN" -X POST -d '${JSON.stringify( - args - )}' ${$page.url.protocol}//${$page.url.hostname}/api/w/${$workspaceStore}/jobs/run/f/${ - flow?.path - }` + + function curlCommand(async: boolean) { + return `curl -H 'Content-Type: application/json' -H "Authorization: Bearer $TOKEN" -X POST -d '${JSON.stringify( + args + )}' ${$page.url.protocol}//${$page.url.hostname}/api/w/${$workspaceStore}/jobs/run${ + async ? '' : '_wait_result' + }/f/${flow?.path}` + } let webhook: HTMLHeadElement let moveDrawer: MoveDrawer @@ -358,31 +361,46 @@
+
+
+ +
+ {#if viewWebhookCommand} +
+ + UUID/Async + Result/Sync + + +
{curlCommand(true)}  copyToClipboard(curlCommand(true))}
+													class="cursor-pointer ml-2">{curlCommand(false)}  copyToClipboard(curlCommand(false))}
+													class="cursor-pointer ml-2">

//^ returns an UUID. Fetch result until completed == true
curl -H "Authorization: Bearer $TOKEN" {$page.url.protocol}//{$page.url + .hostname}/api/w/{$workspaceStore}/jobs_u/completed/get_result_maybe/$UUID
+
+
+
+ {/if} +
-
-
- -
- {#if viewWebhookCommand} -
- -
{curlCommand}  copyToClipboard(curlCommand)}
-									class="cursor-pointer ml-2">
-
- {/if} -
{#if schedule}

@@ -461,7 +461,7 @@

-

+

Webhooks {SCRIPT_VIEW_WEBHOOK_INFO_TIP} @@ -520,35 +520,39 @@

{/if} + {#if SCRIPT_VIEW_SHOW_EXAMPLE_CURL} +
+ +
+ {/if} + {#if viewWebhookCommand} + {@const command = curlCommand(key == 'async')} +
+ +
{command}  copyToClipboard(command)}
+												class="cursor-pointer ml-2">{#if key == 'async'}

//^ returns an UUID. Fetch until completed == true
curl -H "Authorization: Bearer $TOKEN" {$page.url.protocol}//{$page.url + .hostname}/api/w/{$workspaceStore}/jobs_u/completed/get_result_maybe/$UUID{/if}
+
+ {/if} {/each} - {#if SCRIPT_VIEW_SHOW_EXAMPLE_CURL} -
- -
- {/if} - {#if viewWebhookCommand} -
- -
{curlCommand}  copyToClipboard(curlCommand)}
-										class="cursor-pointer ml-2">
-
- {/if} -
+
{#if can_write}

Danger zone