From 1539bdb3a78146685af9e5d369b325c2119b29ec Mon Sep 17 00:00:00 2001 From: Davide Scaini Date: Thu, 7 May 2026 22:35:17 +0200 Subject: [PATCH] Send and store base_hash for optimistic conflict detection --- src/components/PageEditor.svelte | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/components/PageEditor.svelte b/src/components/PageEditor.svelte index c9cdfac..033128b 100644 --- a/src/components/PageEditor.svelte +++ b/src/components/PageEditor.svelte @@ -14,6 +14,7 @@ let saveStatus = ''; let savedUrl = ''; let errorMsg = ''; + let baseHash = ''; let uploading = false; let dragOver = false; let fileInput: HTMLInputElement; @@ -36,6 +37,7 @@ saveStatus = ''; savedUrl = ''; errorMsg = ''; + baseHash = ''; } function onSectionChange() { @@ -63,6 +65,7 @@ if (!r.ok) throw new Error(`HTTP ${r.status}`); const data = await r.json(); content = data.content; + baseHash = data.base_hash ?? ''; } catch (e) { errorMsg = `Errore nel caricamento: ${e}`; } @@ -80,8 +83,9 @@ method: 'POST', headers: { 'Content-Type': 'application/json' }, credentials: 'include', - body: JSON.stringify({ content }), + body: JSON.stringify({ content, base_hash: baseHash }), }); + if (r.status === 409) { errorMsg = await r.text(); return; } if (!r.ok) throw new Error(await r.text()); saveStatus = 'Costruendo…'; const rb = await fetch('/rebuild', { method: 'POST', credentials: 'include' });