Download app/routers/internal.py from Modulo-6/api: direct link, hf CLI and curl.
- Browser
- Download file 1.75 kB
-
https://huggingface.co/spaces/Modulo-6/api/resolve/main/app/routers/internal.py
- Command line
-
hf download hf://spaces/Modulo-6/api/app/routers/internal.py
-
curl -L -o internal.py https://huggingface.co/spaces/Modulo-6/api/resolve/main/app/routers/internal.py
1.75 kB
| """ | |
| Endpoints internos: no hay un usuario humano detrás de estas llamadas, así que no usan | |
| `get_current_user`/JWT de sesión — se protegen con un secreto compartido simple | |
| (`settings.internal_tick_secret`). | |
| `POST /internal/reservas/tick` avanza automáticamente el estado de las reservas de | |
| quirófano según su horario (`RESERVADA → EN_CURSO → COMPLETADA`). Está pensado para que | |
| lo dispare un cron externo (GitHub Actions, cron-job.org, etc.), no un scheduler en | |
| memoria: el deploy de M6 (HF Spaces, tier gratuito) duerme el contenedor tras | |
| inactividad, y un loop interno se congelaría con él. La propia request del cron despierta | |
| el Space si estaba dormido. Ver `M6_DISEÑO.md` §5.4. | |
| """ | |
| import secrets | |
| from fastapi import APIRouter, Depends, Header, HTTPException, status | |
| from supabase import Client | |
| from app.config import settings | |
| from app.dependencies import get_db | |
| from app.services import cama_service | |
| router = APIRouter(prefix="/internal", tags=["Internal"]) | |
| _ERROR_401 = {"codigo": "NO_AUTENTICADO", "mensaje": "Token interno ausente o inválido"} | |
| def _verificar_token_interno(x_internal_token: str = Header(...)) -> None: | |
| if not settings.internal_tick_secret or not secrets.compare_digest( | |
| x_internal_token, settings.internal_tick_secret | |
| ): | |
| raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail=_ERROR_401) | |
| def tick_reservas( | |
| db: Client = Depends(get_db), | |
| _: None = Depends(_verificar_token_interno), | |
| ): | |
| return cama_service.procesar_transiciones_automaticas(db) | |