内容后台:能原样接住线上真实画展(文件名带空格、本站 mp4 视频 + 网页版、作品外链、离线缩略图索引、世界线主色),不再在校验时丢数据
- 站内路径允许普通空格,多认 exhibition_web/、thumbs/;制表符/换行/引号/尖括号/?#/.. 照旧拒 - 视频:本站 .mp4/.webm 不用填 B 站链接;web / link / links 保留 - 离线媒体索引 media 保留并写进 site.js(以前发布一次就丢缩略图,画展会直接拉几百张原图) - 世界线 tone/sector/media 保留并带进星系图数据 - 后台:本站视频的预览图走缩略图索引;编辑本站视频不再强制 B 站链接 - 测试 +8(86 条全过) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -50,7 +50,8 @@ SLUG = re.compile(r"^[a-z0-9][a-z0-9_-]{0,31}$")
|
||||
DATE = re.compile(r"^\d{4}-\d{2}-\d{2}$")
|
||||
HEX = re.compile(r"^#[0-9A-Fa-f]{6}$")
|
||||
# 站内相对路径:只许 exhibition/ 和 uploads/ 下面,不许 .. / 协议 / 开头斜杠
|
||||
PATH_RE = re.compile(r"^(exhibition|uploads)/[^\s<>\"'\\?#]{1,240}$")
|
||||
# 文件名里允许普通空格(真实作品名大量带空格,如「明介 (1).webp」);制表符 / 换行、引号、尖括号、? # \ 一律不收
|
||||
PATH_RE = re.compile(r"^(exhibition|exhibition_web|uploads|thumbs)/[^\t\n\r\f\v<>\"'\\?#]{1,240}$")
|
||||
BVID = re.compile(r"^BV[0-9A-Za-z]{10}$")
|
||||
|
||||
_SCHEMA = """
|
||||
@@ -158,7 +159,7 @@ def _path(v, where, allow_empty=True):
|
||||
return ""
|
||||
raise Bad("%s 不能空" % where)
|
||||
if not PATH_RE.match(v) or ".." in v or "//" in v:
|
||||
raise Bad("%s 不是站内图片路径(只认 exhibition/… 或 uploads/…)" % where)
|
||||
raise Bad("%s 不是站内文件路径(只认 exhibition/…、exhibition_web/…、uploads/…、thumbs/…)" % where)
|
||||
return v
|
||||
|
||||
|
||||
@@ -300,19 +301,42 @@ def normalize_site(d):
|
||||
m = re.search(r"(BV[0-9A-Za-z]{10})", e["url"])
|
||||
if m and "bvid" not in e:
|
||||
e["bvid"] = m.group(1)
|
||||
if not e["url"] and "bvid" not in e:
|
||||
raise Bad("%s 是视频,要填 B 站链接" % w)
|
||||
if g.get("web"):
|
||||
e["web"] = _path(g["web"], w + " 的网页版视频")
|
||||
local = bool(re.search(r"\.(mp4|webm)$", e.get("src", ""), re.I))
|
||||
if not e["url"] and "bvid" not in e and not local:
|
||||
raise Bad("%s 是视频,要填 B 站链接(或用本站的 .mp4 文件)" % w)
|
||||
elif not e.get("src") and t != "wall":
|
||||
raise Bad("%s 还没有图片" % w)
|
||||
if g.get("frames"):
|
||||
e["frames"] = [{"src": _path((f or {}).get("src"), w + " 的帧", allow_empty=False),
|
||||
"label": _s((f or {}).get("label"), 20, w + " 的帧标签")}
|
||||
for f in _list(g["frames"], w + " 的帧", 60)]
|
||||
if g.get("link"):
|
||||
e["link"] = _url(g["link"], w + " 的外链")
|
||||
if g.get("links"):
|
||||
e["links"] = [x for x in (_url(u, w + " 的外链") for u in _list(g["links"], w + " 的外链", 8)) if x]
|
||||
if t == "wall" and not e.get("frames") and not e.get("src"):
|
||||
raise Bad("%s 是动态壁纸,至少要有一帧" % w)
|
||||
gal.append(e)
|
||||
out["gallery"] = gal
|
||||
|
||||
media = {}
|
||||
md = d.get("media") if isinstance(d.get("media"), dict) else {}
|
||||
if len(md) > 5000:
|
||||
raise Bad("媒体索引太大了(超过 5000 条)")
|
||||
for k, v in md.items():
|
||||
v = v if isinstance(v, dict) else {}
|
||||
m = {}
|
||||
if v.get("t"):
|
||||
m["t"] = _path(v["t"], "媒体索引(%s)的缩略图" % str(k)[:40])
|
||||
if v.get("r") not in (None, ""):
|
||||
m["r"] = _num(v["r"], 0.05, 20, "媒体索引(%s)的宽高比" % str(k)[:40])
|
||||
if m:
|
||||
media[_path(k, "媒体索引的文件")] = m
|
||||
if media:
|
||||
out["media"] = media
|
||||
|
||||
apps = []
|
||||
for i, a in enumerate(_list(d.get("apps"), "工具与开源", 100)):
|
||||
a = a if isinstance(a, dict) else {}
|
||||
@@ -371,6 +395,14 @@ def normalize_site(d):
|
||||
items.append({"no": no, "name": _s(u.get("name"), 12, w + " 的名字", required=True), "kind": kind,
|
||||
"tag": _s(u.get("tag"), 24, w + " 的一句话"), "desc": _s(u.get("desc"), 600, w + " 的简介"),
|
||||
"tags": [t for t in tags if t], "look": _look(u.get("look"), w)})
|
||||
tone = str(u.get("tone") or "").strip() # 卡片 / 首页小机架上的主色(老数据带的,保留)
|
||||
if tone:
|
||||
if not HEX.match(tone):
|
||||
raise Bad("%s 的主色要写成 #RRGGBB" % w)
|
||||
items[-1]["tone"] = tone
|
||||
for k, lim, nm in (("sector", 12, "扇区"), ("media", 24, "介质")):
|
||||
if u.get(k):
|
||||
items[-1][k] = _s(u.get(k), lim, w + " 的" + nm)
|
||||
items.sort(key=lambda x: x["no"])
|
||||
out["universe"] = {"items": items, "empty": _num(un.get("empty", 6), 0, 20, "空槽数", integer=True)}
|
||||
return out
|
||||
@@ -480,13 +512,14 @@ def site_payload(site):
|
||||
items = u.get("items") or []
|
||||
nos = [int(x["no"]) for x in items]
|
||||
nxt = (max(nos) + 1) if nos else 0
|
||||
UNIVERSES = [{"no": x["no"], "name": x["name"], "kind": x["kind"], "tag": x["tag"], "desc": x["desc"], "tags": x["tags"]} for x in items]
|
||||
UNIVERSES = [dict({"no": x["no"], "name": x["name"], "kind": x["kind"], "tag": x["tag"], "desc": x["desc"], "tags": x["tags"]},
|
||||
**{k: x[k] for k in ("tone", "sector", "media") if x.get(k)}) for x in items]
|
||||
UNIVERSES += [{"no": "%04d" % (nxt + k), "empty": True} for k in range(int(u.get("empty") or 0))]
|
||||
LOOKS = {x["no"]: x["look"] for x in items}
|
||||
media = {}
|
||||
media = {k: dict(v) for k, v in (site.get("media") or {}).items()} # 离线索引打底,作品自带的宽高比 / 缩略图覆盖上去
|
||||
for g in site.get("gallery") or []:
|
||||
if g.get("src") and (g.get("thumb") or g.get("r")):
|
||||
m = {}
|
||||
m = media.get(g["src"], {})
|
||||
if g.get("r"):
|
||||
m["r"] = g["r"]
|
||||
if g.get("thumb"):
|
||||
|
||||
@@ -187,6 +187,43 @@ bad = json.loads(json.dumps(doc)); bad["site"]["hero"]["tagline"] = "长" * 200
|
||||
st, j = a.req("draft", {"doc": bad, "base": 1})
|
||||
check("校验:超长 → 拒,并说清多长", st == 400 and "最多 160" in j.get("error", ""), j)
|
||||
|
||||
# 真实画展的样子(2026-10-06 线上恢复时踩到):文件名带空格、本站 mp4 视频 + 网页版副本、作品外链、离线缩略图索引、世界线主色
|
||||
real = json.loads(json.dumps(doc))
|
||||
real["site"]["gallery"] = [
|
||||
{"id": "r1", "type": "image", "date": "2024-10-20", "title": "定制 (1)", "owner": "own", "src": "exhibition/渲染与动画/20241020/星野 渲染-定制 (1).webp", "r": 1.7778,
|
||||
"links": ["https://example.com/workshop/1", "https://example.com/cgmodel/2"], "link": "https://example.com/a"},
|
||||
{"id": "r2", "type": "video", "date": "2022-10-23", "title": "本站视频", "owner": "gift", "src": "exhibition/他人赠或合照带我/20221023/忘了谁做的了 (1).mp4",
|
||||
"web": "exhibition_web/他人赠或合照带我/20221023/忘了谁做的了 (1).mp4", "r": 2.3636}]
|
||||
real["site"]["media"] = {"exhibition/渲染与动画/20241020/星野 渲染-定制 (1).webp": {"t": "thumbs/abc123.png", "r": 1.7778},
|
||||
"exhibition/他人赠或合照带我/20221023/忘了谁做的了 (1).mp4": {"t": "thumbs/def456.png", "r": 2.3636}}
|
||||
real["site"]["universe"]["items"][0]["tone"] = "#e6e1d6"
|
||||
tk = tuple(t["k"] for t in doc["order"]["templates"])
|
||||
try:
|
||||
n = S.cms.normalize(real, tk)
|
||||
ok = (n["site"]["gallery"][0]["src"] == real["site"]["gallery"][0]["src"] and n["site"]["gallery"][0]["links"] == real["site"]["gallery"][0]["links"]
|
||||
and n["site"]["gallery"][0]["link"] == "https://example.com/a" and n["site"]["gallery"][1]["web"] == real["site"]["gallery"][1]["web"]
|
||||
and n["site"]["media"] == real["site"]["media"] and n["site"]["universe"]["items"][0]["tone"] == "#e6e1d6")
|
||||
pay = S.cms.site_payload(n["site"])
|
||||
check("真实画展:带空格的文件名、本站 mp4 视频(不填 B 站链接)、网页版副本、外链、缩略图索引、世界线主色全部原样保留",
|
||||
ok and S.cms.normalize(n, tk) == n, n["site"]["gallery"])
|
||||
check("真实画展:网站内容文件里缩略图索引还在(不然画展会直接拉几百张原图)",
|
||||
pay["media"]["exhibition/他人赠或合照带我/20221023/忘了谁做的了 (1).mp4"].get("t") == "thumbs/def456.png" and pay["universe"]["UNIVERSES"][0].get("tone") == "#e6e1d6", pay["media"])
|
||||
except S.cms.Bad as e:
|
||||
check("真实画展:带空格的文件名、本站 mp4 视频、网页版副本、外链、缩略图索引全部原样保留", False, e)
|
||||
for badp in ["exhibition/a\tb.webp", "exhibition/a\"b.webp", "exhibition/a?b.webp", "thumbs/../x.png", "other/a.webp"]:
|
||||
bad = json.loads(json.dumps(real)); bad["site"]["gallery"][0]["src"] = badp
|
||||
try:
|
||||
S.cms.normalize(bad, tk); rej = False
|
||||
except S.cms.Bad:
|
||||
rej = True
|
||||
check("校验:站内路径 %r → 拒" % badp, rej)
|
||||
bad = json.loads(json.dumps(real)); bad["site"]["gallery"][1]["src"] = "exhibition/x/a.webp"
|
||||
try:
|
||||
S.cms.normalize(bad, tk); rej = False
|
||||
except S.cms.Bad as e:
|
||||
rej = "B 站" in str(e)
|
||||
check("校验:视频既没有 B 站链接、也不是本站 mp4 → 拒", rej)
|
||||
|
||||
XSS = '</script><script>alert(1)</script><img src=x onerror=alert(2)>'
|
||||
good = json.loads(json.dumps(doc))
|
||||
good["site"]["hero"]["tagline"] = "首页改一句 " + XSS[:40]
|
||||
|
||||
Reference in New Issue
Block a user