feat: add translation billing stats and remove Export/Settings pages
- Add TranslationLog model to track translation API usage per task - Integrate Dify API actual price (total_price) into translation stats - Display translation statistics in admin dashboard with per-task costs - Remove unused Export and Settings pages to simplify frontend - Add GET /api/v2/admin/translation-stats endpoint 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -186,3 +186,34 @@ async def get_user_activity_summary(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"Failed to get user activity summary: {str(e)}"
|
||||
)
|
||||
|
||||
|
||||
@router.get("/translation-stats", summary="Get translation statistics")
|
||||
async def get_translation_stats(
|
||||
db: Session = Depends(get_db),
|
||||
admin_user: User = Depends(get_current_admin_user)
|
||||
):
|
||||
"""
|
||||
Get translation usage statistics for billing and monitoring.
|
||||
|
||||
Returns:
|
||||
- total_translations: Total number of translation jobs
|
||||
- total_tokens: Sum of all tokens used
|
||||
- total_characters: Sum of all characters translated
|
||||
- estimated_cost: Estimated cost based on token pricing
|
||||
- by_language: Breakdown by target language
|
||||
- recent_translations: List of recent translation activities
|
||||
- last_30_days: Statistics for the last 30 days
|
||||
|
||||
Requires admin privileges.
|
||||
"""
|
||||
try:
|
||||
stats = admin_service.get_translation_statistics(db)
|
||||
return stats
|
||||
|
||||
except Exception as e:
|
||||
logger.exception("Failed to get translation statistics")
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
||||
detail=f"Failed to get translation statistics: {str(e)}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user