douyinWEB/scripts/_diag_dual_deploy_avatars_neko.py
2026-09-13 22:10:49 -05:00

122 lines
4.1 KiB
Python

#!/usr/bin/env python3
"""Compare deployed revisions on both VPS vs local key files."""
from __future__ import annotations
import hashlib
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
HOSTS = [("dylive", "107.173.30.245"), ("dy", "108.174.50.68")]
PASS = "Xiao4669805"
FILES = [
"backend/app/session_auth.py",
"backend/app/youtube_neko.py",
"backend/app/youtube_relay_pipeline.py",
"backend/app/yt_assign_db.py",
"frontend/src/lib/api.js",
"frontend/src/components/YtAssignPanel.tsx",
]
REMOTE_SCRIPT = r"""
set +e
cd /opt/douyinWEB
echo "git=$(git rev-parse --short HEAD 2>/dev/null) branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)"
echo "api=$(systemctl is-active douyinweb-api) web=$(systemctl is-active douyinweb-web)"
echo "api_mtime=$(stat -c %y /opt/douyinWEB/backend/app/session_auth.py 2>/dev/null)"
echo "fe_panel_mtime=$(stat -c %y /opt/douyinWEB/frontend/src/components/YtAssignPanel.tsx 2>/dev/null)"
echo "next_mtime=$(stat -c %y /opt/douyinWEB/frontend/.next/BUILD_ID 2>/dev/null)"
python3 - <<'PY'
import hashlib, pathlib
files=[
'backend/app/session_auth.py',
'backend/app/youtube_neko.py',
'backend/app/youtube_relay_pipeline.py',
'backend/app/yt_assign_db.py',
'frontend/src/lib/api.js',
'frontend/src/components/YtAssignPanel.tsx',
]
root=pathlib.Path('/opt/douyinWEB')
for rel in files:
p=root/rel
if not p.exists():
print('MISSING', rel); continue
h=hashlib.sha256(p.read_bytes()).hexdigest()[:12]
print(h, rel)
PY
echo '--- markers ---'
grep -n '物理机配对\|默认停止\|Live 页\|目录为空' /opt/douyinWEB/frontend/src/components/YtAssignPanel.tsx 2>/dev/null | head -30
grep -Rni '物理机配对\|目录为空' /opt/douyinWEB/frontend/src/components /opt/douyinWEB/frontend/src/app/neko 2>/dev/null | head -30
echo '--- channel thumbs ---'
cd /opt/douyinWEB/backend
./.venv/bin/python - <<'PY'
from app.db import _connect, _lock
with _lock:
conn=_connect()
print('tables', [r[0] for r in conn.execute("SELECT name FROM sqlite_master WHERE type='table' AND (name LIKE '%assign%' OR name LIKE 'yt_%')").fetchall()])
for table in ('yt_oauth_channels','yt_channels','youtube_channels','yt_assign_channels','shorts_channels'):
try:
cols=[r[1] for r in conn.execute(f'PRAGMA table_info({table})').fetchall()]
print(table, 'cols', cols[:20])
except Exception as e:
print(table, 'no', e)
# try common queries
queries=[
("SELECT id, title, substr(coalesce(thumb_url,thumbnail_url,''),1,100) FROM yt_oauth_channels LIMIT 8",),
("SELECT id, title, substr(coalesce(thumb_url,''),1,100) FROM shorts_channels LIMIT 8",),
("SELECT id, name, substr(coalesce(thumbnail_url,''),1,100) FROM yt_assign_groups LIMIT 8",),
]
for (sql,) in queries:
try:
rows=conn.execute(sql).fetchall()
print('OK', sql[:50], 'n=', len(rows))
for r in rows: print(' ', r)
except Exception as e:
print('FAIL', sql[:40], e)
PY
"""
def connect(host):
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for i in range(8):
try:
c.connect(
host,
22,
"root",
PASS,
timeout=40,
allow_agent=False,
look_for_keys=False,
banner_timeout=120,
)
return c
except Exception as e:
print("retry", host, e, flush=True)
time.sleep(2 + i)
raise SystemExit("ssh fail " + host)
def run(c, cmd, timeout=120):
_i, o, e = c.exec_command(cmd, timeout=timeout)
return (o.read() + e.read()).decode("utf-8", "replace")
print("LOCAL", flush=True)
for rel in FILES:
path = rf"c:\Users\admin\Desktop\douyinWEB\{rel.replace('/', chr(92))}"
data = open(path, "rb").read()
print(f" {hashlib.sha256(data).hexdigest()[:12]} {rel}", flush=True)
for label, host in HOSTS:
print(f"\n######## {label} {host} ########", flush=True)
c = connect(host)
print(run(c, REMOTE_SCRIPT), flush=True)
c.close()
print("ALL_DONE", flush=True)