feat(api): add core version to version API endpoint

This commit is contained in:
ReturnFI
2025-12-16 07:12:57 +00:00
parent b379fb9191
commit f87401d9a0
2 changed files with 19 additions and 5 deletions

View File

@ -43,6 +43,7 @@ class ServerServicesStatusResponse(BaseModel):
class VersionInfoResponse(BaseModel): class VersionInfoResponse(BaseModel):
current_version: str current_version: str
core_version: Optional[str] = None
class VersionCheckResponse(BaseModel): class VersionCheckResponse(BaseModel):

View File

@ -182,13 +182,26 @@ def __parse_services_status(services_status: dict[str, bool]) -> ServerServicesS
@router.get('/version', response_model=VersionInfoResponse) @router.get('/version', response_model=VersionInfoResponse)
async def get_version_info(): async def get_version_info():
"""Retrieves the current version of the panel.""" """Retrieves the current version of the panel and Hysteria core."""
try: try:
version_output = cli_api.show_version() version_output = cli_api.show_version()
if version_output: if not version_output:
current_version = version_output.split(": ")[1].strip() raise HTTPException(status_code=404, detail="Version information not found")
return VersionInfoResponse(current_version=current_version)
raise HTTPException(status_code=404, detail="Version information not found") lines = version_output.strip().splitlines()
current_version = None
core_version = None
for line in lines:
if "Panel Version:" in line:
current_version = line.split(": ")[1].strip()
elif "Hysteria2 Core Version:" in line:
core_version = line.split(": ")[1].strip()
if current_version:
return VersionInfoResponse(current_version=current_version, core_version=core_version)
raise HTTPException(status_code=404, detail="Panel version not found in output")
except Exception as e: except Exception as e:
raise HTTPException(status_code=500, detail=str(e)) raise HTTPException(status_code=500, detail=str(e))