Add LoRAGateway node for LoRA management and enhance folder filter state handling

This commit is contained in:
Will Miao
2025-01-30 22:03:53 +08:00
parent 4b043d54f6
commit 6e861550a7
5 changed files with 78 additions and 16 deletions

View File

@@ -1,13 +1,13 @@
from .nodes import LorasEndpoint
from .nodes.lora_gateway import LoRAGateway
NODE_CLASS_MAPPINGS = {
"LorasEndpoint": LorasEndpoint
"LoRAGateway": LoRAGateway
}
NODE_DISPLAY_NAME_MAPPINGS = {
"LoRAGateway": "LoRAGateway"
}
WEB_DIRECTORY = "./js"
# Add this init function to properly register routes
def init():
LorasEndpoint.add_routes()
__all__ = ['NODE_CLASS_MAPPINGS']
__all__ = ['NODE_CLASS_MAPPINGS', 'NODE_DISPLAY_NAME_MAPPINGS', 'WEB_DIRECTORY']

View File

@@ -11,6 +11,7 @@ from .utils.lora_metadata import extract_lora_metadata
from typing import Dict, Optional
from .services.civitai_client import CivitaiClient
import folder_paths
import logging
class LorasEndpoint:
def __init__(self):

0
nodes/__init__.py Normal file
View File

24
nodes/lora_gateway.py Normal file
View File

@@ -0,0 +1,24 @@
from ..lora_manager import LorasEndpoint
class LoRAGateway:
"""
LoRA Gateway Node
Acts as the entry point for LoRA management services
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {},
"optional": {}
}
RETURN_TYPES = ()
FUNCTION = "register_services"
CATEGORY = "LoRA Management"
@classmethod
def register_services(cls):
# Service registration logic
LorasEndpoint.add_routes()
return ()

View File

@@ -292,19 +292,30 @@ document.addEventListener('DOMContentLoaded', function() {
}, 500);
}
});
// Restore folder filter state
restoreFolderFilter();
// Restore scroll position if exists
const savedScrollPos = localStorage.getItem('scrollPosition');
if (savedScrollPos !== null) {
window.scrollTo(0, parseInt(savedScrollPos));
localStorage.removeItem('scrollPosition');
}
});
function toggleFolder(element) {
// Remove active class from all tags if clicking already active tag
if (element.classList.contains('active')) {
document.querySelectorAll('.tag').forEach(tag => tag.classList.remove('active'));
// Show all cards
document.querySelectorAll('.lora-card').forEach(card => card.style.display = '');
} else {
// Remove active class from all tags
document.querySelectorAll('.tag').forEach(tag => tag.classList.remove('active'));
// Store the previous state
const wasActive = element.classList.contains('active');
// Remove active class from all tags
document.querySelectorAll('.tag').forEach(tag => tag.classList.remove('active'));
if (!wasActive) {
// Add active class to clicked tag
element.classList.add('active');
// Store active folder in localStorage
localStorage.setItem('activeFolder', element.getAttribute('data-folder'));
// Hide all cards first
document.querySelectorAll('.lora-card').forEach(card => {
if (card.getAttribute('data-folder') === element.getAttribute('data-folder')) {
@@ -313,6 +324,29 @@ function toggleFolder(element) {
card.style.display = 'none';
}
});
} else {
// Clear stored folder when deactivating
localStorage.removeItem('activeFolder');
// Show all cards
document.querySelectorAll('.lora-card').forEach(card => card.style.display = '');
}
}
// Add this function to restore folder filter state
function restoreFolderFilter() {
const activeFolder = localStorage.getItem('activeFolder');
if (activeFolder !== null) {
const folderTag = document.querySelector(`.tag[data-folder="${activeFolder}"]`);
if (folderTag) {
folderTag.classList.add('active');
document.querySelectorAll('.lora-card').forEach(card => {
if (card.getAttribute('data-folder') === activeFolder) {
card.style.display = '';
} else {
card.style.display = 'none';
}
});
}
}
}
@@ -408,7 +442,10 @@ async function fetchCivitai() {
loadingStatus.textContent = 'Metadata update complete';
setTimeout(() => {
loadingOverlay.style.display = 'none';
// Optionally reload the page to show updated data
// Store current scroll position
const scrollPos = window.scrollY;
localStorage.setItem('scrollPosition', scrollPos.toString());
// Reload the page
window.location.reload();
}, 2000);