Add Checkpoints feature with routes, template, and JavaScript integration

- Introduced CheckpointsRoutes for managing checkpoints-related endpoints and handling the checkpoints page.
- Added checkpoints.html template for rendering the checkpoints interface with a work-in-progress message.
- Implemented checkpoints.js to manage the initialization of the Checkpoints page and its components.
- Updated LoraManager to include checkpoints routes in the application setup, enhancing overall functionality.
This commit is contained in:
Will Miao
2025-03-20 10:50:46 +08:00
parent a88b0239eb
commit c987338c84
4 changed files with 111 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ from .config import config
from .routes.lora_routes import LoraRoutes
from .routes.api_routes import ApiRoutes
from .routes.recipe_routes import RecipeRoutes
from .routes.checkpoints_routes import CheckpointsRoutes
from .services.lora_scanner import LoraScanner
from .services.recipe_scanner import RecipeScanner
from .services.file_monitor import LoraFileMonitor
@@ -59,12 +60,14 @@ class LoraManager:
# Setup feature routes
routes = LoraRoutes()
checkpoints_routes = CheckpointsRoutes()
# Setup file monitoring
monitor = LoraFileMonitor(routes.scanner, config.loras_roots)
monitor.start()
routes.setup_routes(app)
checkpoints_routes.setup_routes(app)
ApiRoutes.setup_routes(app, monitor)
RecipeRoutes.setup_routes(app)
@@ -130,4 +133,4 @@ class LoraManager:
async def _cleanup(cls, app):
"""Cleanup resources"""
if 'lora_monitor' in app:
app['lora_monitor'].stop()
app['lora_monitor'].stop()

View File

@@ -0,0 +1,44 @@
import os
from aiohttp import web
import jinja2
import logging
from ..config import config
from ..services.settings_manager import settings
logger = logging.getLogger(__name__)
logging.getLogger('asyncio').setLevel(logging.CRITICAL)
class CheckpointsRoutes:
"""Route handlers for Checkpoints management endpoints"""
def __init__(self):
self.template_env = jinja2.Environment(
loader=jinja2.FileSystemLoader(config.templates_path),
autoescape=True
)
async def handle_checkpoints_page(self, request: web.Request) -> web.Response:
"""Handle GET /checkpoints request"""
try:
template = self.template_env.get_template('checkpoints.html')
rendered = template.render(
is_initializing=False,
settings=settings,
request=request
)
return web.Response(
text=rendered,
content_type='text/html'
)
except Exception as e:
logger.error(f"Error handling checkpoints request: {e}", exc_info=True)
return web.Response(
text="Error loading checkpoints page",
status=500
)
def setup_routes(self, app: web.Application):
"""Register routes with the application"""
app.router.add_get('/checkpoints', self.handle_checkpoints_page)

36
static/js/checkpoints.js Normal file
View File

@@ -0,0 +1,36 @@
import { appCore } from './core.js';
import { state, initPageState } from './state/index.js';
// Initialize the Checkpoints page
class CheckpointsPageManager {
constructor() {
// Initialize any necessary state
this.initialized = false;
}
async initialize() {
if (this.initialized) return;
// Initialize page state
initPageState('checkpoints');
// Initialize core application
await appCore.initialize();
// Initialize page-specific components
this._initializeWorkInProgress();
this.initialized = true;
}
_initializeWorkInProgress() {
// Add any work-in-progress specific initialization here
console.log('Checkpoints Manager is under development');
}
}
// Initialize everything when DOM is ready
document.addEventListener('DOMContentLoaded', async () => {
const checkpointsPage = new CheckpointsPageManager();
await checkpointsPage.initialize();
});

View File

@@ -0,0 +1,27 @@
{% extends "base.html" %}
{% block title %}Checkpoints Manager{% endblock %}
{% block page_id %}checkpoints{% endblock %}
{% block preload %}
<link rel="preload" href="/loras_static/js/checkpoints.js" as="script" crossorigin="anonymous">
{% endblock %}
{% block init_title %}Initializing Checkpoints Manager{% endblock %}
{% block init_message %}Setting up checkpoints interface. This may take a few moments...{% endblock %}
{% block init_check_url %}/api/checkpoints?page=1&page_size=1{% endblock %}
{% block content %}
<div class="work-in-progress">
<div class="wip-content">
<i class="fas fa-tools"></i>
<h2>Checkpoints Manager</h2>
<p>This feature is currently under development and will be available soon.</p>
<p>Please check back later for updates!</p>
</div>
</div>
{% endblock %}
{% block main_script %}
<script type="module" src="/loras_static/js/checkpoints.js"></script>
{% endblock %}