"""Nextcloud FILES through the front door (WebDAV as the seeded user) — the household's own route.""" import secrets def put(w, sub, t, name, body): rc, code, out = w.app_curl(sub, f"/remote.php/dav/files/{t['uid']}/{name}", "-u", f"{t['uid']}:{t['pw']}", "-H", "Content-Type: text/plain", method="PUT", data=body) return code in ("201", "204") def get(w, sub, t, name): rc, code, out = w.app_curl(sub, f"/remote.php/dav/files/{t['uid']}/{name}", "-u", f"{t['uid']}:{t['pw']}") return code, out def seed_files(w, sub, t, n=3, say=print): files = {} for i in range(n): name, body = f"felhom-seed-{i}-{secrets.token_hex(3)}.txt", "seed " + secrets.token_hex(16) ok = put(w, sub, t, name, body) say(f" nextcloud file PUT {name} ok={ok}") if ok: files[name] = body return files def verify_files(w, sub, t, files, say=print): res = {} for name, body in files.items(): code, out = get(w, sub, t, name) res[name] = (code == "200" and out == body) neg_code, _ = get(w, sub, t, "felhom-never-" + secrets.token_hex(4) + ".txt") say(f" nextcloud files read back: {sum(res.values())}/{len(res)} (negative control http={neg_code})") return res, neg_code