Spaces:
Sleeping
Sleeping
Download app/debug.py from low-key-007/maidapp: direct link, hf CLI and curl.
- Browser
- Download file 1.88 kB
-
https://huggingface.co/spaces/low-key-007/maidapp/resolve/main/app/debug.py
- Command line
-
hf download hf://spaces/low-key-007/maidapp/app/debug.py
-
curl -L -o debug.py https://huggingface.co/spaces/low-key-007/maidapp/resolve/main/app/debug.py
1.88 kB
| import os | |
| from fastapi import APIRouter | |
| from app.config import settings | |
| from app.supabase_client import supabase_request | |
| import redis.asyncio as aioredis | |
| from fastapi import APIRouter, Depends | |
| from app.auth import get_current_user | |
| from app.supabase_client import supabase_request | |
| router = APIRouter(tags=["debug"]) | |
| async def ping(): | |
| return {"status": "ok", "app": "maidapp"} | |
| async def debug_supabase(): | |
| try: | |
| # simple SELECT 1 via PostgREST: call the "rpc" or access the version via a safe endpoint | |
| # PostgREST has no generic "select 1", but we can query one known table if present (services) | |
| resp = await supabase_request("GET", "services", params={"select": "*", "limit": 1}) | |
| return {"status": "ok", "services_sample": resp} | |
| except Exception as e: | |
| return {"status": "error", "error": str(e)} | |
| async def debug_redis(): | |
| if not settings.REDIS_URL: | |
| return {"status": "error", "error": "REDIS_URL not set"} | |
| try: | |
| r = aioredis.from_url(settings.REDIS_URL, encoding="utf-8", decode_responses=True) | |
| pong = await r.ping() | |
| return {"status": "ok", "pong": pong} | |
| except Exception as e: | |
| return {"status": "error", "error": str(e)} | |
| from fastapi import Depends | |
| from app.auth import get_current_user | |
| async def protected(current_user: dict = Depends(get_current_user)): | |
| return { | |
| "message": f"Hello {current_user['phone']}, you are a {current_user['role']}!" | |
| } | |
| async def get_my_messages(current_user: dict = Depends(get_current_user)): | |
| user_id = current_user["sub"] | |
| res = await supabase_request("GET", "messages", params={ | |
| "user_id": f"eq.{user_id}", "select": "*", "order": "created_at.desc" | |
| }) | |
| return res |