update:优化页面样式

This commit is contained in:
hrz
2025-02-15 16:17:08 +08:00
parent 2379cdc3ba
commit 2901506157
13 changed files with 80257 additions and 74 deletions
+21 -1
View File
@@ -1,10 +1,30 @@
import uuid
from manager.api.response import response_success, response_error
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
class AuthApi:
def __init__(self, config):
self.config = config
async def login(self, request):
try:
data = await request.json()
if 'password' not in data:
return response_error("密码不能为空")
# 通过config参数回传修改能力
if self.config['manager']['token'] == data['password']:
return response_success(data=str(uuid.uuid4()))
return response_error("密码不正确")
except Exception as e:
return response_error(str(e))
+7 -7
View File
@@ -1,17 +1,18 @@
import logging
from aiohttp import web
from manager.api.auth import verify_token
from manager.api.response import response_unauthorized, response_success, response_error
logger = logging.getLogger(__name__)
class PromptHandler:
class PromptApi:
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 response_unauthorized()
return web.json_response({
'prompt': self.config['prompt'],
@@ -20,17 +21,16 @@ class PromptHandler:
async def update_prompt(self, request):
if not await verify_token(self.config, request):
return web.json_response({'error': 'Unauthorized'}, status=401)
return response_unauthorized()
try:
data = await request.json()
if 'prompt' not in data:
return web.json_response({'error': 'Missing prompt field'}, status=400)
return response_success()
# 通过config参数回传修改能力
self.config['prompt'] = data['prompt']
return web.json_response({'success': True}, headers={'Access-Control-Allow-Origin': '*'})
return response_success()
except Exception as e:
logger.error(f"Failed to update prompt: {e}")
return web.json_response({'error': str(e)}, status=500)
return response_error(str(e))
+16
View File
@@ -0,0 +1,16 @@
from aiohttp import web
from typing import Optional, Dict, Any # 导入Optional用于表示可选类型
def response_error(msg):
return web.json_response({"code": -1, 'msg': msg}, status=200)
def response_success(msg: str = '', data: Optional[Any] = None):
if data is None:
data = {}
return web.json_response({"code": 0, 'msg': msg, 'data': data}, status=200)
def response_unauthorized():
return web.json_response({"code": 401}, status=200)