diff --git a/apps/admin/deploy/_deploy_wx_props_catalog_82.py b/apps/admin/deploy/_deploy_wx_props_catalog_82.py new file mode 100644 index 0000000..d1f2664 --- /dev/null +++ b/apps/admin/deploy/_deploy_wx_props_catalog_82.py @@ -0,0 +1,109 @@ +# -*- coding: utf-8 -*- +"""Push ops prop catalog (products.py / vip_config) to api.nomadro.cn + migrate old SKUs.""" +from __future__ import annotations + +from pathlib import Path + +import paramiko + +REPO = Path(__file__).resolve().parents[3] +HOST, USER, PASS = "82.157.112.245", "ubuntu", "Xiao4669805" + +FILES = [ + ( + REPO / "apps/api/services/ebook_svc/domains/books/products.py", + "/opt/nomadmini/backend/app/domains/books/products.py", + ), + ( + REPO / "apps/api/services/ebook_svc/services/vip_config.py", + "/opt/nomadmini/backend/app/services/vip_config.py", + ), +] + + +def rewrite(text: str) -> str: + return text.replace("ebook_svc.", "app.") + + +def main() -> None: + c = paramiko.SSHClient() + c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + c.connect(HOST, username=USER, password=PASS, timeout=40, allow_agent=False, look_for_keys=False) + sftp = c.open_sftp() + for src, dest in FILES: + data = rewrite(src.read_text(encoding="utf-8")).encode("utf-8") + tmp = f"/tmp/{Path(dest).name}" + with sftp.file(tmp, "wb") as rf: + rf.write(data) + print("up", src.name, "->", dest, len(data)) + sftp.close() + + remote = r""" +set -e +sudo cp /tmp/products.py /opt/nomadmini/backend/app/domains/books/products.py +sudo cp /tmp/vip_config.py /opt/nomadmini/backend/app/services/vip_config.py +sudo chown -R ubuntu:ubuntu /opt/nomadmini/backend/app/domains/books/products.py /opt/nomadmini/backend/app/services/vip_config.py + +# 旧微信草稿 id → 新运营 SKU(书籍 + 商城商品) +python3 <<'PY' +import sqlite3 +db = "/opt/nomadmini/data/nomadmini.db" +con = sqlite3.connect(db) +maps = { + "29": "nomad_lite", + "298": "nomad_plus", + "588": "nomad_pro", + "test": "pay_test", +} +# books.product_id +for old, new in maps.items(): + cur = con.execute("update books set product_id=? where product_id=?", (new, old)) + print("books", old, "->", new, "rows", cur.rowcount) +# shop products wxProductId if column exists +cols = {r[1] for r in con.execute("pragma table_info(shop_products)").fetchall()} if con.execute( + "select name from sqlite_master where type='table' and name='shop_products'" +).fetchone() else set() +if "wxProductId" in cols or "wx_product_id" in cols: + col = "wxProductId" if "wxProductId" in cols else "wx_product_id" + for old, new in maps.items(): + cur = con.execute(f"update shop_products set {col}=? where {col}=?", (new, old)) + print("shop", old, "->", new, "rows", cur.rowcount) +# goods table variants +for table in ("products", "goods"): + row = con.execute( + "select name from sqlite_master where type='table' and name=?", (table,) + ).fetchone() + if not row: + continue + cols = {r[1] for r in con.execute(f"pragma table_info({table})").fetchall()} + for col in ("wxProductId", "wx_product_id", "product_id"): + if col not in cols: + continue + for old, new in maps.items(): + cur = con.execute(f"update {table} set {col}=? where {col}=?", (new, old)) + if cur.rowcount: + print(table, col, old, "->", new, "rows", cur.rowcount) +con.commit() +# show current book SKUs +print("--- books product_id ---") +for r in con.execute("select id, title, product_id, price_fen from books order by id").fetchall(): + print(r) +con.close() +PY + +sudo systemctl restart nomadmini-api.service +sleep 2 +systemctl is-active nomadmini-api.service +curl -s http://127.0.0.1:8010/health || true +echo +""" + _, o, e = c.exec_command(remote, timeout=120) + print(o.read().decode()) + err = e.read().decode() + if err: + print("stderr", err[-2000:]) + c.close() + + +if __name__ == "__main__": + main() diff --git a/apps/admin/deploy/_probe_restart_products_82.py b/apps/admin/deploy/_probe_restart_products_82.py new file mode 100644 index 0000000..946d3c6 --- /dev/null +++ b/apps/admin/deploy/_probe_restart_products_82.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +from __future__ import annotations + +import paramiko + +HOST, USER, PASS = "82.157.112.245", "ubuntu", "Xiao4669805" +CMD = r""" +set -e +echo '=== file head ===' +head -8 /opt/nomadmini/backend/app/domains/books/products.py +echo '=== grep nomad_lite ===' +grep -n nomad_lite /opt/nomadmini/backend/app/domains/books/products.py || true +echo '=== processes ===' +ps aux | grep -E 'uvicorn|nomadmini|gunicorn|8010' | grep -v grep || true +echo '=== pm2 ===' +pm2 list 2>/dev/null || true +echo '=== systemd units ===' +ls /etc/systemd/system/*nom* /etc/systemd/system/*ebook* /etc/systemd/system/*api* 2>/dev/null || true +echo '=== how 8010 listens ===' +sudo ss -lntp | grep -E '8010|8000' || true +echo '=== find restart scripts ===' +ls /opt/nomadmini/*.sh /opt/nomadmini/backend/*.sh 2>/dev/null || true +cat /opt/nomadmini/ecosystem.config.* 2>/dev/null || true +""" + + +def main() -> None: + c = paramiko.SSHClient() + c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + c.connect(HOST, username=USER, password=PASS, timeout=40, allow_agent=False, look_for_keys=False) + _, o, e = c.exec_command(CMD, timeout=60) + print(o.read().decode()) + err = e.read().decode() + if err: + print("STDERR", err[-1500:]) + c.close() + + +if __name__ == "__main__": + main() diff --git a/apps/admin/deploy/_push_admin_offer_name_82.py b/apps/admin/deploy/_push_admin_offer_name_82.py new file mode 100644 index 0000000..1a7cd17 --- /dev/null +++ b/apps/admin/deploy/_push_admin_offer_name_82.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +from __future__ import annotations + +from pathlib import Path + +import paramiko + +REPO = Path(__file__).resolve().parents[3] +HOST, USER, PASS = "82.157.112.245", "ubuntu", "Xiao4669805" +SRC = REPO / "apps/api/services/ebook_svc/routers/admin.py" +DEST = "/opt/nomadmini/backend/app/routers/admin.py" + + +def main() -> None: + data = SRC.read_text(encoding="utf-8").replace("ebook_svc.", "app.").encode("utf-8") + c = paramiko.SSHClient() + c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + c.connect(HOST, username=USER, password=PASS, timeout=40, allow_agent=False, look_for_keys=False) + sftp = c.open_sftp() + with sftp.file("/tmp/admin.py", "wb") as rf: + rf.write(data) + sftp.close() + _, o, e = c.exec_command( + "sudo cp /tmp/admin.py /opt/nomadmini/backend/app/routers/admin.py && " + "sudo systemctl restart nomadmini-api.service && sleep 2 && " + "systemctl is-active nomadmini-api.service && curl -s http://127.0.0.1:8010/health", + timeout=60, + ) + print(o.read().decode()) + err = e.read().decode() + if err: + print("STDERR", err[-800:]) + c.close() + + +if __name__ == "__main__": + main() diff --git a/apps/admin/deploy/_restart_nomadmini_api_82.py b/apps/admin/deploy/_restart_nomadmini_api_82.py new file mode 100644 index 0000000..182e491 --- /dev/null +++ b/apps/admin/deploy/_restart_nomadmini_api_82.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +from __future__ import annotations + +import json +import urllib.request + +import paramiko + +HOST, USER, PASS = "82.157.112.245", "ubuntu", "Xiao4669805" + + +def main() -> None: + c = paramiko.SSHClient() + c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) + c.connect(HOST, username=USER, password=PASS, timeout=40, allow_agent=False, look_for_keys=False) + _, o, e = c.exec_command( + "sudo systemctl restart nomadmini-api.service && sleep 2 && " + "systemctl is-active nomadmini-api.service && " + "curl -s http://127.0.0.1:8010/health", + timeout=60, + ) + print(o.read().decode()) + err = e.read().decode() + if err: + print("STDERR", err[-1000:]) + c.close() + + req = urllib.request.Request( + "https://api.nomadro.cn/api/admin/login", + data=json.dumps({"username": "admin", "password": "Xiao4669805"}).encode(), + headers={"Content-Type": "application/json"}, + method="POST", + ) + tok = json.loads(urllib.request.urlopen(req, timeout=20).read()).get("token", "") + req2 = urllib.request.Request( + "https://api.nomadro.cn/api/admin/product-offers", + headers={"Authorization": "Bearer " + tok}, + ) + items = json.loads(urllib.request.urlopen(req2, timeout=20).read()).get("items") or [] + for o in items: + print(o.get("key"), o.get("product_id"), o.get("name"), o.get("price_yuan"), o.get("remark")) + + +if __name__ == "__main__": + main() diff --git a/apps/admin/src/pages/BookEdit.tsx b/apps/admin/src/pages/BookEdit.tsx index c3ab1e6..d1e1328 100644 --- a/apps/admin/src/pages/BookEdit.tsx +++ b/apps/admin/src/pages/BookEdit.tsx @@ -21,6 +21,7 @@ type Book = { chapter_count?: number word_count?: number offer_key?: string + offer_name?: string is_free?: boolean } @@ -312,7 +313,7 @@ export default function BookEdit() { {isFree ? '免费模式 · 无支付墙' - : `道具 ${book.product_id || '-'} · 试读 ${Math.min(99, book.unlock_percent)}%`} + : `${book.offer_name || book.product_id || '-'} · 试读 ${Math.min(99, book.unlock_percent)}%`} @@ -336,9 +337,9 @@ export default function BookEdit() { ) : (