fix(drafts): swap crypto.randomUUID() for the project's randomUUID helper

crypto.randomUUID() is gated on a secure origin (HTTPS or localhost).
Self-hosted Windmill instances often run on a bare HTTP origin or a
LAN IP where the WebCrypto API is unavailable, so the /add redirect
would throw before issuing the 307. Use the existing RFC4122 v4 helper
in FlowChatManager that the rest of the codebase already imports for
this exact reason.
This commit is contained in:
Diego Imbert
2026-06-08 19:32:09 +02:00
parent f74504e273
commit bf4dd6c470
+7 -1
View File
@@ -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}/<that-path>?new_draft=true&<existing-params>`.
* 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()}`)