feat: update API routes for version info and enhance version fetching functionality

This commit is contained in:
Will Miao
2025-06-20 16:38:11 +08:00
parent 1b2a02cb1a
commit 32d12bb334
3 changed files with 71 additions and 3 deletions

View File

@@ -15,7 +15,8 @@ class UpdateRoutes:
@staticmethod
def setup_routes(app):
"""Register update check routes"""
app.router.add_get('/loras/api/check-updates', UpdateRoutes.check_updates)
app.router.add_get('/api/check-updates', UpdateRoutes.check_updates)
app.router.add_get('/api/version-info', UpdateRoutes.get_version_info)
@staticmethod
async def check_updates(request):
@@ -55,6 +56,34 @@ class UpdateRoutes:
'error': str(e)
})
@staticmethod
async def get_version_info(request):
"""
Returns the current version in the format 'version-short_hash'
"""
try:
# Read local version from pyproject.toml
local_version = UpdateRoutes._get_local_version().replace('v', '')
# Get git info (commit hash, branch)
git_info = UpdateRoutes._get_git_info()
short_hash = git_info['short_hash']
# Format: version-short_hash
version_string = f"{local_version}-{short_hash}"
return web.json_response({
'success': True,
'version': version_string
})
except Exception as e:
logger.error(f"Failed to get version info: {e}", exc_info=True)
return web.json_response({
'success': False,
'error': str(e)
})
@staticmethod
def _get_local_version() -> str:
"""Get local plugin version from pyproject.toml"""