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
+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)