13e3992d4c
Security fixes: - Add file upload size limits (10MB) for customer and product imports - Add XLSX file validation with row limits and magic byte checking - Implement password validation (min 6 chars) in registration - Add rate limiting for guest login (5 per IP per 15 minutes) - Sanitize error messages to prevent information leakage - Fix XSS vulnerability by removing unsafe v-html usage - Enforce WhatsApp webhook signature verification - Add SSRF protection with URL validation and IP blocking - Fix marketing endpoints to use proper authentication Code quality improvements: - Create shared utility functions for UUID validation and string sanitization - Remove duplicate UUID validation code from admin modules - Remove dead code (pass statement in translation.py) - Fix aliyun SDK import compatibility
68 lines
2.3 KiB
Python
68 lines
2.3 KiB
Python
from fastapi import APIRouter, Depends, HTTPException
|
|
from typing import Optional, Dict, Any
|
|
from pydantic import BaseModel
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from app.database import get_db
|
|
from app.services.discovery import DiscoveryService
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
class SearchRequest(BaseModel):
|
|
product_description: str
|
|
target_market: str = "US"
|
|
|
|
|
|
class AnalyzeRequest(BaseModel):
|
|
company_url: str
|
|
product_description: str
|
|
|
|
|
|
class OutreachRequest(BaseModel):
|
|
company: Dict[str, Any]
|
|
product: Dict[str, Any]
|
|
|
|
|
|
@router.post("/search")
|
|
async def search_leads(req: SearchRequest, db: AsyncSession = Depends(get_db)):
|
|
if not req.product_description.strip():
|
|
raise HTTPException(status_code=400, detail="请填写产品描述")
|
|
svc = DiscoveryService(db=db)
|
|
try:
|
|
result = await svc.search(req.product_description, req.target_market)
|
|
return {"success": True, "data": result}
|
|
except Exception as e:
|
|
logger.error(f"Search failed: {e}")
|
|
raise HTTPException(status_code=500, detail="搜索失败,请稍后重试")
|
|
|
|
|
|
@router.post("/analyze")
|
|
async def analyze_company(req: AnalyzeRequest):
|
|
if not req.company_url.strip():
|
|
raise HTTPException(status_code=400, detail="请填写公司网址")
|
|
if not req.product_description.strip():
|
|
raise HTTPException(status_code=400, detail="请填写产品描述")
|
|
svc = DiscoveryService()
|
|
try:
|
|
result = await svc.analyze(req.company_url, req.product_description)
|
|
return {"success": True, "data": result}
|
|
except Exception as e:
|
|
logger.error(f"Analysis failed: {e}")
|
|
raise HTTPException(status_code=500, detail="分析失败,请稍后重试")
|
|
|
|
|
|
@router.post("/outreach")
|
|
async def generate_outreach(req: OutreachRequest):
|
|
if not req.company.get("name"):
|
|
raise HTTPException(status_code=400, detail="请填写公司名称")
|
|
if not req.product.get("name"):
|
|
raise HTTPException(status_code=400, detail="请填写产品名称")
|
|
svc = DiscoveryService()
|
|
try:
|
|
result = await svc.generate_outreach(req.company, req.product)
|
|
return {"success": True, "data": result}
|
|
except Exception as e:
|
|
logger.error(f"Outreach generation failed: {e}")
|
|
raise HTTPException(status_code=500, detail="生成失败,请稍后重试")
|
|
|