全量细审修复:部署漏配防清空、scrypt 并发闸、发布冲突可解、价格文件只在改了才写、排位扩容
- cms.py:没设 YS_PORTAL_DIR / YS_ORDER_DIR 或缺 content/site.json 时拒绝工作(不建空的第一版,免得一发布清空网站); 同时最多 2 个 scrypt(内存上限 256M);登录冷却记录定期清理;价格 / 付款只在这次发布真改了才写回 (不覆盖 admin.py price 的改动) - 后台页面:发布冲突二选一(丢掉我的草稿 / 确认后覆盖发布);草稿没存上、还有图在上传时不让发布 - layout.js:中圈排满后分档到外圈空槽之间找位置,40 条世界线也不重叠;去掉慢的 Math.hypot - config.js:后台把世界线删光也照实显示;门户删掉旧启动仪式留下的死数据;版本号 v=3 - 测试:内容后台 78 / 回归 27 / 数据库 38 全过;端到端浏览器 36 全过 - 文档同步(交接文档、内容后台设计「实现对照」、后端交接说明、交付清单) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -508,6 +508,7 @@ def cmd_price(argv):
|
||||
raise SystemExit("用法:price / price per N / price set N 价格 [链接] / price rm N")
|
||||
d["tiers"] = tiers
|
||||
S.jsave(S.PRICES_FILE, d)
|
||||
print("⚠️ 2026-10-05 起价格建议在内容后台改(「价格与付款」页):后台下次改价格并发布时,会以后台里的为准覆盖这里的改动。")
|
||||
try:
|
||||
os.chmod(S.PRICES_FILE, 0o644)
|
||||
except OSError:
|
||||
|
||||
+45
-18
@@ -608,6 +608,8 @@ class CMS(object):
|
||||
self.fails = {} # 登录失败:key -> [时间戳]
|
||||
self.fail_lock = threading.Lock()
|
||||
self.uploads = {} # 上传限频:uid -> [时间戳]
|
||||
# 算一次 scrypt 要 16MB 内存:这台机器服务进程上限 256M,同时最多算 2 个,免得一波并发登录把进程撑爆
|
||||
self.hash_sem = threading.BoundedSemaphore(2)
|
||||
c = store.conn()
|
||||
c.executescript(_SCHEMA)
|
||||
with store.tx() as c: # 一个账号都没有 → 建初始账号(BEGIN IMMEDIATE:两个进程同时首启也只建一个)
|
||||
@@ -708,13 +710,27 @@ class CMS(object):
|
||||
return int(worst + 0.999) if worst > 0 else 0
|
||||
|
||||
def _fail(self, keys):
|
||||
now = time.time()
|
||||
with self.fail_lock:
|
||||
for k in keys:
|
||||
self.fails.setdefault(k, []).append(time.time())
|
||||
self.fails.setdefault(k, []).append(now)
|
||||
if len(self.fails) > 2000: # 被大量 IP 扫的时候:把过了窗口期的记录清掉,内存不跟着涨
|
||||
for k in [k for k, v in self.fails.items() if not v or now - v[-1] > FAIL_WIN]:
|
||||
self.fails.pop(k, None)
|
||||
|
||||
# ---------------------------------------------------------------- 内容
|
||||
def dirs_ok(self):
|
||||
"""门户 / 下单页目录配好了没有。没配好就**什么都不写**:不然会在当前目录建个叫 <PORTAL_DIR> 的怪目录,
|
||||
第一版内容还会是空骨架 —— 店主一发布,网站内容就被清空。"""
|
||||
for name, d in (("YS_PORTAL_DIR", PORTAL_DIR), ("YS_ORDER_DIR", ORDER_DIR)):
|
||||
if not d or d.startswith("<") or not os.path.isdir(d):
|
||||
raise Bad("服务器没配好 %s(现在是「%s」)—— 内容后台先不能用,请照交接文档 7.1b 配好再重启" % (name, d))
|
||||
|
||||
def _seed(self):
|
||||
"""第一次用:把网站现在的内容文件当成第 1 版(文件没有就用空骨架)。"""
|
||||
"""第一次用:把网站现在的内容文件当成第 1 版。门户的 content/site.json 必须在(防止从空骨架开始、一发布就把网站清空)。"""
|
||||
self.dirs_ok()
|
||||
if not os.path.isfile(os.path.join(PORTAL_DIR, "content", "site.json")):
|
||||
raise Bad("门户目录里没有 content/site.json —— 先把仓库里的 portal/content/ 放上去再用内容后台")
|
||||
def jl(p):
|
||||
try:
|
||||
with open(p, encoding="utf-8") as f:
|
||||
@@ -734,8 +750,7 @@ class CMS(object):
|
||||
try:
|
||||
doc = normalize({"site": site, "order": order}, self.tpl_keys)
|
||||
except Bad as e:
|
||||
self.log("内容后台:现有内容文件不合格(%s),从空骨架开始" % e)
|
||||
doc = normalize({}, self.tpl_keys)
|
||||
raise Bad("网站现有的内容文件不合格(%s)—— 修好再用内容后台" % e)
|
||||
with self.store.tx() as c:
|
||||
if not c.execute("SELECT 1 FROM cms_versions LIMIT 1").fetchone():
|
||||
c.execute("INSERT INTO cms_versions (no, data, note, by, at, chg) VALUES (1, ?, '从网站现有内容导入', 'system', ?, '全部内容')",
|
||||
@@ -752,8 +767,14 @@ class CMS(object):
|
||||
r = self.store.conn().execute("SELECT data, base, updated, by FROM cms_draft WHERE k='doc'").fetchone()
|
||||
return (json.loads(r[0]), r[1], r[2], r[3]) if r else (None, None, None, None)
|
||||
|
||||
def write_files(self, doc):
|
||||
def write_files(self, doc, prev=None):
|
||||
"""prev = 网站上现在那一版。价格档位 / 付款方式**只有这次真的改了**才写回 prices.json / payinfo.json ——
|
||||
不然有人用 admin.py price 在命令行改过价格,店主随便发布一张画就会把它悄悄改回去。"""
|
||||
self.dirs_ok()
|
||||
site, order = doc["site"], doc["order"]
|
||||
po = (prev or {}).get("order") or {}
|
||||
write_prices = prev is None or po.get("prices") != order["prices"]
|
||||
write_pay = prev is None or po.get("pay") != order["pay"]
|
||||
stamp = datetime.now(CST).strftime("%Y-%m-%d %H:%M")
|
||||
head = "/* 由内容后台发布生成(%s)。别手改:下次发布会被覆盖。改内容请用内容后台。 */\n" % stamp
|
||||
_atomic_write(os.path.join(PORTAL_DIR, "content", "site.json"), json.dumps(site, ensure_ascii=False, indent=1))
|
||||
@@ -768,13 +789,15 @@ class CMS(object):
|
||||
return v if isinstance(v, dict) else {}
|
||||
except (OSError, ValueError):
|
||||
return {}
|
||||
pr = jl(self.prices_file)
|
||||
pr["per"] = order["prices"]["per"]
|
||||
pr["tiers"] = {str(t["n"]): {"price": t["price"], "payplatform": t["url"]} for t in order["prices"]["tiers"]}
|
||||
_atomic_write(self.prices_file, json.dumps(pr, ensure_ascii=False, indent=1), 0o640)
|
||||
pay = jl(self.payinfo_file)
|
||||
pay.update(order["pay"])
|
||||
_atomic_write(self.payinfo_file, json.dumps(pay, ensure_ascii=False, indent=1), 0o640)
|
||||
if write_prices:
|
||||
pr = jl(self.prices_file)
|
||||
pr["per"] = order["prices"]["per"]
|
||||
pr["tiers"] = {str(t["n"]): {"price": t["price"], "payplatform": t["url"]} for t in order["prices"]["tiers"]}
|
||||
_atomic_write(self.prices_file, json.dumps(pr, ensure_ascii=False, indent=1), 0o640)
|
||||
if write_pay:
|
||||
pay = jl(self.payinfo_file)
|
||||
pay.update(order["pay"])
|
||||
_atomic_write(self.payinfo_file, json.dumps(pay, ensure_ascii=False, indent=1), 0o640)
|
||||
|
||||
def publish(self, who, ip, doc, note, base):
|
||||
with self.lock:
|
||||
@@ -784,7 +807,7 @@ class CMS(object):
|
||||
rows = diff_summary(cur, doc)
|
||||
if not rows:
|
||||
raise Bad("草稿和网站上的一模一样,没有要发布的")
|
||||
self.write_files(doc)
|
||||
self.write_files(doc, cur)
|
||||
no = cur_no + 1
|
||||
with self.store.tx() as c:
|
||||
c.execute("INSERT INTO cms_versions (no, data, note, by, at, chg) VALUES (?,?,?,?,?,?)",
|
||||
@@ -796,6 +819,7 @@ class CMS(object):
|
||||
|
||||
# ---------------------------------------------------------------- 上传
|
||||
def save_upload(self, uid, name, data_url):
|
||||
self.dirs_ok()
|
||||
now = time.time()
|
||||
arr = [t for t in self.uploads.get(uid, []) if now - t < 3600]
|
||||
if len(arr) >= 120:
|
||||
@@ -966,9 +990,10 @@ class CMS(object):
|
||||
if wait:
|
||||
return self._reply(h, 429, {"ok": False, "error": "错的次数太多了,%d 秒后再试" % wait, "wait": wait})
|
||||
r = self.user_row(who) if who else None
|
||||
ok = bool(r) and not r[5] and check_pw(pw, r[3])
|
||||
if not r:
|
||||
check_pw(pw, "scrypt$16384$8$1$AAAAAAAAAAAAAAAAAAAAAA==$AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=") # 账号不存在也算一遍,别让时间差暴露账号在不在
|
||||
with self.hash_sem:
|
||||
ok = bool(r) and not r[5] and check_pw(pw, r[3])
|
||||
if not r:
|
||||
check_pw(pw, "scrypt$16384$8$1$AAAAAAAAAAAAAAAAAAAAAA==$AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=") # 账号不存在也算一遍,别让时间差暴露账号在不在
|
||||
if not ok:
|
||||
self._fail(keys)
|
||||
self.audit(who or "?", ip, "登录失败")
|
||||
@@ -1000,8 +1025,10 @@ class CMS(object):
|
||||
|
||||
def _ep_post_password(self, h, s, q, b):
|
||||
r = self.store.conn().execute("SELECT pw FROM cms_users WHERE id=?", (s["uid"],)).fetchone()
|
||||
old, new = str(b.get("old") or ""), str(b.get("new") or "")
|
||||
if not check_pw(old, r[0]):
|
||||
old, new = str(b.get("old") or "")[:200], str(b.get("new") or "")[:200]
|
||||
with self.hash_sem:
|
||||
right = check_pw(old, r[0])
|
||||
if not right:
|
||||
return self._reply(h, 400, {"ok": False, "error": "现在的密码不对"})
|
||||
p = pw_problem(new, old)
|
||||
if p:
|
||||
|
||||
@@ -223,6 +223,9 @@ check("付款方式写回 payinfo.json", pay.get("note") == "付款时留言写
|
||||
check("下单页的价格接口立刻反映新档位", S.price_for(3) == 15)
|
||||
lit = [x for x in json.loads(site_js.split("window.JZ_CONTENT = ", 1)[1].rsplit(";", 1)[0])["universe"]["UNIVERSES"] if not x.get("empty")]
|
||||
check("星系图数据:新世界线没写位置(交给 layout.js 自动排)", any(x["no"] == "0005" for x in lit))
|
||||
# 命令行改了价格之后,后台发布别的内容不能把它改回去
|
||||
pr = json.load(open(S.PRICES_FILE, encoding="utf-8")); pr["tiers"]["5"] = {"price": 22, "payplatform": ""}
|
||||
S.jsave(S.PRICES_FILE, pr)
|
||||
b = C(ip="203.0.113.40"); b.login("admin", NEWPW)
|
||||
st, j = b.req("content")
|
||||
d2 = j["draft"]; d2["site"]["hero"]["cta1"] = "看看画"
|
||||
@@ -231,6 +234,7 @@ st, j = b.req("publish", {"base": 1})
|
||||
check("别人已经发布过(底稿是旧版)→ 409 冲突,不静默覆盖", st == 409 and j.get("conflict"), j)
|
||||
st, j = b.req("publish", {"base": 2})
|
||||
check("刷新到新底稿再发 → v3", st == 200 and j.get("version") == 3, j)
|
||||
check("后台发布没动价格时,不覆盖命令行改过的 prices.json", json.load(open(S.PRICES_FILE, encoding="utf-8")).get("tiers", {}).get("5", {}).get("price") == 22)
|
||||
st, j = a.req("rollback", {"no": 1})
|
||||
check("回到 v1 → 记为 v4", st == 200 and j.get("version") == 4, j)
|
||||
v1 = json.loads(db().execute("SELECT data FROM cms_versions WHERE no=1").fetchone()[0])
|
||||
@@ -321,6 +325,24 @@ ps = [subprocess.Popen([sys.executable, "-c", probe], env=dict(os.environ, YS_RO
|
||||
n = sqlite3.connect(os.path.join(R2, "ys.db")).execute("SELECT COUNT(*) FROM cms_users").fetchone()[0]
|
||||
check("三个进程同时首次启动:只建了一个初始账号", n == 1, n)
|
||||
|
||||
# ================================================================== 11b. 部署漏配:目录不对 / 缺内容文件 → 不建第一版、不写文件
|
||||
import store as ST
|
||||
R3 = tempfile.mkdtemp(prefix="ys-cms-dirs-")
|
||||
c3 = S.cms.CMS(ST.Store(R3), R3, log=lambda *a: None, prices_file=os.path.join(R3, "prices.json"), payinfo_file=os.path.join(R3, "payinfo.json"), tpl_keys=S.TPL_KEYS, pngcheck=S.pngcheck)
|
||||
old_p = S.cms.PORTAL_DIR
|
||||
for bad_dir, why in (("<PORTAL_DIR>", "没配环境变量"), (os.path.join(R3, "empty-www"), "目录里没有 content/site.json")):
|
||||
if not bad_dir.startswith("<"):
|
||||
os.makedirs(bad_dir, exist_ok=True)
|
||||
S.cms.PORTAL_DIR = bad_dir
|
||||
try:
|
||||
c3.current(); refused = False
|
||||
except S.cms.Bad as e:
|
||||
refused = True; msg = str(e)
|
||||
n = sqlite3.connect(os.path.join(R3, "ys.db")).execute("SELECT COUNT(*) FROM cms_versions").fetchone()[0]
|
||||
check("部署漏配(%s):内容后台拒绝工作、不建空的第一版" % why, refused and n == 0 and not os.path.exists("<PORTAL_DIR>"), msg if refused else "没拒")
|
||||
S.cms.PORTAL_DIR = old_p
|
||||
shutil.rmtree(R3, ignore_errors=True)
|
||||
|
||||
# ================================================================== 12. 原有接口不受影响
|
||||
try:
|
||||
with urllib.request.urlopen("http://127.0.0.1:%d/api/status" % srv.server_address[1], timeout=10) as r:
|
||||
|
||||
@@ -54,7 +54,7 @@
|
||||
| `cms.py` | ~900 | **内容后台**(2026-10-05 晚):账号 / 会话 / 草稿 / 发布 / 回滚 / 传图;`server.py` 把 `/api/cms/*` 交给它。见仓库根目录 `内容后台设计.md` |
|
||||
| `store.py` | ~400 | **数据层**(2026-10-05 新增):SQLite 建库 / 第一次启动自动导入旧 JSON / 存取 / 导出回旧格式 / 体检 / 热备份 |
|
||||
| `tests/回执复现测试.py` | ~280 | 回归 + 漏洞复现(27 条,HTTP 层打接口) |
|
||||
| `tests/内容后台测试.py` | ~330 | 内容后台专项(75 条:强制改密、无明文、Cookie、https / CSRF / 来源 / 冷却、校验、发布、回滚、传图、会话、命令行) |
|
||||
| `tests/内容后台测试.py` | ~360 | 内容后台专项(78 条:强制改密、无明文、Cookie、https / CSRF / 来源 / 冷却、校验、发布、回滚、传图、会话、命令行) |
|
||||
| `tests/数据库测试.py` | ~290 | 数据库专项(38 条:全新安装、迁移、回退、事务、并发、规模),数据全是现编的 |
|
||||
|
||||
> 这几个文件是**自足**的:没有 import 本项目之外的模块。**部署时 `store.py`、`cms.py` 必须和 `server.py` 放在同一个目录**(`server.py` 直接 `import store` / `import cms`)。
|
||||
|
||||
+5
-5
@@ -1,19 +1,19 @@
|
||||
# 交付清单(自查用)
|
||||
|
||||
> 生成:2026-10-05 21:24 共 38 个文件 合计 44.9 MB(2026-10-05 晚:加了内容后台 cms.py、内容后台测试;nginx 片段加了内容后台一节)
|
||||
> 生成:2026-10-05 21:54 共 38 个文件 合计 44.9 MB(2026-10-05 晚:内容后台 cms.py + 推送后全量细审的修复)
|
||||
|
||||
| 文件 | 字节 | SHA-256 |
|
||||
|---|---|---|
|
||||
| `README.md` | 8,696 | `5cef368dbf5916def012dbfcf7fdfb35d1f435faf5a7b42b65f6ad683343b1c2` |
|
||||
| `backend-site/admin.py` | 30,200 | `70df55efa4172aca7e244138ac2252c3af5121459340f2cbfac887fd40754bde` |
|
||||
| `backend-site/cms.py` | 59,893 | `b549a0d6b011f15eefa0c20325d23e5158a3bc1ecdca462b864ababac183fb25` |
|
||||
| `backend-site/admin.py` | 30,382 | `9b4069444b4c1716a6abef22dfada6bcb3171d78c896579457c926a468d734ec` |
|
||||
| `backend-site/cms.py` | 61,942 | `3d5ea3869427f94fbc9a71e464e10b2c275450e617fbc42c9feb68a66b45fde3` |
|
||||
| `backend-site/pngcheck.py` | 4,945 | `ccec7ab21b0399da651029ffa5781bad498e0905b31a1102f6ba3e3f01e8594d` |
|
||||
| `backend-site/server.py` | 181,993 | `05c0aaa93f5adf39beecb9042313da8233099cee6060013d8f7cbf7fd142788a` |
|
||||
| `backend-site/store.py` | 19,303 | `9d22007b43188225d4254f8c9710c310d9d55635d0d67496ec99e91fe47bcd2d` |
|
||||
| `backend-site/tests/内容后台测试.py` | 22,569 | `105b2115668d8eb7cfd60e86d6b2cb44f7a564f2f84d40f56cea584f8a13e0b8` |
|
||||
| `backend-site/tests/内容后台测试.py` | 24,099 | `9fd44d4aff00c32270fde4347e365781b3fb4b7aca89e024b5b3b252416b9f87` |
|
||||
| `backend-site/tests/回执复现测试.py` | 15,355 | `4529f6076abdfce89bf4406c7fbd0789482deaa595383749580bdc3e08ddc327` |
|
||||
| `backend-site/tests/数据库测试.py` | 16,045 | `9838f32bf213cd3c727625a50b5e0cbff7da98ded8b7452cacd187c448bde04f` |
|
||||
| `backend-site/交接说明.md` | 22,394 | `8e4dd211654fa7a0c30b26c8e1368274f59e91ea2104ba5e73122f690bc55b6b` |
|
||||
| `backend-site/交接说明.md` | 22,394 | `d226d6613f48343a867e2b5961b3290c3bd8238f3941eeca36b1efc5dd01ac48` |
|
||||
| `backend-site/回执-Claude.md` | 37,690 | `de1648832fe8bcd004c32ed538d4a90c6c29a0d72b8c70f448fdbe5332d8b5d9` |
|
||||
| `backend-tools/chk_worker.ps1` | 486 | `939a42cafa0954347f28d69e75b8af407ed1dab870cc3956fa8b7c5eb55e372f` |
|
||||
| `backend-tools/deploy.py` | 5,694 | `bf2cf47e715a3663faba5f1125ca9dee57596fd59664e2898515985924a0cc8c` |
|
||||
|
||||
+18
-1
@@ -905,7 +905,9 @@ $('#prevBtn').onclick = async () => {
|
||||
+ '<div class="mf"><button class="btn" type="button" onclick="closeModal()">知道了</button></div>');
|
||||
};
|
||||
async function openPublish() {
|
||||
if (DOC.site.gallery.some(g => g._up)) return toast('还有图在上传,等传完再发布', true);
|
||||
await flush();
|
||||
if (dirtyLocal) return toast('最新的改动没存上(看右上角的提示),先改好再发布 —— 不然发出去的是上一次存上的草稿', true);
|
||||
if (!CHANGES.length) return toast('没有要发布的改动');
|
||||
openModal('<h3>发布这些改动</h3><p>发布后马上出现在网站上。每次发布都留一份完整版本,随时能回到之前的版本。</p>'
|
||||
+ '<ul class="chg">' + CHANGES.map(c => '<li><b>' + esc(c[0]) + '</b><span>' + esc(dtxt(c)) + '</span></li>').join('') + '</ul>'
|
||||
@@ -915,12 +917,27 @@ async function openPublish() {
|
||||
$('#pubGo').disabled = true;
|
||||
const j = await api('publish', { note: $('#pubNote').value.trim(), base: BASE });
|
||||
if (!j.ok) { $('#pubGo').disabled = false;
|
||||
if (j.conflict) { closeModal(); openModal('<h3>别人刚发布过</h3><p>' + esc(j.error) + '</p><div class="mf"><button class="btn" type="button" onclick="closeModal()">先不发</button><button class="btn pri" type="button" id="reloadGo">刷新看看</button></div>'); $('#reloadGo').onclick = async () => { closeModal(); await loadContent(); renderAll(); go('home'); }; return; }
|
||||
if (j.conflict) { closeModal(); conflictModal(j.error); return; }
|
||||
return toast(j.error || '发布失败', true); }
|
||||
closeModal(); await loadContent(); renderAll(); go(PANE); toast('v' + j.version + ' 已发布,网站上已经是新内容');
|
||||
};
|
||||
}
|
||||
$('#pubBtn').onclick = openPublish;
|
||||
/* 别人在你编辑期间发布过:二选一 —— 丢掉自己的草稿看网站上现在的,或者确认后用自己的草稿覆盖发布 */
|
||||
function conflictModal(msg) {
|
||||
openModal('<h3>别人刚发布过</h3><p>' + esc(msg) + '</p><p>可以先去「发布记录」看对方改了什么。然后:</p>'
|
||||
+ '<div class="mf"><button class="btn" type="button" onclick="closeModal()">先不发</button><button class="btn bad" type="button" id="cfDrop">丢掉我的草稿</button><button class="btn pri" type="button" id="cfMine">用我的草稿覆盖发布</button></div>');
|
||||
$('#cfDrop').onclick = async () => { closeModal(); clearTimeout(saveTimer); dirtyLocal = false; await api('discard', {}); await loadContent(); renderAll(); go('home'); toast('已丢掉你的草稿,现在显示的是网站上的内容'); };
|
||||
$('#cfMine').onclick = async () => {
|
||||
if (!confirm('确定用你的草稿覆盖?对方那次发布的改动会被你的版本盖掉(发布记录里还能找回)。')) return;
|
||||
closeModal();
|
||||
const mine = clone(DOC); await loadContent(); DOC = mine; BASE = VERSION; dirtyLocal = true;
|
||||
if (!(await save())) return;
|
||||
const j = await api('publish', { note: '覆盖发布(基于 v' + VERSION + ')', base: VERSION });
|
||||
if (!j.ok) return toast(j.error || '发布失败', true);
|
||||
await loadContent(); renderAll(); go(PANE); toast('v' + j.version + ' 已发布');
|
||||
};
|
||||
}
|
||||
async function renderVersions() {
|
||||
const j = await api('versions');
|
||||
const V = j.versions || [];
|
||||
|
||||
@@ -75,6 +75,6 @@ window.JZ_UNIVERSE = {
|
||||
(function () {
|
||||
var C = window.JZ_CONTENT && window.JZ_CONTENT.universe, U = window.JZ_UNIVERSE;
|
||||
if (!C || !U) return;
|
||||
if (Array.isArray(C.UNIVERSES) && C.UNIVERSES.length) U.UNIVERSES = C.UNIVERSES;
|
||||
if (Array.isArray(C.UNIVERSES)) U.UNIVERSES = C.UNIVERSES; // 后台把世界线删光了也照实显示(不退回兜底)
|
||||
if (C.LOOKS && typeof C.LOOKS === 'object') U.LOOKS = C.LOOKS;
|
||||
})();
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* ============================================================================= */
|
||||
import * as THREE from 'three';
|
||||
import { makePlanet } from './planets.js?v=2';
|
||||
import { layoutSystems } from './layout.js?v=2';
|
||||
import { layoutSystems } from './layout.js?v=3';
|
||||
|
||||
export function mountGalaxy(el) {
|
||||
const CFG = window.JZ_UNIVERSE, G = CFG.GALAXY, C = G.colors;
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
* · 补给线连到「比它更靠近核心、又离它最近」的那颗星(没有合适的就连核心),
|
||||
* 而且这条线不能从别的星系中间穿过;
|
||||
* · 按编号从小到大一颗一颗排,每一颗只看排在它前面的 —— 所以**新加一条,已有的星和线都不动**。
|
||||
* · 中圈排满(二十来条以后)才会去外圈空槽之间找位置;那一档要避开空槽,所以改「空槽数」可能让这几颗挪一挪。
|
||||
*
|
||||
* 用法:import { layoutSystems } from './layout.js';
|
||||
* const L = layoutSystems(window.JZ_UNIVERSE) → [{ u, look, x, z, kind, parent }]
|
||||
@@ -26,12 +27,13 @@ export function footprint(look) {
|
||||
return (look.r || 1) * 2.2 + (moons.length ? Math.max(...moons) : 0);
|
||||
}
|
||||
|
||||
const dist = (a, b) => Math.hypot(a.x - b.x, a.z - b.z);
|
||||
const dist = (a, b) => { const dx = a.x - b.x, dz = a.z - b.z; return Math.sqrt(dx * dx + dz * dz); }; // 别用 Math.hypot:V8 里慢好几倍
|
||||
/** 点到线段的距离(补给线按直线近似;实际画的是稍微拱起来的弧,水平投影还是这条线) */
|
||||
function segDist(p, a, b) {
|
||||
const vx = b.x - a.x, vz = b.z - a.z, L2 = vx * vx + vz * vz || 1;
|
||||
const t = Math.max(0, Math.min(1, ((p.x - a.x) * vx + (p.z - a.z) * vz) / L2));
|
||||
return Math.hypot(p.x - (a.x + vx * t), p.z - (a.z + vz * t));
|
||||
const dx = p.x - (a.x + vx * t), dz = p.z - (a.z + vz * t);
|
||||
return Math.sqrt(dx * dx + dz * dz);
|
||||
}
|
||||
|
||||
export function layoutSystems(CFG) {
|
||||
@@ -74,7 +76,7 @@ export function layoutSystems(CFG) {
|
||||
|
||||
// 给一个候选位置挑补给线起点:比它更靠近核心的星(或核心),线不能穿过别的星系
|
||||
function parentFor(c, others) {
|
||||
const cands = [CORE, ...others.filter(o => Math.hypot(o.x, o.z) < c.r - 4)];
|
||||
const cands = [CORE, ...others.filter(o => o.r < c.r - 4)];
|
||||
let best = null;
|
||||
for (const p of cands) {
|
||||
const len = dist(p, c);
|
||||
@@ -88,33 +90,53 @@ export function layoutSystems(CFG) {
|
||||
return best;
|
||||
}
|
||||
|
||||
for (const u of list) {
|
||||
if (u.empty || out.has(u.no)) continue;
|
||||
const look = lookOf(u), fp = footprint(look);
|
||||
let best = null;
|
||||
// 候选位置:按「够不够宽敞」先粗筛打分(便宜),再只给排在前面的几十个检查补给线会不会穿星(贵)—— 40 条世界线也很快。
|
||||
// 中圈排满了就分档放宽:到外圈空槽之间找位置(这时也要避开空槽)、间距要求逐步降低;最后兜底也保证不叠在别人身上。
|
||||
const slots = [...out.values()].filter(s => s.kind === 'slot');
|
||||
const PASSES = [
|
||||
{ rMax: R * 0.68, need: 4, offs: [-0.2, -0.1, 0, 0.1, 0.2], slots: false },
|
||||
{ rMax: R * 0.96, need: 3, offs: [-0.3, -0.2, -0.1, 0, 0.1, 0.2, 0.3], slots: true },
|
||||
{ rMax: R * 0.98, need: 1.2, offs: [-0.4, -0.3, -0.2, -0.1, 0, 0.1, 0.2, 0.3, 0.4], slots: true },
|
||||
];
|
||||
function place(fp, pass) {
|
||||
const others = pass.slots ? placed.concat(slots) : placed, cands = [];
|
||||
for (let arm = 0; arm < ARMS; arm++) {
|
||||
for (let r = rMin; r <= rMax; r += 1.25) {
|
||||
for (const off of [-0.2, -0.1, 0, 0.1, 0.2]) {
|
||||
for (let r = rMin; r <= pass.rMax; r += 1.25) {
|
||||
for (const off of pass.offs) {
|
||||
const a = armAngle(r, arm, G) + off;
|
||||
const c = { x: Math.cos(a) * r, z: Math.sin(a) * r, r };
|
||||
let clear = r - CORE.fp - fp;
|
||||
for (const o of placed) clear = Math.min(clear, dist(o, c) - o.fp - fp);
|
||||
if (clear < 4) continue;
|
||||
const par = parentFor(c, placed);
|
||||
if (!par) continue;
|
||||
for (const o of others) clear = Math.min(clear, dist(o, c) - o.fp - fp);
|
||||
if (clear < pass.need) continue;
|
||||
// 分数:够宽敞(封顶,不为了宽敞跑到边上)、靠近中圈、所在旋臂人少、在旋臂正中更好
|
||||
const score = Math.min(clear, 12) - 0.08 * Math.abs(r - mid) - 2.2 * armCount[arm] - 3 * Math.abs(off) + Math.min(par.clear, 6) * 0.3;
|
||||
if (!best || score > best.score + 1e-9) best = { score, r, a, arm, parent: par.p };
|
||||
cands.push({ c, a, r, arm, clear, score: Math.min(clear, 12) - 0.08 * Math.abs(r - mid) - 2.2 * armCount[arm] - 3 * Math.abs(off) });
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!best) { // 实在挤不下(几十条以后):退回外圈槽位,至少不叠在别人身上
|
||||
const e = Math.max(0, num(u) - first), r = R * 0.86;
|
||||
put(u, look, r, armAngle(r, e % ARMS, G) + 0.32 * Math.floor(e / ARMS) + 0.16, 'auto', null);
|
||||
cands.sort((x, y) => y.score - x.score || x.r - y.r || x.a - y.a);
|
||||
let best = null;
|
||||
for (const k of cands.slice(0, 60)) {
|
||||
const par = parentFor(k.c, placed);
|
||||
if (!par) continue;
|
||||
const s = k.score + Math.min(par.clear, 6) * 0.3;
|
||||
if (!best || s > best.s + 1e-9) best = { s, k, parent: par.p };
|
||||
}
|
||||
if (best) return best;
|
||||
return cands.length ? { k: cands[0], parent: CORE } : null; // 线怎么都会擦到别的星:就近连核心,至少星不叠
|
||||
}
|
||||
|
||||
for (const u of list) {
|
||||
if (u.empty || out.has(u.no)) continue;
|
||||
const look = lookOf(u), fp = footprint(look);
|
||||
let got = null;
|
||||
for (const pass of PASSES) { got = place(fp, pass); if (got) break; }
|
||||
if (!got) { // 整张图都满了(几十条以后):退到最外圈,按编号错开
|
||||
const e = Math.max(0, num(u) - first), r = R * 1.02 + 2 * Math.floor(e / ARMS);
|
||||
placed.push(put(u, look, r, armAngle(r, e % ARMS, G) + 0.16, 'auto', null));
|
||||
continue;
|
||||
}
|
||||
const s = put(u, look, best.r, best.a, 'auto', best.parent.no);
|
||||
armCount[best.arm]++;
|
||||
const s = put(u, look, got.k.r, got.k.a, 'auto', got.parent.no);
|
||||
armCount[got.k.arm]++;
|
||||
placed.push(s);
|
||||
}
|
||||
// 4) 空槽的淡线:接到最近的、不穿星的已点亮星(或核心)
|
||||
|
||||
+2
-12
@@ -1687,7 +1687,7 @@ window.__hdcEarly=(function(){
|
||||
<script src="content/site.js"></script>
|
||||
<script>/* 预览草稿:后台点「预览」会带 ?preview=1 打开;只有登录了内容后台的浏览器拿得到草稿(拿不到就还是正式内容) */
|
||||
if(/[?&]preview=1(&|$)/.test(location.search)) document.write('<script src="/order/api/cms/draft.js"><\/script>');</script>
|
||||
<script src="assets/universe/config.js?v=2"></script>
|
||||
<script src="assets/universe/config.js?v=3"></script>
|
||||
<script>
|
||||
/* ============================================================================
|
||||
金钻宇宙门户 · 状态机与交互(纯原生,零依赖)
|
||||
@@ -1815,16 +1815,6 @@ const BOARD_SLOTS = { gallery:6 };
|
||||
/* 浏览器标题 / 文档描述里的站点名。 */
|
||||
const SITE_NAME = '金钻客栈';
|
||||
|
||||
/* 启动序列逐字文本(晶钻超算 + 浮尘) */
|
||||
const BOOT_LINES = [
|
||||
'ICD-0 // 晶钻超算 演算集群',
|
||||
'> 扫描平行宇宙世界线 <b>...</b>',
|
||||
'> 发现 11 条世界线 · <b>5</b> 条已点亮',
|
||||
'> 浮尘机器人布点完成(肉眼不可见)',
|
||||
'> 权限核验:金钻 · 主宇宙',
|
||||
'ACCESS GRANTED <span class="ok">✓</span>'
|
||||
];
|
||||
|
||||
/* ---------- 2. 全局 Ticker(单一 rAF,隐藏页暂停) ---------- */
|
||||
const Ticker = (function(){
|
||||
const subs = new Set();
|
||||
@@ -3588,7 +3578,7 @@ function mark(no) { document.querySelectorAll('#uniList .ucell,#uSlots button').
|
||||
let api = null, loading = null, pending = null;
|
||||
function load() {
|
||||
if (loading) return loading;
|
||||
loading = import('./assets/universe/galaxy.js?v=2').then(({ mountGalaxy }) => {
|
||||
loading = import('./assets/universe/galaxy.js?v=3').then(({ mountGalaxy }) => {
|
||||
api = mountGalaxy({ stage, canvas: $('uGl'), labels: $('uLabels'), panel: $('uPanel'), back: $('uBack'), hud: $('uHud'),
|
||||
// 选中时星球让位:桌面往左挪给档案卡,手机往上挪(档案卡是窗里的底部抽屉)
|
||||
layout: () => mob() ? { x: 0, y: 0.26 } : { x: 0.17, y: 0 },
|
||||
|
||||
+4
-3
@@ -103,7 +103,8 @@
|
||||
- **星系图排布** `layout.js`:新点亮的世界线自动排到中圈不挤的位置,补给线接到附近更靠里的星(不穿星);空槽按编号固定在外圈;**新加一条,已有的星和线都不动**。
|
||||
- **星球预设**从 7 种加到 18 种:类地(卡通地球)/ 海洋 / 丛林 / 荒漠 / 冻原 / 熔岩 / 毒雾 / 荒芜岩球 / 冰巨星 / 带环巨星(光环只有这个预设才有)。
|
||||
- 星图名牌 / 档案卡的文字一律转义(内容来自后台,不能当 HTML 拼)。
|
||||
- 新增 `tests/内容后台测试.py`(75 条);端到端浏览器流程 36 条(第 8 节)。
|
||||
- 新增 `tests/内容后台测试.py`(78 条);端到端浏览器流程 36 条(第 8 节)。
|
||||
- 推送后全量细审又修了:部署漏配(没设 `YS_PORTAL_DIR` / 缺 `content/site.json`)时内容后台拒绝工作,不会建空的第一版、一发布清空网站;同时最多 2 个 scrypt 在算(内存上限 256M);登录冷却记录定期清理;发布冲突给「丢掉我的草稿 / 用我的覆盖」二选一(原来会卡死在冲突里);草稿没存上、还有图在上传时不让发布;价格 / 付款文件只在这次真改了才写(不覆盖 `admin.py price` 的改动);排位在世界线很多时分档放宽、40 条也不重叠;删掉门户里旧启动仪式留下的死数据。
|
||||
|
||||
---
|
||||
|
||||
@@ -151,7 +152,7 @@
|
||||
| 前端 | 门户的 `#rack` / `#bay` DOM 与 `window.__icd.open/close/flip/tray` 调试钩子删了;新增 `window.__jzUniverse.show()/fly(no)` | 只有页面自己和自动化脚本 |
|
||||
| **新增接口** | `/api/cms/*`(登录 / 内容 / 草稿 / 发布 / 回滚 / 传图 / 预览),见 `cms.py` 开头;nginx 要加一节(`deploy/nginx-片段.md` ④) | 只有内容后台页面 |
|
||||
| **数据格式** | 库里新增 `cms_users` / `cms_sessions` / `cms_draft` / `cms_versions` / `cms_audit` 五张表(启动时自动建);新增内容文件 `portal/content/site.{json,js}`、`order/content/order.{json,js}`;画展上传的图在 `portal/uploads/` | 服务器、门户、下单页 |
|
||||
| 文件被谁写 | `prices.json` / `payinfo.json` 现在由内容后台发布时写(**格式不变**,别的字段原样保留) | 服务器 |
|
||||
| 文件被谁写 | `prices.json` / `payinfo.json` 现在也由内容后台发布时写(**格式不变**,别的字段原样保留;只有这次发布真改了价格 / 付款才写)。`admin.py price` 还能用,但建议统一在后台改 | 服务器 |
|
||||
| 前端 | 门户读 `window.JZ_CONTENT`、下单页读 `window.JZ_ORDER`(读不到用内置兜底);下单页 `TEMPLATES` 拆成 `TEMPLATES_ALL`(全部,用于显示老订单)和 `TEMPLATES`(上架的) | 页面自己 |
|
||||
|
||||
**没变**:所有买家接口、渲染机接口的路径和字段;本机开单的本机接口。
|
||||
@@ -381,7 +382,7 @@ python3 admin.py sweep # 清过期成品 + 核销(建议每天
|
||||
| 本机开单 | 假本机服务(模拟渲染)+ headless 浏览器走完整流程 | 无报错、无横滚 |
|
||||
| 门户 | headless 浏览器 1366 / 390:六个板块都切一遍;宇宙:星图就绪、点卡片飞过去出档案、`#0002` 深链、全屏开关、手机上拖星图页面不滚;首页不下载 three.js | 全过;除星系图板块外,其余板块和改动前**逐像素一致** |
|
||||
| 下单页 | 打开截图 | 正常(本轮没改) |
|
||||
| **内容后台(后端)** | `python3 backend/backend-site/tests/内容后台测试.py <server.py 所在目录> <仓库根目录>` | 75 / 75:初始账号与强制改密(改密前 11 个接口全 403)、库里无明文、Cookie 属性、https / CSRF / 跨站来源 / 爆破冷却(按 IP 5 次、按账号合计 20 次)、内容校验、XSS 转义、发布写文件、冲突 409、回滚一致、预览要登录、传图核验与去元数据、会话撤销与过期、命令行、三进程同时首启只建一个账号 |
|
||||
| **内容后台(后端)** | `python3 backend/backend-site/tests/内容后台测试.py <server.py 所在目录> <仓库根目录>` | 78 / 78:部署漏配时拒绝工作、后台发布不覆盖命令行改过的价格、初始账号与强制改密(改密前 11 个接口全 403)、库里无明文、Cookie 属性、https / CSRF / 跨站来源 / 爆破冷却(按 IP 5 次、按账号合计 20 次)、内容校验、XSS 转义、发布写文件、冲突 409、回滚一致、预览要登录、传图核验与去元数据、会话撤销与过期、命令行、三进程同时首启只建一个账号 |
|
||||
| **内容后台(端到端)** | 迷你反代模拟 nginx + 真服务器 + headless 浏览器 1366 / 390 | 36 / 36:门户入口 → 登录 → 强制改密 → 改文案 / 传图 / 点亮新地球 / 加入口 / 下架模板 / 加档位 → 预览(未登录看不到草稿)→ 发布 → 门户 / 星系图 / 下单页都变了 → 回滚复原 → 退出;无新增报错(只有交付副本本来就缺的 `view_stats.json` 和模板缩略图 404) |
|
||||
|
||||
后端测试数据全是测试脚本现编的,建在系统临时目录。⚠️ 交付副本里三个 URL 格式串被脱敏成 `http<WIN-PATH>`,要起服务器的测试得先在**测试副本**里换成能格式化的占位(这三处分别吃 1 / 2 / 0 个参数);线上原版直接跑。
|
||||
|
||||
@@ -169,4 +169,8 @@
|
||||
| 下单页「页面上的提示文字」 | 只做了页头那句话 + 公告条 | 其它提示散在下单页逻辑里,动它风险大;以后要加再逐个接 |
|
||||
| 署名卡片是否锁定(待定) | 没锁,店主可以改 | 没定之前按「可以改」 |
|
||||
| 新点亮的世界线放哪 | 自动排位(`portal/assets/universe/layout.js`):中圈不挤的位置,补给线接附近的星,已有的都不动 | 店主要求「新星球的位置和连线要好看、不打架」 |
|
||||
| 「两个人同时编辑:提示先看对方改了什么再合并」 | 发布时底稿过期 → 409,弹窗二选一:丢掉我的草稿 / 确认后用我的草稿覆盖发布(覆盖前可先看发布记录) | 不做逐字段合并,简单可控 |
|
||||
| (设计没写) | 部署漏配(没设 `YS_PORTAL_DIR` / `YS_ORDER_DIR`,或门户目录里没有 `content/site.json`)时内容后台**拒绝工作**,不建第一版、不写任何文件 | 否则会从空骨架开始,店主一发布就把网站内容清空 |
|
||||
| (设计没写) | 价格档位 / 付款方式只有这次发布真改了才写回 `prices.json` / `payinfo.json` | 不覆盖有人用 `admin.py price` 在命令行改过的价格 |
|
||||
| (设计没写) | 同时最多 2 个密码哈希在算 | 一次 scrypt 要 16MB 内存,服务进程上限 256M |
|
||||
|
||||
|
||||
Reference in New Issue
Block a user