GeminiBalance / app /router /version_routes.py
CatPtain's picture
Upload 77 files
76b9762 verified
from fastapi import APIRouter, HTTPException
from pydantic import BaseModel, Field
from typing import Optional
from app.service.update.update_service import check_for_updates
from app.utils.helpers import get_current_version
from app.log.logger import get_update_logger
router = APIRouter(prefix="/api/version", tags=["Version"])
logger = get_update_logger()
class VersionInfo(BaseModel):
current_version: str = Field(..., description="ε½“ε‰εΊ”η”¨η¨‹εΊη‰ˆζœ¬")
latest_version: Optional[str] = Field(None, description="ε―η”¨ηš„ζœ€ζ–°η‰ˆζœ¬")
update_available: bool = Field(False, description="ζ˜―ε¦ζœ‰ε―η”¨ζ›΄ζ–°")
error_message: Optional[str] = Field(None, description="ζ£€ζŸ₯ζ›΄ζ–°ζ—Άε‘η”Ÿηš„ι”™θ――δΏ‘ζ―")
@router.get("/check", response_model=VersionInfo, summary="ζ£€ζŸ₯应用程序更新")
async def get_version_info():
"""
ζ£€ζŸ₯ε½“ε‰εΊ”η”¨η¨‹εΊη‰ˆζœ¬δΈŽζœ€ζ–°ηš„ GitHub release η‰ˆζœ¬γ€‚
"""
try:
current_version = get_current_version()
update_available, latest_version, error_message = await check_for_updates()
logger.info(f"Version check API result: current={current_version}, latest={latest_version}, available={update_available}, error='{error_message}'")
return VersionInfo(
current_version=current_version,
latest_version=latest_version,
update_available=update_available,
error_message=error_message
)
except Exception as e:
logger.error(f"Error in /api/version/check endpoint: {e}", exc_info=True)
raise HTTPException(status_code=500, detail="ζ£€ζŸ₯η‰ˆζœ¬δΏ‘ζ―ζ—Άε‘η”Ÿε†…ιƒ¨ι”™θ――")