From 32d12bb3343a52b903e0ca00c5bde65be050bcb4 Mon Sep 17 00:00:00 2001 From: Will Miao <13051207myq@gmail.com> Date: Fri, 20 Jun 2025 16:38:11 +0800 Subject: [PATCH] feat: update API routes for version info and enhance version fetching functionality --- py/routes/update_routes.py | 31 +++++++++++++++++++++- static/js/managers/UpdateService.js | 2 +- web/comfyui/ui_utils.js | 41 ++++++++++++++++++++++++++++- 3 files changed, 71 insertions(+), 3 deletions(-) diff --git a/py/routes/update_routes.py b/py/routes/update_routes.py index 14168684..3b45c0f1 100644 --- a/py/routes/update_routes.py +++ b/py/routes/update_routes.py @@ -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""" diff --git a/static/js/managers/UpdateService.js b/static/js/managers/UpdateService.js index 694101a7..52a62603 100644 --- a/static/js/managers/UpdateService.js +++ b/static/js/managers/UpdateService.js @@ -60,7 +60,7 @@ export class UpdateService { try { // Call backend API to check for updates - const response = await fetch('/loras/api/check-updates'); + const response = await fetch('/api/check-updates'); const data = await response.json(); if (data.success) { diff --git a/web/comfyui/ui_utils.js b/web/comfyui/ui_utils.js index 68ad7476..524940c8 100644 --- a/web/comfyui/ui_utils.js +++ b/web/comfyui/ui_utils.js @@ -104,6 +104,45 @@ const initializeWidgets = () => { addWidget('.comfy-menu', addWidgetMenu); }; +// Fetch version info from the API +const fetchVersionInfo = async () => { + try { + const response = await fetch('/api/version-info'); + const data = await response.json(); + + if (data.success) { + return data.version; + } + return ''; + } catch (error) { + console.error('Error fetching version info:', error); + return ''; + } +}; + +// Register about badge with version info +const registerAboutBadge = async () => { + let version = await fetchVersionInfo(); + const label = version ? `LoRA-Manager v${version}` : 'LoRA-Manager'; + + app.registerExtension({ + name: 'LoraManager.AboutBadge', + aboutPageBadges: [ + { + label: label, + url: 'https://github.com/willmiao/ComfyUI-Lora-Manager', + icon: 'pi pi-tags' + } + ] + }); +}; + +// Initialize everything +const initialize = () => { + initializeWidgets(); + registerAboutBadge(); +}; + const getLoraManagerIcon = () => { return ` @@ -144,4 +183,4 @@ const getLoraManagerIcon = () => { `; }; -initializeWidgets(); \ No newline at end of file +initialize(); \ No newline at end of file