diff --git a/README.md b/README.md index 0117683..0324ba8 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,7 @@ Dateiformat (`lablinks.json`): ## Versionen +- **1.2.1** – Fix: Sync-Konflikt (HTTP 412) bei Nextcloud hinter komprimierendem Proxy (ETag mit `-gzip`) - **1.2.0** – Links liegen jetzt in `storage.local` (kein 8-KB-Limit mehr); bestehende Daten werden automatisch übernommen - **1.1.1** – Sicherheits-Härtung (URL-Schema, Validierung, HTTP-Regel, CSP, UUID-IDs) - **1.1.0** – WebDAV-/Nextcloud-Sync diff --git a/manifest.json b/manifest.json index 611cd9a..4d391fb 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "manifest_version": 3, "name": "LabLinks", - "version": "1.2.0", + "version": "1.2.1", "description": "Retro-Launcher für deine HomeLab WebUIs.", "permissions": ["storage"], "optional_host_permissions": ["https://*/*", "http://*/*"], diff --git a/sync.js b/sync.js index e493128..cb27b1e 100644 --- a/sync.js +++ b/sync.js @@ -123,13 +123,22 @@ const LabSync = (() => { try { data = JSON.parse(text); } catch { throw new Error("Remote-Datei ist kein gültiges JSON"); } if (!data || typeof data !== "object" || !Array.isArray(data.links)) throw new Error("Remote-Datei hat ein unbekanntes Format"); - return { data: cleanState(data), etag: res.headers.get("ETag") }; + return { data: cleanState(data), etag: pickEtag(res.headers) }; } - // -> "ok" | "conflict" - async function putRemote(cfg, data, etag) { + // Nextcloud liefert den echten ETag in OC-ETag. Hinter Apache/nginx mit Kompression hängt der + // Server beim normalen ETag ein "-gzip" an, das beim PUT (If-Match) nicht mehr passt -> 412. + function pickEtag(h) { + const raw = h.get("OC-ETag") || h.get("ETag"); + return raw ? raw.replace(/^W\//, "").replace(/-(gzip|br|deflate)"$/, '"') : null; + } + + // -> "ok" | "conflict"; unconditional: ohne If-Match schreiben (ETag unzuverlässig) + async function putRemote(cfg, data, etag, unconditional = false) { const headers = { "Content-Type": "application/json" }; - if (etag) headers["If-Match"] = etag; else headers["If-None-Match"] = "*"; + if (!unconditional) { + if (etag) headers["If-Match"] = etag; else headers["If-None-Match"] = "*"; + } const body = JSON.stringify({ version: 1, ...data }, null, 2); let res = await dav(cfg, "PUT", fileUrl(cfg), headers, body); @@ -181,6 +190,7 @@ const LabSync = (() => { if (!cfg || !cfg.url) return { skipped: true }; checkServerUrl(cfg.url); + let conflictSig = null; // Remote-Stand beim letzten 412 for (let attempt = 0; attempt < 4; attempt++) { const local = await readLocal(); const remote = await fetchRemote(cfg); @@ -193,7 +203,13 @@ const LabSync = (() => { if (localChanged) await writeLocal(merged); if (!remote || sig(merged) !== sig(remote.data)) { - if ((await putRemote(cfg, merged, remote?.etag)) === "conflict") continue; + // Bleibt der Remote-Stand nach einem 412 unverändert, war es kein echter Konflikt, + // sondern ein unpassender ETag -> ohne Vorbedingung schreiben. + const spurious = remote && conflictSig !== null && conflictSig === sig(remote.data); + if ((await putRemote(cfg, merged, remote?.etag, spurious)) === "conflict") { + conflictSig = remote ? sig(remote.data) : ""; + continue; + } } return { links: merged.links.length, pulled: localChanged }; }