improve sharable hash

This commit is contained in:
Ruben Fiszel
2024-07-02 15:17:04 +02:00
parent 2f374ba7ef
commit 14bacba0ad
2 changed files with 17 additions and 3 deletions

View File

@@ -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)
}
}
</script>
<div class="max-w-3xl">

View File

@@ -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