douyinWEB/scripts/debug_pb_upsert.py
eric a360eec2ba Document slots/covers/PB ops UX and sync feature pass to main.
Ship zombie reconcile, S3 covers, session end/drill-down, rooms ops, and refresh README for production.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-08 20:07:15 -05:00

59 lines
2.6 KiB
Python

# -*- coding: utf-8 -*-
import paramiko
SCRIPT = r'''
import sys, asyncio, json
sys.path.insert(0, "/opt/douyinWEB/backend")
from app import pb_sync, db
async def main():
await pb_sync.ensure_admin()
headers = await pb_sync._auth_headers()
s = (db.list_sessions(limit=1, offset=0).get("sessions") or [None])[0]
print("sample session", s.get("id"), s.get("anchor_name"), (s.get("cover_path") or "")[:60] if s else None)
body = {
"sqlite_id": s["id"],
"room_id": s.get("room_id") or "",
"source_url": s.get("source_url") or "",
"anchor_name": s.get("anchor_name") or "",
"title": s.get("title") or "",
"started_at": s.get("started_at") or 0,
"ended_at": s.get("ended_at") or 0,
"duration_seconds": s.get("duration_seconds") or 0,
"push_date": s.get("push_date") or "",
"status": s.get("status") or "",
}
if str(s.get("cover_path") or "").startswith("http"):
body["cover_url"] = s["cover_path"]
body["cover_path"] = s["cover_path"]
async with await pb_sync._client() as client:
# inspect collection rules
col = await client.get("/api/collections/dy_sessions", headers=headers)
cj = col.json()
print("createRule", cj.get("createRule"), "updateRule", cj.get("updateRule"), "listRule", cj.get("listRule"))
resp = await client.post("/api/collections/dy_sessions/records", headers=headers, json=body)
print("POST", resp.status_code, resp.text[:500])
# try rooms
rooms = db.list_rooms(limit=1).get("rooms") or []
if rooms:
r = rooms[0]
rbody = {"sqlite_id": r["id"], "url": r.get("url") or "", "room_id": r.get("room_id") or "", "note": r.get("note") or "", "enabled": bool(r.get("enabled")), "last_status": r.get("last_status") or "", "last_anchor": r.get("last_anchor") or ""}
rr = await client.post("/api/collections/dy_rooms/records", headers=headers, json=rbody)
print("ROOM POST", rr.status_code, rr.text[:300])
lst = await client.get("/api/collections/dy_rooms/records", headers=headers, params={"perPage": 2})
print("ROOM list", lst.status_code, lst.json().get("totalItems"))
asyncio.run(main())
'''
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False)
_, o, e = c.exec_command(
"/opt/douyinWEB/backend/.venv/bin/python - <<'PY'\n" + SCRIPT + "\nPY",
timeout=60,
)
print(o.read().decode("utf-8", "replace"))
print(e.read().decode("utf-8", "replace")[-1000:])
c.close()