Spaces:
Sleeping

zyntalic-verse / server.py
kugguk's picture
Publish the standalone Verse entrance, stage, and sample archive
9d97643 verified
Raw History Blame Contribute Delete
1.72 kB
"""Host the Verse entrance, stage, engine, and bundled sample archive."""
from pathlib import Path
from shutil import copyfileobj
from tempfile import TemporaryDirectory
from zipfile import ZipFile
import uvicorn
from fastapi import FastAPI
from fastapi.staticfiles import StaticFiles
ROOT = Path(__file__).resolve().parent
FILES = {
"index.html",
"launcher-art.webp",
"verse/index.html",
"verse/verse-world.js",
"verse/kengatsumoto-close.webp",
"verse/landscape.webp",
"verse/zebracorn-mark.svg",
"verse/engine/pyodide-lock.json",
"verse/engine/pyodide.asm.js",
"verse/engine/pyodide.asm.wasm",
"verse/engine/pyodide.js",
"verse/engine/stdlib-zip.wasm",
"verse/engine/zyntalic-zip.wasm",
"arch/tracks/rules/index.json",
"arch/tracks/rules/state.json",
"arch/tracks/rules/days/2026-11-19-run0001.txt",
"arch/tracks/rules/days/2026-11-19-run0002.txt",
"arch/tracks/rules/days/2026-11-19-run0003.txt",
}
bundle_storage = TemporaryDirectory(prefix="zyntalic-verse-")
public_dir = Path(bundle_storage.name)
with ZipFile(ROOT / "verse-bundle.zip") as bundle:
if sorted(bundle.namelist()) != sorted(FILES):
raise ValueError("Unexpected files in the Verse bundle")
for name in FILES:
path = public_dir / name
path.parent.mkdir(parents=True, exist_ok=True)
with bundle.open(name) as origin, path.open("wb") as target:
copyfileobj(origin, target)
app = FastAPI(title="Zyntalic Dual · The Verse", docs_url=None, redoc_url=None, openapi_url=None)
app.mount("/", StaticFiles(directory=public_dir, html=True), name="verse")
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=7860)