"""Правит /notify: в POST использовать готовый data, в GET — query.""" import ast import re P = "/opt/hub-core/core.py" s = open(P, encoding="utf-8").read() # 1) do_POST: заменяем блок, который читает body old_post = ''' if self.path.startswith("/notify"): try: ln = int(self.headers.get("Content-Length") or 0) raw = self.rfile.read(ln) if ln else b"{}" data = json.loads(raw or b"{}") except Exception: data = {} title = (data.get("title") or data.get("name") or "Событие").strip() msg = (data.get("message") or data.get("msg") or "").strip() ok = _matrix_notify("🔔 " + title + (("\\n" + msg) if msg else "")) return self._json(200 if ok else 502, {"sent": bool(ok)}) ''' new_post = ''' if self.path.startswith("/notify"): title = (data.get("title") or data.get("name") or "Событие").strip() msg = (data.get("message") or data.get("msg") or "").strip() ok = _matrix_notify("🔔 " + title + (("\\n" + msg) if msg else "")) return self._json(200 if ok else 502, {"sent": bool(ok)}) ''' if old_post in s: s = s.replace(old_post, new_post, 1) print(" do_POST исправлен") else: print(" блок do_POST не найден — проверю вручную") # 2) do_GET: наш блок тоже читает body — переделаем на query old_get = ''' if self.path.startswith("/notify"): try: ln = int(self.headers.get("Content-Length") or 0) raw = self.rfile.read(ln) if ln else b"{}" data = json.loads(raw or b"{}") except Exception: data = {} title = (data.get("title") or data.get("name") or "Событие").strip() msg = (data.get("message") or data.get("msg") or "").strip() text = "🔔 " + title + (("\\n" + msg) if msg else "") ok = _matrix_notify(text) return self._json(200 if ok else 502, {"sent": bool(ok)}) ''' new_get = ''' if self.path.startswith("/notify"): from urllib.parse import parse_qs, urlparse as _up qs = parse_qs(_up(self.path).query) title = (qs.get("title") or qs.get("name") or ["Событие"])[0] msg = (qs.get("message") or qs.get("msg") or [""])[0] ok = _matrix_notify("🔔 " + title + (("\\n" + msg) if msg else "")) return self._json(200 if ok else 502, {"sent": bool(ok)}) ''' if old_get in s: s = s.replace(old_get, new_get, 1) print(" do_GET исправлен") else: print(" блок do_GET не найден") open(P, "w", encoding="utf-8").write(s) ast.parse(s) print("core.py обновлён")