Shield external portal jumps (keep EXTERNAL_* for later), serve /nav from static build, and proxy /book + /community to vertical Next apps with Caddy notes. Co-authored-by: Cursor <cursoragent@cursor.com>
49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
"""Feedback route."""
|
|
|
|
import logging
|
|
|
|
import httpx
|
|
from fastapi import APIRouter, Request
|
|
from fastapi.responses import JSONResponse
|
|
|
|
from ..config import get_settings
|
|
from ..db import get_pb
|
|
|
|
router = APIRouter(prefix="/api", tags=["feedback"])
|
|
logger = logging.getLogger("feedback")
|
|
|
|
|
|
@router.post("/feedback")
|
|
async def post_feedback(request: Request):
|
|
body = await request.json()
|
|
message = (body.get("message") or "").strip()
|
|
if not message or len(message) < 4:
|
|
return JSONResponse({"ok": False, "error": "message required"}, 400)
|
|
|
|
email = (body.get("email") or "").strip()
|
|
|
|
# Save to PocketBase
|
|
try:
|
|
pb = get_pb()
|
|
pb.collection("feedback").create({
|
|
"email": email,
|
|
"message": message,
|
|
})
|
|
except Exception as e:
|
|
logger.warning("Failed to save feedback: %s", e)
|
|
|
|
# Forward to webhook if configured
|
|
s = get_settings()
|
|
if s.feedback_webhook_url:
|
|
try:
|
|
async with httpx.AsyncClient() as client:
|
|
await client.post(s.feedback_webhook_url, json={
|
|
"email": email,
|
|
"message": message,
|
|
"at": __import__("datetime").datetime.utcnow().isoformat(),
|
|
})
|
|
except Exception as e:
|
|
logger.warning("Feedback webhook failed: %s", e)
|
|
|
|
return {"ok": True}
|