Download tasks/asana/environment/reference/clone/app.py from TIGER-Lab/WebsiteBench: direct link, hf CLI and curl.
- Browser
- Download file 5.73 kB
-
https://huggingface.co/datasets/TIGER-Lab/WebsiteBench/resolve/main/tasks/asana/environment/reference/clone/app.py
- Command line
-
hf download hf://datasets/TIGER-Lab/WebsiteBench/tasks/asana/environment/reference/clone/app.py
-
curl -L -o app.py https://huggingface.co/datasets/TIGER-Lab/WebsiteBench/resolve/main/tasks/asana/environment/reference/clone/app.py
5.73 kB
| """Asana offline clone — WebsiteBench candidate application. | |
| Route hub only; business logic lives in ``asana_app``. All state is local: | |
| site-bound SQLite through the generated ``websitebench.site_backend`` seam and | |
| LocalAuthStore. No runtime request leaves the local origin. | |
| """ | |
| import json | |
| import os | |
| from pathlib import Path | |
| from fastapi import FastAPI, Request | |
| from fastapi.responses import HTMLResponse, JSONResponse, RedirectResponse | |
| from fastapi.staticfiles import StaticFiles | |
| from asana_app import pages | |
| from asana_app.api import _cookie_name, public_project_snapshot, router as api_router | |
| from asana_app.services import SERVICES | |
| SITE_ID = "asana" | |
| DISPLAY_NAME = "Asana" | |
| CLONE_ROOT = Path(__file__).resolve().parent | |
| app = FastAPI(title=DISPLAY_NAME, docs_url=None, redoc_url=None, openapi_url=None) | |
| app.include_router(api_router) | |
| app.mount("/static", StaticFiles(directory=CLONE_ROOT / "static"), name="static") | |
| async def validate_api_json(request: Request, call_next): | |
| """Reject malformed or non-object JSON before business handlers run.""" | |
| content_type = request.headers.get("content-type", "").lower() | |
| if (request.url.path.startswith("/api/") and | |
| request.method in {"POST", "PUT", "PATCH"} and | |
| content_type.startswith("application/json")): | |
| try: | |
| body = await request.json() | |
| except (json.JSONDecodeError, UnicodeDecodeError): | |
| return JSONResponse( | |
| {"error": {"code": "invalid-json", | |
| "message": "Request body must be valid JSON."}}, | |
| status_code=400, | |
| ) | |
| if not isinstance(body, dict): | |
| return JSONResponse( | |
| {"error": {"code": "invalid-json", | |
| "message": "Request body must be a JSON object."}}, | |
| status_code=400, | |
| ) | |
| return await call_next(request) | |
| def healthz() -> JSONResponse: | |
| return JSONResponse( | |
| {"ok": True, "site_id": SITE_ID}, | |
| headers={ | |
| "X-WebsiteBench-Container-Build-ID": os.environ.get( | |
| "DEPLOYMENT_BUILD_ID", os.environ.get("SOURCE_REF", "") | |
| ) | |
| }, | |
| ) | |
| _MARKETING = { | |
| "/": pages.home_page, | |
| "/pricing": pages.pricing_page, | |
| "/product": pages.product_page, | |
| "/resources": pages.resources_page, | |
| "/templates": pages.templates_page, | |
| } | |
| def _register_marketing(path: str, render) -> None: | |
| def marketing_page() -> str: # pragma: no cover - thin wrapper | |
| return render() | |
| for _path, _render in _MARKETING.items(): | |
| _register_marketing(_path, _render) | |
| def _register_nav_detail(path: str) -> None: | |
| def nav_detail_page() -> str: # pragma: no cover - thin wrapper | |
| return pages.nav_detail_page(path) | |
| for _path in pages.NAV_DETAIL_PAGES: | |
| _register_nav_detail(_path) | |
| def template_category(category: str) -> str: | |
| """Keep every observed public template-card destination locally reachable.""" | |
| return pages.templates_page() | |
| def resource_category(category: str) -> str: | |
| """Keep every observed resource-card destination locally reachable.""" | |
| return pages.resources_page() | |
| def public_demo() -> str: | |
| return pages.resources_page() | |
| def public_terms(document: str) -> str: | |
| return pages.templates_page() | |
| def solutions() -> str: | |
| return pages.solutions_page() | |
| def _authenticated(request: Request) -> bool: | |
| token = request.cookies.get(_cookie_name(request, SERVICES)) | |
| session = SERVICES.auth.resolve_session(token) | |
| return bool(session and session.get("authenticated")) | |
| def login(request: Request): | |
| if _authenticated(request): | |
| return RedirectResponse("/app/home", status_code=302) | |
| return pages.login_page() | |
| def create_account(request: Request, email: str = ""): | |
| if _authenticated(request): | |
| return RedirectResponse("/app/home", status_code=302) | |
| return pages.signup_page(email) | |
| def forgot_password() -> str: | |
| return pages.forgot_page() | |
| # Dash-free aliases for tooling that cannot pass "-/" routes as arguments | |
| # (OpenCLI adapters treat a leading dash as an option). Same content. | |
| def login_alias(request: Request): | |
| return login(request) | |
| def forgot_alias() -> str: | |
| return pages.forgot_page() | |
| def shared_project(project_id: str): | |
| """Anonymous read-only surface enabled only by a project's public-link mode.""" | |
| with SERVICES.auth.connect() as connection: | |
| snapshot = public_project_snapshot(connection, project_id) | |
| if snapshot is None: | |
| return HTMLResponse(pages.not_found_page(), status_code=404) | |
| return pages.shared_project_page(snapshot) | |
| def app_pages(request: Request, rest: str = ""): | |
| if not _authenticated(request): | |
| target = request.url.path | |
| return RedirectResponse(f"/-/login?u={target}", status_code=302) | |
| return pages.app_shell() | |