mirror of
https://github.com/willmiao/ComfyUI-Lora-Manager.git
synced 2026-03-21 21:22:11 -03:00
feat: update API routes for version info and enhance version fetching functionality
This commit is contained in:
@@ -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"""
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 `
|
||||
<svg enable-background="new 0 0 512 512" version="1.1" viewBox="0 0 512 512" xml:space="preserve" xmlns="http://www.w3.org/2000/svg">
|
||||
@@ -144,4 +183,4 @@ const getLoraManagerIcon = () => {
|
||||
`;
|
||||
};
|
||||
|
||||
initializeWidgets();
|
||||
initialize();
|
||||
Reference in New Issue
Block a user