diff --git a/app.py b/app.py index 2e1dbeb0..befb5808 100644 --- a/app.py +++ b/app.py @@ -1,8 +1,8 @@ import asyncio from config.logger import setup_logging from config.settings import load_config -from core.server import WebSocketServer -from core.http_server import ConfigServer +from core.websocket_server import WebSocketServer +from manager.http_server import ConfigServer async def main(): setup_logging() # 最先初始化日志 diff --git a/config/settings.py b/config/settings.py index 9bdab1fe..d1f5a984 100644 --- a/config/settings.py +++ b/config/settings.py @@ -1,15 +1,29 @@ import os import argparse +from ruamel.yaml import YAML from core.utils.util import read_config, get_project_dir +def get_config_file(): + default_config_file = "config.yaml" + # 判断是否存在私有的配置文件 + if os.path.exists(get_project_dir() + "." + default_config_file): + default_config_file = "." + default_config_file + return default_config_file + + def load_config(): """加载配置文件""" parser = argparse.ArgumentParser(description="Server configuration") - default_config_file = "config.yaml" - # 判断是否存在私有的配置文件 - if os.path.exists(get_project_dir() + "." + default_config_file): - default_config_file = "." + default_config_file + default_config_file = get_config_file() parser.add_argument("--config_path", type=str, default=default_config_file) args = parser.parse_args() return read_config(args.config_path) + + +def update_config(config): + yaml = YAML() + yaml.preserve_quotes = True + """将配置保存到YAML文件""" + with open(get_config_file(), 'w') as f: + yaml.dump(config, f) diff --git a/core/connection.py b/core/connection.py index c1cbe4b8..972e9ae5 100644 --- a/core/connection.py +++ b/core/connection.py @@ -15,7 +15,7 @@ from core.handle.textHandle import handleTextMessage from core.utils.util import get_string_no_punctuation_or_emoji from concurrent.futures import ThreadPoolExecutor, TimeoutError from core.handle.audioHandle import handleAudioMessage, sendAudioMessage -from .auth import AuthMiddleware, AuthenticationError +from core.auth import AuthMiddleware, AuthenticationError class ConnectionHandler: diff --git a/core/server.py b/core/websocket_server.py similarity index 100% rename from core/server.py rename to core/websocket_server.py diff --git a/manager/api/prompt.py b/manager/api/prompt.py index a9ce8238..1fe5aa08 100644 --- a/manager/api/prompt.py +++ b/manager/api/prompt.py @@ -1,5 +1,7 @@ import logging from aiohttp import web +from config.settings import update_config +from ruamel.yaml.scalarstring import PreservedScalarString from manager.api.auth import verify_token from manager.api.response import response_unauthorized, response_success, response_error @@ -28,10 +30,13 @@ class PromptApi: if 'prompt' not in data: return response_success() - self.config['prompt'] = data['prompt'] - # TODO 保存到配置文件 - return response_success() + # 使用PreservedScalarString保留多行文本格式 + self.config['prompt'] = PreservedScalarString(data['prompt']) + # 保存到配置文件 + update_config(self.config) + + return response_success() except Exception as e: logger.error(f"Failed to update prompt: {e}") return response_error(str(e)) diff --git a/core/http_server.py b/manager/http_server.py similarity index 100% rename from core/http_server.py rename to manager/http_server.py diff --git a/manager/static/css/common.css b/manager/static/css/common.css new file mode 100644 index 00000000..b6f7287e --- /dev/null +++ b/manager/static/css/common.css @@ -0,0 +1,77 @@ +/* common.css */ +/* 基础样式 */ +body { + margin: 0; + padding: 0; + background: linear-gradient(135deg, #1a1f25 0%, #0d1117 100%); + min-height: 100vh; + font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; +} + +/* 头部组件 */ +.app-header { + background: rgba(13, 17, 23, 0.8); + backdrop-filter: blur(10px); + color: #fff; + padding: 1.5rem 2rem; + font-size: 1.4rem; + border-bottom: 1px solid rgba(255, 255, 255, 0.1); + display: flex; + align-items: center; + gap: 1rem; + position: relative; + z-index: 1; +} + +.header-logo { + width: 32px; + height: 32px; + background: linear-gradient(45deg, #00c6fb 0%, #005bea 100%); + border-radius: 8px; + display: flex; + align-items: center; + justify-content: center; + font-weight: bold; +} + +/* 页脚组件 */ +.app-footer { + text-align: center; + color: rgba(255, 255, 255, 0.6); + font-size: 13px; + padding: 20px; + position: fixed; + bottom: 0; + width: 100%; + z-index: 1; +} + +/* 背景动画 */ +.animated-bg { + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + z-index: -1; + background: linear-gradient(-45deg, #1a1f25, #0d1117, #162030, #1c1c1c); + background-size: 400% 400%; +} + + +.user-menu { + position: fixed; + top: 23px; + right: 32px; + z-index: 1000; + cursor: pointer; +} + +.user-info { + align-items: center; +} + +.user-name { + font-size: 14px; + color: #606266; +} \ No newline at end of file diff --git a/manager/static/images/favicon.ico b/manager/static/images/favicon.ico new file mode 100644 index 00000000..2e4ba64e Binary files /dev/null and b/manager/static/images/favicon.ico differ diff --git a/manager/static/index.html b/manager/static/index.html index c42fcfed..2e087027 100644 --- a/manager/static/index.html +++ b/manager/static/index.html @@ -1,5 +1,5 @@ - - + + @@ -8,39 +8,11 @@ + + 小智-server
-
- - xiaozhi-esp32-server + xiaozhi-esp32-server + +
+ + + +
-
配置角色:
-
cc:ba:97:11:a6:ac
-
角色介绍
@@ -117,15 +78,13 @@
保存配置 - 重置 + 重置
注意:保存配置后,需要重启设备,新的配置才会生效。
- +
diff --git a/manager/static/js/common.js b/manager/static/js/common.js index 0f888e11..790e6b43 100644 --- a/manager/static/js/common.js +++ b/manager/static/js/common.js @@ -37,4 +37,32 @@ function get(api, fn) { } fn(data); }); +} + +// 注册全局组件 +const AppHeader = { + template: ` +
+ + xiaozhi-esp32-server +
+ ` +}; + +const AppFooter = { + template: ` + + ` +}; + +// 初始化Vue应用的通用配置 +function createVueApp(options) { + const app = Vue.createApp({ + ...options, + components: { AppHeader, AppFooter } + }); + app.use(ElementPlus); + return app; } \ No newline at end of file diff --git a/manager/static/login.html b/manager/static/login.html index 0a622146..6621a134 100644 --- a/manager/static/login.html +++ b/manager/static/login.html @@ -1,46 +1,18 @@ - - + + + + 小智-server
-
- - xiaozhi-esp32-server -
+ xiaozhi-esp32-server + - + +
+ diff --git a/requirements.txt b/requirements.txt index fb127028..544dc8fd 100755 --- a/requirements.txt +++ b/requirements.txt @@ -13,3 +13,4 @@ edge_tts==7.0.0 httpx==0.27.2 aiohttp==3.9.3 ormsgpack==1.7.0 +ruamel.yaml==0.18.10 diff --git a/static/index.html b/static/index.html deleted file mode 100644 index 8c32c57c..00000000 --- a/static/index.html +++ /dev/null @@ -1,53 +0,0 @@ - - - - 小智提示词配置 - - - - -

小智提示词配置

- -
- - -
- - - \ No newline at end of file