update:优化web端目录结构

This commit is contained in:
hrz
2025-02-15 12:30:20 +08:00
parent e6381c6176
commit 2379cdc3ba
8 changed files with 204 additions and 122 deletions
+10
View File
@@ -0,0 +1,10 @@
async def verify_token(config, request):
if 'token' not in config['manager']:
return True
expected_token = config['manager']['token']
token = request.headers.get('Authorization', '').replace('Bearer ', '')
if not token or token != expected_token:
return False
return True
+36
View File
@@ -0,0 +1,36 @@
import logging
from aiohttp import web
from manager.api.auth import verify_token
logger = logging.getLogger(__name__)
class PromptHandler:
def __init__(self, config):
self.config = config
async def get_prompt(self, request):
if not await verify_token(self.config, request):
return web.json_response({'error': 'Unauthorized'}, status=401)
return web.json_response({
'prompt': self.config['prompt'],
'Access-Control-Allow-Origin': '*'
})
async def update_prompt(self, request):
if not await verify_token(self.config, request):
return web.json_response({'error': 'Unauthorized'}, status=401)
try:
data = await request.json()
if 'prompt' not in data:
return web.json_response({'error': 'Missing prompt field'}, status=400)
# 通过config参数回传修改能力
self.config['prompt'] = data['prompt']
return web.json_response({'success': True}, headers={'Access-Control-Allow-Origin': '*'})
except Exception as e:
logger.error(f"Failed to update prompt: {e}")
return web.json_response({'error': str(e)}, status=500)
+53
View File
@@ -0,0 +1,53 @@
<!DOCTYPE html>
<html>
<head>
<title>小智提示词配置</title>
<meta charset="utf-8">
<style>
body { max-width: 800px; margin: 20px auto; padding: 0 20px; font-family: Arial, sans-serif; }
textarea { width: 100%; height: 300px; margin: 20px 0; padding: 10px; }
button { padding: 10px 20px; font-size: 16px; }
.success { color: green; }
.error { color: red; }
</style>
</head>
<body>
<h1>小智提示词配置</h1>
<textarea id="prompt"></textarea>
<div>
<button onclick="updatePrompt()">更新提示词</button>
<span id="status"></span>
</div>
<script>
// 加载当前prompt
fetch('/api/prompt')
.then(response => response.json())
.then(data => {
document.getElementById('prompt').value = data.prompt;
});
function updatePrompt() {
const prompt = document.getElementById('prompt').value;
fetch('/api/prompt', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({prompt: prompt})
})
.then(response => response.json())
.then(data => {
const status = document.getElementById('status');
if(data.success) {
status.textContent = '更新成功!';
status.className = 'success';
} else {
status.textContent = '更新失败: ' + data.error;
status.className = 'error';
}
setTimeout(() => status.textContent = '', 3000);
});
}
</script>
</body>
</html>
+13
View File
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<title>login</title>
<meta charset="utf-8">
<style>
</style>
</head>
<body>
login
</body>
</html>