Send and store base_hash for optimistic conflict detection

This commit is contained in:
Davide Scaini
2026-05-07 22:35:17 +02:00
parent d6eda096d9
commit 1539bdb3a7
+5 -1
View File
@@ -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' });