bd7635986a
Vue 前端 + FastAPI 后端,含部署脚本与词典数据。 Co-authored-by: Cursor <cursoragent@cursor.com>
21 lines
626 B
Python
21 lines
626 B
Python
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
|
|
from auth import get_current_user
|
|
from database import get_db
|
|
from models import User
|
|
from schemas import TranslateRequest, TranslateResponse
|
|
from services.translation_service import translation_service
|
|
|
|
router = APIRouter(prefix="/api", tags=["translate"])
|
|
|
|
|
|
@router.post("/translate", response_model=TranslateResponse)
|
|
def translate(
|
|
data: TranslateRequest,
|
|
db: Session = Depends(get_db),
|
|
current_user: User = Depends(get_current_user),
|
|
):
|
|
result = translation_service.translate(db, data.text)
|
|
return TranslateResponse(**result)
|