From 1f8bc93aa98bb5be19da4938bf7dc9f0d68c335a Mon Sep 17 00:00:00 2001 From: Whispering Wind <151555003+ReturnFI@users.noreply.github.com> Date: Tue, 11 Mar 2025 01:03:23 +0330 Subject: [PATCH] Added API endpoints for getting version info and checking for updates --- .../scripts/webpanel/routers/api/v1/server.py | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/core/scripts/webpanel/routers/api/v1/server.py b/core/scripts/webpanel/routers/api/v1/server.py index 2ef99b0..5639d9b 100644 --- a/core/scripts/webpanel/routers/api/v1/server.py +++ b/core/scripts/webpanel/routers/api/v1/server.py @@ -1,6 +1,6 @@ from fastapi import APIRouter, HTTPException import cli_api -from .schema.server import ServerStatusResponse, ServerServicesStatusResponse +from .schema.server import ServerStatusResponse, ServerServicesStatusResponse, VersionCheckResponse, VersionInfoResponse router = APIRouter() @@ -144,3 +144,40 @@ def __parse_services_status(services_status: dict[str, bool]) -> ServerServicesS elif 'wg-quick' in service: parsed_services_status['hysteria_warp'] = status return ServerServicesStatusResponse(**parsed_services_status) + +@router.get('/version', response_model=VersionInfoResponse) +async def get_version_info(): + """Retrieves the current version of the panel.""" + try: + version_output = cli_api.show_version() + if version_output: + current_version = version_output.split(": ")[1].strip() + return VersionInfoResponse(current_version=current_version) + raise HTTPException(status_code=404, detail="Version information not found") + except Exception as e: + raise HTTPException(status_code=500, detail=str(e)) + + +@router.get('/version/check', response_model=VersionCheckResponse) +async def check_version_info(): + """Checks for updates and retrieves version information.""" + try: + check_output = cli_api.check_version() + if check_output: + lines = check_output.splitlines() + current_version = lines[0].split(": ")[1].strip() + + if len(lines) > 1 and "Latest Version" in lines[1]: + latest_version = lines[1].split(": ")[1].strip() + is_latest = current_version == latest_version + changelog_start_index = 3 + changelog = "\n".join(lines[changelog_start_index:]).strip() + return VersionCheckResponse(is_latest=is_latest, current_version=current_version, + latest_version=latest_version, changelog=changelog) + else: + return VersionCheckResponse(is_latest=True, current_version=current_version) + + raise HTTPException(status_code=404, detail="Version information not found") + + except Exception as e: + raise HTTPException(status_code=500, detail=str(e)) \ No newline at end of file