فهرست منبع

修复旧站资源清单解析并支持资源阶段续跑

过滤 mailto、tel、javascript 和 data 伪链接,避免旧文章长文本被当作超长文件路径;对文件系统长度异常和不存在路径做安全判定。\n\n新增 continue-assets 后台模式和本地入口,可复用已完成的影子库及已复制资源,只重跑资源整理、双节点校验和后续验收。\n\nValidation:\n- python3 -m py_compile local-run/bin/legacy-sites-job.py\n- bash -n local-run/bin/legacy-sites-to-hxcs.sh\n- 影子库合并及 HXCS 新站保护指纹已通过\n- 资源复制续跑中,已暂存约 45GB、175225 个文件
非繁 3 هفته پیش
والد
کامیت
ecbe9bbc3f
2فایلهای تغییر یافته به همراه28 افزوده شده و 5 حذف شده
  1. 22 4
      local-run/bin/legacy-sites-job.py
  2. 6 1
      local-run/bin/legacy-sites-to-hxcs.sh

+ 22 - 4
local-run/bin/legacy-sites-job.py

@@ -682,6 +682,8 @@ def extract_asset_refs(staging: Path) -> set[str]:
         base = rel.rsplit("/", 1)[0]
         for match in list(attr.finditer(text)) + list(css.finditer(text)):
             value = match.group(1).strip()
+            if value.lower().startswith(("mailto:", "tel:", "javascript:", "data:", "#")):
+                continue
             parsed = urlparse(value)
             if parsed.scheme in ("http", "https") or value.startswith("//"):
                 normalized = normalize_path(value)
@@ -694,6 +696,16 @@ def extract_asset_refs(staging: Path) -> set[str]:
     return paths
 
 
+def staged_path_exists(path: str) -> bool:
+    relative = path.lstrip("/")
+    if len(relative) > 3900 or any(len(part) > 255 for part in relative.split("/")):
+        return False
+    try:
+        return (STAGE_WEBAPP / relative).exists()
+    except OSError:
+        return False
+
+
 def tar_paths_from_source(paths: set[str], extraction_root: Path) -> None:
     extraction_root.mkdir(parents=True, exist_ok=True)
     file_list = "\n".join(p.lstrip("/") for p in quote_paths(paths)) + "\n"
@@ -755,11 +767,11 @@ def stage_assets() -> None:
     ASSET_LIST.write_text("\n".join(quote_paths(direct)) + "\n", encoding="utf-8")
     tar_paths_from_source(direct, STAGE_WEBAPP)
     derived = extract_asset_refs(STAGE_WEBAPP)
-    missing = sorted(p for p in derived if not (STAGE_WEBAPP / p.lstrip("/")).exists())
-    remaining = {p for p in derived if (STAGE_WEBAPP / p.lstrip("/")).exists() is False}
+    missing = sorted(p for p in derived if not staged_path_exists(p))
+    remaining = set(missing)
     if remaining:
         tar_paths_from_source(remaining, STAGE_WEBAPP)
-    missing = sorted(p for p in derived if not (STAGE_WEBAPP / p.lstrip("/")).exists())
+    missing = sorted(p for p in derived if not staged_path_exists(p))
     ASSET_MISSING.write_text("\n".join(missing) + "\n", encoding="utf-8")
     local_hash = subprocess.run(
         f"cd {shlex.quote(str(STAGE_WEBAPP))} && find . -type f -print0 | sort -z | xargs -0 -r sha256sum | sha256sum",
@@ -1013,11 +1025,17 @@ def run_mode(mode: str) -> None:
             update_status(stage="verify")
             verify()
             update_status(stage="complete", state="complete", finished_at=now())
+        elif mode == "continue-assets":
+            update_status(stage="stage-assets", continued_at=now())
+            stage_assets()
+            update_status(stage="verify")
+            verify()
+            update_status(stage="complete", state="complete", finished_at=now())
         elif mode == "refresh-delta":
             raise JobError("refresh-delta 需要在正式切换前的停写窗口另行授权后实现/执行")
         else:
             raise JobError(f"未知模式:{mode}")
-        if mode not in {"all", "resume", "continue-merge"}:
+        if mode not in {"all", "resume", "continue-merge", "continue-assets"}:
             update_status(state="complete", stage=mode, finished_at=now())
     except Exception as exc:
         log("任务失败:" + str(exc))

+ 6 - 1
local-run/bin/legacy-sites-to-hxcs.sh

@@ -22,10 +22,11 @@ MODE="${1:-status}"
 die() { printf '失败:%s\n' "$*" >&2; exit 1; }
 usage() {
 	cat <<'EOF'
-用法:legacy-sites-to-hxcs.sh <preflight|snapshot|build-shadow|stage-assets|verify|run-detached|resume-detached|continue-detached|status|wait|refresh-delta>
+用法:legacy-sites-to-hxcs.sh <preflight|snapshot|build-shadow|stage-assets|verify|run-detached|resume-detached|continue-detached|continue-assets-detached|status|wait|refresh-delta>
   run-detached  在 10.0.42.6 脱离 SSH 会话执行完整复制流程
   resume-detached  保留旧生产快照,重新克隆影子库后断点续跑
   continue-detached  复用现有影子库,仅重新执行合并、资源和验收
+  continue-assets-detached  复用影子库和已复制资源,重新执行资源整理和验收
   status        查看后台任务状态和最后日志
   wait         等待后台任务结束(本机 VPN 中断不影响任务)
 EOF
@@ -175,6 +176,10 @@ case "${MODE}" in
 		deploy_tools
 		start_detached continue-merge
 		;;
+	continue-assets-detached)
+		deploy_tools
+		start_detached continue-assets
+		;;
 	status)
 		show_status
 		;;