diff --git a/l4d2web/l4d2web/static/js/files-overlay/editor.js b/l4d2web/l4d2web/static/js/files-overlay/editor.js index 03a3384..320a9c8 100644 --- a/l4d2web/l4d2web/static/js/files-overlay/editor.js +++ b/l4d2web/l4d2web/static/js/files-overlay/editor.js @@ -181,7 +181,10 @@ : ta.value; // is_new mode: relPath is empty; compose path from data-at-folder - // + filename. The /save endpoint creates the file when missing. + // + filename. The /save endpoint creates the file when missing, + // 409s when the destination already exists. On 409 we offer the + // same overwrite / keep-both / cancel prompt that the legacy + // create-new flow used (via askConflict in dialogs.js). if (!relPath) { if (!editedFilename) return; const atFolder = ta.dataset.atFolder || ""; @@ -192,11 +195,35 @@ if (r.ok) { if (typeof window.modals?.closeRouted === "function") window.modals.closeRouted(); scheduleRefresh(parentOf(fullPath)); - } else if (r.status === 409) { - alert(r.rawText || `A file at ${fullPath} already exists. Pick a different name.`); - } else { - alert((r.body && r.body.error) || r.rawText || `Create failed (HTTP ${r.status}).`); + return; } + if (r.status === 409 && typeof fo.askConflict === "function") { + const action = await fo.askConflict(fullPath); + if (action === "overwrite") { + // /save overwrites in place when the destination is a file — + // a plain re-POST does the right thing. + const r2 = await postJson(`${baseUrl}/files/save`, { path: fullPath, content }); + if (r2.ok) { + if (typeof window.modals?.closeRouted === "function") window.modals.closeRouted(); + scheduleRefresh(parentOf(fullPath)); + } else { + alert((r2.body && r2.body.error) || `Save failed (HTTP ${r2.status}).`); + } + } else if (action === "keep-both" && typeof fo.withCollisionSuffix === "function") { + const altered = fo.withCollisionSuffix(fullPath); + const r2 = await postJson(`${baseUrl}/files/save`, { path: altered, content }); + if (r2.ok) { + if (typeof window.modals?.closeRouted === "function") window.modals.closeRouted(); + scheduleRefresh(parentOf(altered)); + } else { + alert((r2.body && r2.body.error) || `Save failed (HTTP ${r2.status}).`); + } + } + // "cancel" → leave the modal open so the user can edit the + // filename and try again without losing typed content. + return; + } + alert((r.body && r.body.error) || r.rawText || `Create failed (HTTP ${r.status}).`); return; }