INNER CODE UNIT · Python
_workspace_url
iLearn-Lab/NovelClaw · apps/auth-portal/local_web_portal/app/main.py:89
def _workspace_url(request: Request, configured_url: str, port: str, path: str) -> str:
configured = (configured_url or "").strip()
if configured:
return configured
safe_path = path if path.startswith("/") else f"/{path}"
return urlunsplit((request.url.scheme, f"{_external_host(request)}:{port}", safe_path, "", ""))
def _ensure_preview_user(request: Request, db: Session) -> User:
uid = request.session.get("uid")
if uid:
try:
user_id = int(uid)
except (TypeError, ValueError):
request.session.pop("uid", None)
else:
existing = db.get(User, user_id)
if existing: