Send and store base_hash for optimistic conflict detection
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
let saveStatus = '';
|
let saveStatus = '';
|
||||||
let savedUrl = '';
|
let savedUrl = '';
|
||||||
let errorMsg = '';
|
let errorMsg = '';
|
||||||
|
let baseHash = '';
|
||||||
let uploading = false;
|
let uploading = false;
|
||||||
let dragOver = false;
|
let dragOver = false;
|
||||||
let fileInput: HTMLInputElement;
|
let fileInput: HTMLInputElement;
|
||||||
@@ -36,6 +37,7 @@
|
|||||||
saveStatus = '';
|
saveStatus = '';
|
||||||
savedUrl = '';
|
savedUrl = '';
|
||||||
errorMsg = '';
|
errorMsg = '';
|
||||||
|
baseHash = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function onSectionChange() {
|
function onSectionChange() {
|
||||||
@@ -63,6 +65,7 @@
|
|||||||
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
||||||
const data = await r.json();
|
const data = await r.json();
|
||||||
content = data.content;
|
content = data.content;
|
||||||
|
baseHash = data.base_hash ?? '';
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
errorMsg = `Errore nel caricamento: ${e}`;
|
errorMsg = `Errore nel caricamento: ${e}`;
|
||||||
}
|
}
|
||||||
@@ -80,8 +83,9 @@
|
|||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
credentials: 'include',
|
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());
|
if (!r.ok) throw new Error(await r.text());
|
||||||
saveStatus = 'Costruendo…';
|
saveStatus = 'Costruendo…';
|
||||||
const rb = await fetch('/rebuild', { method: 'POST', credentials: 'include' });
|
const rb = await fetch('/rebuild', { method: 'POST', credentials: 'include' });
|
||||||
|
|||||||
Reference in New Issue
Block a user