File size: 2,929 Bytes
8b73048 5b91cf1 8b73048 5b91cf1 11488bb c7632e7 8b73048 d56556d 8b73048 11488bb 8b73048 c2ff93d 93a5ed3 d78e28f 93a5ed3 d78e28f 67b82ae |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
import funciones
from io import BytesIO
from fastapi import FastAPI, Form
from fastapi import FastAPI, File, UploadFile
from fastapi.responses import StreamingResponse, JSONResponse
from fastapi import FastAPI, Depends, HTTPException, status
from fastapi.security.api_key import APIKeyHeader
API_KEY = "tu_super_secreta_clave_de_api"
api_key_header = APIKeyHeader(name="X-API-Key", auto_error=False)
async def get_api_key(api_key: str = Depends(api_key_header)):
if not api_key or api_key != API_KEY:
raise HTTPException(
status_code=status.HTTP_401_UNAUTHORIZED,
detail="Credenciales de autenticación inválidas",
)
return api_key
#Y manda ésto en los headers:
#"X-API-Key": apiKey
app = FastAPI()
# Nuevo endpoint para Health Check
@app.get("/health",
tags=["Health Check"],
description="Verifica el estado de salud de la API.",
summary="Health Check"
)
async def health_check():
"""
Este endpoint devuelve una respuesta 200 OK para indicar que la API está funcionando.
"""
return JSONResponse(content={"status": "ok"}, status_code=200)
@app.post("/echo-image/",
tags=["Health Check"],
description="Test endpoint que recibe y regresa la misma imagen, para probar envío, recepción y problemas con api o red.",
summary="Summary"
)
async def echo_image(
image: UploadFile = File(...),
#api_key: str = Depends(get_api_key)
):
if not image.content_type.startswith("image/"):
return {"error": "El archivo no es una imagen"}
contents = await image.read()
return StreamingResponse(BytesIO(contents), media_type=image.content_type)
@app.post(
"/identifica_documento/",
tags=["General"],
summary="Reconocimiento Avanzado de Documentos")
async def procesa_documento(image: UploadFile = File(...)):
if not image.content_type.startswith("image/"):
return {"error": "El archivo no es una imagen"}
return await funciones.identifica_documento(image)
#PROCESA CUALQUIER DOCUMENTO, ESTABA LISTO PARA DNI Y PASAPORTE PERO LE FALTA INE, SE REANUDA CADA QUE ESTÉ AL DÍA.
# @app.post(
# "/procesa_documento/",
# tags=["General"],
# summary="Reconocimiento Avanzado de Documentos")
# async def procesa_documento(image: UploadFile = File(...)):
# if not image.content_type.startswith("image/"):
# return {"error": "El archivo no es una imagen"}
# return await funciones.procesa_documento(image)
@app.post(
"/procesa_ine/",
tags=["Zurich"],
summary="Documentos México")
async def procesa_documento(image: UploadFile = File(...)):
if not image.content_type.startswith("image/"):
return {"error": "El archivo no es una imagen"}
return await funciones.procesa_ine(image) |