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>
81 lines
2.6 KiB
Python
81 lines
2.6 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/timeutil.py",
|
|
"backend/app/models.py",
|
|
"backend/app/stats.py",
|
|
"backend/app/monitor.py",
|
|
"backend/app/youtube_monitor.py",
|
|
"backend/app/main.py",
|
|
"frontend/src/lib/api.js",
|
|
"frontend/src/app/page.tsx",
|
|
"frontend/src/app/slots/page.tsx",
|
|
"frontend/src/app/sessions/page.tsx",
|
|
"frontend/src/app/anchors/page.tsx",
|
|
"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)[-2500:], 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()
|
|
|
|
# Ensure API process uses Beijing TZ as fallback for any remaining localtime
|
|
run(
|
|
c,
|
|
"grep -q 'Environment=TZ=Asia/Shanghai' /etc/systemd/system/douyinweb-api.service || "
|
|
"sed -i '/\\[Service\\]/a Environment=TZ=Asia/Shanghai' /etc/systemd/system/douyinweb-api.service; "
|
|
"systemctl daemon-reload; "
|
|
"systemctl restart douyinweb-api --no-block; sleep 4; "
|
|
"systemctl start douyinweb-api; sleep 2; systemctl is-active douyinweb-api",
|
|
)
|
|
run(
|
|
c,
|
|
"cd /opt/douyinWEB/backend && .venv/bin/python -c "
|
|
"\"from app.timeutil import push_date_from_ts, beijing_hour, stamp_beijing; "
|
|
"print(push_date_from_ts(__import__('time').time()), beijing_hour(), stamp_beijing())\"",
|
|
)
|
|
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")
|
|
c.close()
|
|
print("DONE")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|