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