style: restrict line-length

This commit is contained in:
Junyan Qin
2025-05-10 18:04:58 +08:00
parent b30016ed08
commit 055b389353
134 changed files with 1096 additions and 2595 deletions

View File

@@ -65,9 +65,7 @@ class RouterGroup(abc.ABC):
async def handler_error(*args, **kwargs):
if auth_type == AuthType.USER_TOKEN:
# 从Authorization头中获取token
token = quart.request.headers.get('Authorization', '').replace(
'Bearer ', ''
)
token = quart.request.headers.get('Authorization', '').replace('Bearer ', '')
if not token:
return self.http_status(401, -1, '未提供有效的用户令牌')

View File

@@ -14,10 +14,8 @@ class LogsRouterGroup(group.RouterGroup):
start_page_number = int(quart.request.args.get('start_page_number', 0))
start_offset = int(quart.request.args.get('start_offset', 0))
logs_str, end_page_number, end_offset = (
self.ap.log_cache.get_log_by_pointer(
start_page_number=start_page_number, start_offset=start_offset
)
logs_str, end_page_number, end_offset = self.ap.log_cache.get_log_by_pointer(
start_page_number=start_page_number, start_offset=start_offset
)
return self.success(

View File

@@ -11,23 +11,17 @@ class PipelinesRouterGroup(group.RouterGroup):
@self.route('', methods=['GET', 'POST'])
async def _() -> str:
if quart.request.method == 'GET':
return self.success(
data={'pipelines': await self.ap.pipeline_service.get_pipelines()}
)
return self.success(data={'pipelines': await self.ap.pipeline_service.get_pipelines()})
elif quart.request.method == 'POST':
json_data = await quart.request.json
pipeline_uuid = await self.ap.pipeline_service.create_pipeline(
json_data
)
pipeline_uuid = await self.ap.pipeline_service.create_pipeline(json_data)
return self.success(data={'uuid': pipeline_uuid})
@self.route('/_/metadata', methods=['GET'])
async def _() -> str:
return self.success(
data={'configs': await self.ap.pipeline_service.get_pipeline_metadata()}
)
return self.success(data={'configs': await self.ap.pipeline_service.get_pipeline_metadata()})
@self.route('/<pipeline_uuid>', methods=['GET', 'PUT', 'DELETE'])
async def _(pipeline_uuid: str) -> str:

View File

@@ -8,30 +8,20 @@ class AdaptersRouterGroup(group.RouterGroup):
async def initialize(self) -> None:
@self.route('', methods=['GET'])
async def _() -> str:
return self.success(
data={'adapters': self.ap.platform_mgr.get_available_adapters_info()}
)
return self.success(data={'adapters': self.ap.platform_mgr.get_available_adapters_info()})
@self.route('/<adapter_name>', methods=['GET'])
async def _(adapter_name: str) -> str:
adapter_info = self.ap.platform_mgr.get_available_adapter_info_by_name(
adapter_name
)
adapter_info = self.ap.platform_mgr.get_available_adapter_info_by_name(adapter_name)
if adapter_info is None:
return self.http_status(404, -1, 'adapter not found')
return self.success(data={'adapter': adapter_info})
@self.route(
'/<adapter_name>/icon', methods=['GET'], auth_type=group.AuthType.NONE
)
@self.route('/<adapter_name>/icon', methods=['GET'], auth_type=group.AuthType.NONE)
async def _(adapter_name: str) -> quart.Response:
adapter_manifest = (
self.ap.platform_mgr.get_available_adapter_manifest_by_name(
adapter_name
)
)
adapter_manifest = self.ap.platform_mgr.get_available_adapter_manifest_by_name(adapter_name)
if adapter_manifest is None:
return self.http_status(404, -1, 'adapter not found')

View File

@@ -92,9 +92,7 @@ class PluginsRouterGroup(group.RouterGroup):
await self.ap.plugin_mgr.reorder_plugins(data.get('plugins'))
return self.success()
@self.route(
'/install/github', methods=['POST'], auth_type=group.AuthType.USER_TOKEN
)
@self.route('/install/github', methods=['POST'], auth_type=group.AuthType.USER_TOKEN)
async def _() -> str:
data = await quart.request.json

View File

@@ -9,9 +9,7 @@ class LLMModelsRouterGroup(group.RouterGroup):
@self.route('', methods=['GET', 'POST'])
async def _() -> str:
if quart.request.method == 'GET':
return self.success(
data={'models': await self.ap.model_service.get_llm_models()}
)
return self.success(data={'models': await self.ap.model_service.get_llm_models()})
elif quart.request.method == 'POST':
json_data = await quart.request.json

View File

@@ -8,30 +8,20 @@ class RequestersRouterGroup(group.RouterGroup):
async def initialize(self) -> None:
@self.route('', methods=['GET'])
async def _() -> quart.Response:
return self.success(
data={'requesters': self.ap.model_mgr.get_available_requesters_info()}
)
return self.success(data={'requesters': self.ap.model_mgr.get_available_requesters_info()})
@self.route('/<requester_name>', methods=['GET'])
async def _(requester_name: str) -> quart.Response:
requester_info = self.ap.model_mgr.get_available_requester_info_by_name(
requester_name
)
requester_info = self.ap.model_mgr.get_available_requester_info_by_name(requester_name)
if requester_info is None:
return self.http_status(404, -1, 'requester not found')
return self.success(data={'requester': requester_info})
@self.route(
'/<requester_name>/icon', methods=['GET'], auth_type=group.AuthType.NONE
)
@self.route('/<requester_name>/icon', methods=['GET'], auth_type=group.AuthType.NONE)
async def _(requester_name: str) -> quart.Response:
requester_manifest = (
self.ap.model_mgr.get_available_requester_manifest_by_name(
requester_name
)
)
requester_manifest = self.ap.model_mgr.get_available_requester_manifest_by_name(requester_name)
if requester_manifest is None:
return self.http_status(404, -1, 'requester not found')

View File

@@ -8,9 +8,7 @@ class StatsRouterGroup(group.RouterGroup):
async def _() -> str:
conv_count = 0
for session in self.ap.sess_mgr.session_list:
conv_count += len(
session.conversations if session.conversations is not None else []
)
conv_count += len(session.conversations if session.conversations is not None else [])
return self.success(
data={

View File

@@ -13,9 +13,7 @@ class SystemRouterGroup(group.RouterGroup):
data={
'version': constants.semantic_version,
'debug': constants.debug_mode,
'enabled_platform_count': len(
self.ap.platform_mgr.get_running_adapters()
),
'enabled_platform_count': len(self.ap.platform_mgr.get_running_adapters()),
}
)
@@ -28,9 +26,7 @@ class SystemRouterGroup(group.RouterGroup):
return self.success(data=self.ap.task_mgr.get_tasks_dict(task_type))
@self.route(
'/tasks/<task_id>', methods=['GET'], auth_type=group.AuthType.USER_TOKEN
)
@self.route('/tasks/<task_id>', methods=['GET'], auth_type=group.AuthType.USER_TOKEN)
async def _(task_id: str) -> str:
task = self.ap.task_mgr.get_task_by_id(int(task_id))
@@ -48,9 +44,7 @@ class SystemRouterGroup(group.RouterGroup):
await self.ap.reload(scope=scope)
return self.success()
@self.route(
'/_debug/exec', methods=['POST'], auth_type=group.AuthType.USER_TOKEN
)
@self.route('/_debug/exec', methods=['POST'], auth_type=group.AuthType.USER_TOKEN)
async def _() -> str:
if not constants.debug_mode:
return self.http_status(403, 403, 'Forbidden')

View File

@@ -10,9 +10,7 @@ class UserRouterGroup(group.RouterGroup):
@self.route('/init', methods=['GET', 'POST'], auth_type=group.AuthType.NONE)
async def _() -> str:
if quart.request.method == 'GET':
return self.success(
data={'initialized': await self.ap.user_service.is_initialized()}
)
return self.success(data={'initialized': await self.ap.user_service.is_initialized()})
if await self.ap.user_service.is_initialized():
return self.fail(1, '系统已初始化')
@@ -31,17 +29,13 @@ class UserRouterGroup(group.RouterGroup):
json_data = await quart.request.json
try:
token = await self.ap.user_service.authenticate(
json_data['user'], json_data['password']
)
token = await self.ap.user_service.authenticate(json_data['user'], json_data['password'])
except argon2.exceptions.VerifyMismatchError:
return self.fail(1, '用户名或密码错误')
return self.success(data={'token': token})
@self.route(
'/check-token', methods=['GET'], auth_type=group.AuthType.USER_TOKEN
)
@self.route('/check-token', methods=['GET'], auth_type=group.AuthType.USER_TOKEN)
async def _(user_email: str) -> str:
token = await self.ap.user_service.generate_jwt_token(user_email)

View File

@@ -70,15 +70,12 @@ class HTTPController:
@self.quart_app.route('/')
async def index():
return await quart.send_from_directory(
frontend_path, 'index.html', mimetype='text/html'
)
return await quart.send_from_directory(frontend_path, 'index.html', mimetype='text/html')
@self.quart_app.route('/<path:path>')
async def static_file(path: str):
if not (
os.path.exists(os.path.join(frontend_path, path))
and os.path.isfile(os.path.join(frontend_path, path))
os.path.exists(os.path.join(frontend_path, path)) and os.path.isfile(os.path.join(frontend_path, path))
):
if os.path.exists(os.path.join(frontend_path, path + '.html')):
path += '.html'
@@ -110,6 +107,4 @@ class HTTPController:
elif path.endswith('.txt'):
mimetype = 'text/plain'
return await quart.send_from_directory(
frontend_path, path, mimetype=mimetype
)
return await quart.send_from_directory(frontend_path, path, mimetype=mimetype)