diff --git a/frontend/src/lib/draftAddRedirect.ts b/frontend/src/lib/draftAddRedirect.ts index 27584a4627..4a948a46f3 100644 --- a/frontend/src/lib/draftAddRedirect.ts +++ b/frontend/src/lib/draftAddRedirect.ts @@ -1,6 +1,7 @@ import { redirect } from '@sveltejs/kit' import { base } from '$app/paths' import { getUsernameForNamespace } from '$lib/userNamespace' +import { randomUUID } from '$lib/components/flows/conversations/FlowChatManager.svelte' /** * Shared `load` for every `/{scripts,flows,apps,apps_raw}/add` route. @@ -14,11 +15,16 @@ import { getUsernameForNamespace } from '$lib/userNamespace' * `{base}/{editPrefix}/?new_draft=true&`. * The `new_draft=true` flag tells the edit route to seed an empty * editor instead of 404-ing on the autogenerated path. + * + * Uses the project's `randomUUID` helper rather than + * `crypto.randomUUID()` — the WebCrypto version is unavailable on + * non-secure origins (HTTP, local IPs over LAN), and self-hosted + * Windmill instances frequently run that way. */ export function makeDraftAddLoad(editPrefix: string) { return ({ url }: { url: URL }) => { const username = getUsernameForNamespace() - const uuid = crypto.randomUUID() + const uuid = randomUUID() const params = new URLSearchParams(url.searchParams) params.set('new_draft', 'true') redirect(307, `${base}/${editPrefix}/u/${username}/draft_${uuid}?${params.toString()}`)