Source identity
| Field | Recorded value |
|---|---|
| Source type | archive member |
| Original record | 05b_public_mirror.py |
| Date | Not specified in source |
| Path or archive member | archives/libsrc-1c3f88063121/NETLIFY_AI_RECOVERY_2026-10-14_21-10-49/scripts/05b_public_mirror.py |
| Original SHA-256 | e6eda5b89e819bbb53cfe030e8b9b6ed39670e49464d003ff221cd3babb8369c |
| Reading-copy SHA-256 | e6eda5b89e819bbb53cfe030e8b9b6ed39670e49464d003ff221cd3babb8369c |
| Archive source | {"sourceId": "libsrc-1c3f88063121", "member": "NETLIFY_AI_RECOVERY_2026-10-14_21-10-49/scripts/05b_public_mirror.py"} |
Recovered source transcript
Download complete source text ↓35 lines · 2.3 KB
"""Save publicly rendered pages for server rendered sites whose HTML is not in the deployed files.
Labeled PUBLIC_MIRROR_PARTIAL: this is what visitors receive today, not the original source or deployed files."""
import glob, json, os, sys, zipfile
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from nlr_common import ROOT, log, now, request, safe_name, sha256_file, write_bytes_atomic, write_json
TARGETS = {"taupe-belekoy-cda1f9": ["/", "/story", "/lab", "/faq", "/donate", "/chapter/2", "/megammind"]}
for name, routes in TARGETS.items():
d = glob.glob(os.path.join(ROOT, "sites", f"*__{name}__*"))[0]
meta = json.load(open(os.path.join(d, "metadata", "site.json")))
base = meta["ssl_url"].rstrip("/")
out = os.path.join(d, "public_mirror")
started, recs = now(), []
for r in routes:
st, h, body, final = request(base + r, auth=False)
local = ("root" if r == "/" else r.strip("/")) + "/index.html"
rec = {"route": r, "url": base + r, "http_status": st, "final_url": final,
"content_type": h.get("Content-Type") if h else None, "bytes": len(body), "local_path": local}
if st == 200:
write_bytes_atomic(os.path.join(out, local), body)
rec["sha256"] = sha256_file(os.path.join(out, local))
recs.append(rec)
man = {"label": "PUBLIC_MIRROR_PARTIAL", "site": name, "started": started, "finished": now(),
"note": "Pages rendered by the live server function at retrieval time. Not original source, not the deployed function, and not guaranteed complete (routes discovered from route chunk names).",
"pages": recs}
write_json(os.path.join(out, "PUBLIC_MIRROR_MANIFEST.json"), man)
zp = os.path.join(ROOT, "zips", f"{safe_name(name)}__{meta['id']}__PUBLIC_MIRROR_PARTIAL__{started.replace(':','-')}.zip")
with zipfile.ZipFile(zp + ".part", "w", zipfile.ZIP_DEFLATED, allowZip64=True) as z:
for rec in recs:
if rec["http_status"] == 200:
z.write(os.path.join(out, rec["local_path"]), rec["local_path"])
z.write(os.path.join(out, "PUBLIC_MIRROR_MANIFEST.json"), "PUBLIC_MIRROR_MANIFEST.json")
os.replace(zp + ".part", zp)
log(f"public mirror {name}: {sum(1 for r in recs if r['http_status']==200)}/{len(recs)} pages -> {os.path.basename(zp)}")