Add isolated Shorts OAuth/clip/upload worker (default off), youtube-svc + group poller, Beijing time UX, and SHORTS.md. Co-authored-by: Cursor <cursoragent@cursor.com>
89 lines
3.1 KiB
Python
89 lines
3.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
import time
|
|
from pathlib import Path
|
|
import paramiko
|
|
|
|
HOST = "107.173.30.245"
|
|
USER = "root"
|
|
PASSWORD = "Xiao4669805"
|
|
REMOTE = "/opt/douyinWEB"
|
|
LOCAL = Path(__file__).resolve().parents[1]
|
|
FILES = [
|
|
"backend/app/pb_sync.py",
|
|
"backend/app/main.py",
|
|
"backend/app/youtube_monitor.py",
|
|
"frontend/src/app/settings/page.tsx",
|
|
]
|
|
|
|
|
|
def run(c, cmd, timeout=420):
|
|
print("$", cmd[:180], flush=True)
|
|
chan = c.get_transport().open_session()
|
|
chan.settimeout(timeout)
|
|
chan.get_pty()
|
|
chan.exec_command(cmd)
|
|
buf = []
|
|
while True:
|
|
if chan.recv_ready():
|
|
buf.append(chan.recv(65535).decode("utf-8", "replace"))
|
|
if chan.exit_status_ready() and not chan.recv_ready():
|
|
break
|
|
time.sleep(0.25)
|
|
while chan.recv_ready():
|
|
buf.append(chan.recv(65535).decode("utf-8", "replace"))
|
|
code = chan.recv_exit_status()
|
|
print("".join(buf)[-2800:], flush=True)
|
|
return code
|
|
|
|
|
|
def main():
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(HOST, 22, USER, PASSWORD, timeout=30, allow_agent=False, look_for_keys=False)
|
|
sftp = c.open_sftp()
|
|
for rel in FILES:
|
|
print("upload", rel, flush=True)
|
|
sftp.put(str(LOCAL / rel), f"{REMOTE}/{rel}")
|
|
sftp.close()
|
|
|
|
run(c, "systemctl restart douyinweb-pb douyinweb-api --no-block; sleep 5; systemctl start douyinweb-pb douyinweb-api; sleep 2; systemctl is-active douyinweb-pb douyinweb-api")
|
|
run(c, "curl -s -X POST http://127.0.0.1:8014/api/pb/bootstrap; echo")
|
|
run(c, "curl -s -X POST http://127.0.0.1:8014/api/pb/sync-groups; echo")
|
|
run(c, "curl -s -X POST 'http://127.0.0.1:8014/api/pb/sync-sessions?limit=100'; echo")
|
|
|
|
# verify records on 8092
|
|
sftp = c.open_sftp()
|
|
with sftp.file(f"{REMOTE}/backend/_yt_pb_check.py", "w") as f:
|
|
f.write(
|
|
"""
|
|
import asyncio, httpx, os
|
|
os.environ['DY_PB_URL']='http://127.0.0.1:8092'
|
|
from app import pb_sync
|
|
async def main():
|
|
await pb_sync.ensure_admin()
|
|
h = await pb_sync._auth_headers(force=True)
|
|
print('token', bool(h.get('Authorization')))
|
|
async with await pb_sync._client() as client:
|
|
cols = await client.get('/api/collections', headers=h)
|
|
names = sorted([i.get('name') for i in (cols.json().get('items') or []) if i.get('type')=='base'])
|
|
print('collections', names)
|
|
g = await client.get('/api/collections/yt_groups/records', headers=h, params={'perPage':5})
|
|
print('yt_groups', g.status_code, 'total', g.json().get('totalItems'))
|
|
for i in g.json().get('items') or []:
|
|
print(' -', i.get('name'), i.get('channel_key'), i.get('last_status'))
|
|
asyncio.run(main())
|
|
"""
|
|
)
|
|
sftp.close()
|
|
run(c, "cd /opt/douyinWEB/backend && .venv/bin/python _yt_pb_check.py; rm -f _yt_pb_check.py")
|
|
|
|
if run(c, "cd /opt/douyinWEB/frontend && npm run build", timeout=420) != 0:
|
|
raise SystemExit(1)
|
|
run(c, "systemctl restart douyinweb-web --no-block; sleep 3; systemctl is-active douyinweb-api douyinweb-web douyinweb-pb")
|
|
c.close()
|
|
print("DONE")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|