From 14bacba0add13e8b42e418cdebd10ce140aaf2ce Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Tue, 2 Jul 2024 15:17:04 +0200 Subject: [PATCH] improve sharable hash --- frontend/src/lib/components/RunForm.svelte | 10 +++++++++- frontend/src/lib/utils.ts | 10 ++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/frontend/src/lib/components/RunForm.svelte b/frontend/src/lib/components/RunForm.svelte index a818e0a66b..c994acc348 100644 --- a/frontend/src/lib/components/RunForm.svelte +++ b/frontend/src/lib/components/RunForm.svelte @@ -67,7 +67,15 @@ export let isValid = true - $: window.location.hash = computeSharableHash(args) + $: onArgsChange(args) + + function onArgsChange(args: any) { + try { + window.location.hash = computeSharableHash(args) + } catch (e) { + console.error('Impossible to set hash in args', e) + } + }
diff --git a/frontend/src/lib/utils.ts b/frontend/src/lib/utils.ts index 42a18e7152..373a64886f 100644 --- a/frontend/src/lib/utils.ts +++ b/frontend/src/lib/utils.ts @@ -670,12 +670,18 @@ export function extractCustomProperties(styleStr: string): string { export function computeSharableHash(args: any) { let nargs = {} - Object.entries(args).forEach(([k, v]) => { + for (let k in args) { + let v = args[k] if (v !== undefined) { // if + let size = roughSizeOfObject(v) > 1000000 + if (size) { + console.error(`Value at key ${k} too big (${size}) to be shared`) + return '' + } nargs[k] = JSON.stringify(v) } - }) + } try { let r = new URLSearchParams(nargs).toString() return r.length > 1000000 ? '' : r