Forum: idempotente Antworten gegen Doppelpost/Cooldown-Fehler bei Funkloch (v1306)
Praxisfall: Antwort wird serverseitig erstellt, aber die HTTP-Antwort geht unterwegs verloren (schlechtes Netz). UI zeigt Fehler statt Erfolg, Text bleibt stehen -> Nutzer tippt erneut -> 2. Versuch laeuft in den 30s-Cooldown (429), der bereits gepostete Beitrag bleibt unsichtbar. - forum_posts.client_uuid (Migration). Reply mit stabiler client_uuid: Retry liefert den BEREITS erstellten Post zurueck (kein Cooldown/Doppelpost). - Frontend: UUID bleibt ueber Retries stabil, Reset erst nach Erfolg; Foto- Doppel-Upload bei Retry verhindert. - Anti-Spam-Cooldown bleibt fuer echte neue Posts aktiv. - Tests: tests/test_forum_idempotency.py (Retry=selber Post, Cooldown greift, ohne UUID rueckwaertskompatibel).
This commit is contained in:
parent
140140f690
commit
6ea3f50b05
9 changed files with 136 additions and 25 deletions
|
|
@ -751,20 +751,33 @@ function _fmtDate(iso) {
|
|||
if (postsListEl) _bindPostActions(postsListEl, thread.id, uid, isMod);
|
||||
|
||||
// Reply abschicken
|
||||
// Idempotenz-Schlüssel: bleibt über Retries STABIL und wird erst nach
|
||||
// erfolgreichem Senden zurückgesetzt. So liefert ein Retry (z.B. wenn die
|
||||
// Antwort des 1. Versuchs im Funkloch verloren ging) denselben Post zurück
|
||||
// statt eines Cooldown-Fehlers/Doppelposts.
|
||||
let _replyUuid = null;
|
||||
document.getElementById('ft-reply')?.addEventListener('click', async () => {
|
||||
const btn = document.getElementById('ft-reply');
|
||||
const text = document.getElementById('forum-reply-text')?.value?.trim();
|
||||
if (!text) { UI.toast.warning('Bitte Text eingeben.'); return; }
|
||||
if (!_replyUuid) {
|
||||
_replyUuid = (window.crypto && crypto.randomUUID)
|
||||
? crypto.randomUUID()
|
||||
: `${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
||||
}
|
||||
|
||||
await UI.asyncButton(btn, async () => {
|
||||
const post = await API.forum.addPost(thread.id, { text, client_time: API.clientNow() });
|
||||
const post = await API.forum.addPost(thread.id, { text, client_time: API.clientNow(), client_uuid: _replyUuid });
|
||||
|
||||
// Foto hochladen falls vorhanden
|
||||
// Foto hochladen falls vorhanden — bei idempotentem Retry hat der Post
|
||||
// seine Fotos bereits, dann NICHT erneut hochladen (kein Doppel-Upload).
|
||||
const files = Array.from(document.getElementById('forum-reply-file')?.files || []);
|
||||
for (const file of files.slice(0, 5)) {
|
||||
try {
|
||||
await API.forum.uploadPostFoto(post.id, file);
|
||||
} catch (e) { /* Foto-Upload-Fehler ignorieren */ }
|
||||
if (!post.foto_urls || post.foto_urls.length === 0) {
|
||||
for (const file of files.slice(0, 5)) {
|
||||
try {
|
||||
await API.forum.uploadPostFoto(post.id, file);
|
||||
} catch (e) { /* Foto-Upload-Fehler ignorieren */ }
|
||||
}
|
||||
}
|
||||
|
||||
thread.antworten = (thread.antworten || 0) + 1;
|
||||
|
|
@ -782,6 +795,7 @@ function _fmtDate(iso) {
|
|||
document.getElementById('forum-reply-text').value = '';
|
||||
const previews = document.getElementById('forum-reply-previews');
|
||||
if (previews) previews.innerHTML = '';
|
||||
_replyUuid = null; // Erfolg → nächste Antwort bekommt eine frische UUID
|
||||
UI.toast.success('Antwort gesendet.');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue