admin.nomadro.com gets sidebar L1/L2 social ops (paginated lists + entity detail); API adds soft-delete archives/stats and shared nomadro_pb for social/coffee/notify/work. Co-authored-by: Cursor <cursoragent@cursor.com>
98 lines
3.7 KiB
Python
98 lines
3.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Hot-patch US nomadmini social_ugc to SQLite soft-delete + stats (no PocketBase)."""
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
US = ("108.174.50.68", "root", "Xiao4669805")
|
|
HERE = Path(__file__).resolve().parent
|
|
SRC = HERE / "_us_social_ugc_sqlite.py"
|
|
ADMIN_SRC = (
|
|
Path(__file__).resolve().parents[3]
|
|
/ "apps/api/services/ebook_svc/routers/social_ugc_admin.py"
|
|
)
|
|
REMOTE_APP = "/opt/nomadmini/backend/app"
|
|
|
|
|
|
def to_app(text: str) -> str:
|
|
return text.replace("ebook_svc.", "app.")
|
|
|
|
|
|
def main() -> int:
|
|
if not SRC.is_file():
|
|
raise SystemExit(f"missing {SRC}")
|
|
body = SRC.read_text(encoding="utf-8").encode("utf-8")
|
|
admin_body = to_app(ADMIN_SRC.read_text(encoding="utf-8")).encode("utf-8")
|
|
if b"ebook_svc." in admin_body:
|
|
raise SystemExit("admin rewrite failed")
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
h, u, p = US
|
|
c.connect(h, 22, u, p, timeout=45, allow_agent=False, look_for_keys=False)
|
|
sftp = c.open_sftp()
|
|
with sftp.file("/tmp/social_ugc_sqlite_us.py", "wb") as f:
|
|
f.write(body)
|
|
with sftp.file("/tmp/social_ugc_admin_us.py", "wb") as f:
|
|
f.write(admin_body)
|
|
sftp.close()
|
|
print("uploaded", len(body), len(admin_body), flush=True)
|
|
|
|
cmd = rf"""
|
|
set -euo pipefail
|
|
TS=$(date +%Y%m%d%H%M%S)
|
|
B={REMOTE_APP}
|
|
cp -a "$B/services/social_ugc.py" "$B/services/social_ugc.py.bak-pre-sqlite-$TS" || true
|
|
cp -a "$B/routers/social_ugc_admin.py" "$B/routers/social_ugc_admin.py.bak-pre-sqlite-$TS" || true
|
|
cp /tmp/social_ugc_sqlite_us.py "$B/services/social_ugc.py"
|
|
cp /tmp/social_ugc_admin_us.py "$B/routers/social_ugc_admin.py"
|
|
# ensure SOCIAL_DB_PATH on nomadmini
|
|
ENVF=/opt/nomadmini/backend/.env
|
|
grep -q '^SOCIAL_DB_PATH=' "$ENVF" || echo 'SOCIAL_DB_PATH=/var/www/nomadro-data/social/social.db' >> "$ENVF"
|
|
# prefer empty PB so nothing accidental
|
|
sed -i 's/^USE_POCKETBASE=.*/USE_POCKETBASE=false/' "$ENVF" || true
|
|
cd /opt/nomadmini/backend
|
|
.venv/bin/python - <<'PY'
|
|
from app.services import social_ugc as ugc
|
|
from app.routers import social_ugc_admin
|
|
print('available', ugc.available())
|
|
print('overview', ugc.overview())
|
|
print('stats', {{k: ugc.stats().get(k) for k in ('ok','counts','backend')}})
|
|
paths = sorted({{getattr(r,'path','') for r in social_ugc_admin.router.routes}})
|
|
for need in ['/api/admin/social/ugc/stats','/api/admin/social/ugc/archives','/api/admin/social/ugc/detail/{{entity}}/{{entity_id}}']:
|
|
assert need in paths, need
|
|
print('routes_ok', len(paths))
|
|
PY
|
|
systemctl restart nomadmini-api
|
|
sleep 3
|
|
systemctl is-active nomadmini-api
|
|
systemctl is-active nomadro-social
|
|
curl -sS --max-time 8 http://127.0.0.1:8020/api/social/v1/health; echo
|
|
TOKEN=$(curl -sS --max-time 12 -X POST https://api.nomadro.com/api/admin/login \
|
|
-H 'content-type: application/json' \
|
|
-d '{{"username":"hackrobot","password":"Xiao4669805@"}}' | python3 -c 'import sys,json; print(json.load(sys.stdin).get("token",""))')
|
|
echo "token_len ${{#TOKEN}}"
|
|
for path in overview stats archives roster; do
|
|
code=$(curl -sS -o /tmp/ugc_$path.json -w '%{{http_code}}' --max-time 15 \
|
|
-H "Authorization: Bearer $TOKEN" \
|
|
"https://api.nomadro.com/api/admin/social/ugc/$path")
|
|
echo "ugc_$path $code"
|
|
head -c 260 /tmp/ugc_$path.json; echo
|
|
done
|
|
curl -sk -o /dev/null -w 'admin_com %{{http_code}}\n' https://admin.nomadro.com/
|
|
echo PUSH_UGC_SQLITE_US_OK
|
|
"""
|
|
_, o, e = c.exec_command(cmd, timeout=180)
|
|
print(o.read().decode("utf-8", "replace"), flush=True)
|
|
err = e.read().decode("utf-8", "replace")
|
|
if err.strip():
|
|
print("STDERR", err[-3000:], flush=True)
|
|
c.close()
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|