Add initialization handling for LoRA page with loading state

- Implement dynamic initialization detection in lora_routes
- Add initialization notice template with loading spinner
- Create CSS styles for initialization notice
- Add client-side script to auto-refresh page when initialization completes
This commit is contained in:
Will Miao
2025-02-04 19:44:23 +08:00
parent 78f16ad651
commit 7fb7e2aa2e
3 changed files with 92 additions and 11 deletions

View File

@@ -49,12 +49,27 @@ class LoraRoutes:
async def handle_loras_page(self, request: web.Request) -> web.Response:
"""Handle GET /loras request"""
try:
# Get cached data for folders only
cache = await self.scanner.get_cached_data()
# Render template with folders only
template = self.template_env.get_template('loras.html')
rendered = template.render(folders=cache.folders)
# 不等待缓存数据,直接检查缓存状态
is_initializing = (
self.scanner._cache is None or
(hasattr(self.scanner, '_cache') and len(self.scanner._cache.raw_data) == 0)
)
if is_initializing:
# 如果正在初始化,返回一个只包含加载提示的页面
template = self.template_env.get_template('loras.html')
rendered = template.render(
folders=[], # 空文件夹列表
is_initializing=True # 新增标志
)
else:
# 正常流程
cache = await self.scanner.get_cached_data()
template = self.template_env.get_template('loras.html')
rendered = template.render(
folders=cache.folders,
is_initializing=False
)
return web.Response(
text=rendered,