Fix: Sync-Konflikt (412) bei Nextcloud durch ETag mit -gzip-Suffix (v1.2.1)
OC-ETag bevorzugen, Kompressions-Suffixe entfernen und bei unveraendertem Remote-Stand nach 412 ohne If-Match schreiben. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
2bcb625c11
commit
dc4e89cd07
3 files changed
+22
-5
No files matched your search
@@ -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
|
||||
|
||||
+1
-1
@@ -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://*/*"],
|
||||
|
||||
@@ -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 (!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 };
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user