From cfc2928de2a07ff1d160faf80bc5598b90531feb Mon Sep 17 00:00:00 2001 From: Jin Hai Date: Fri, 10 Apr 2026 18:00:41 +0800 Subject: [PATCH] Go: remove unused API route (#14028) ### What problem does this PR solve? As title ### Type of change - [x] Refactoring --------- Signed-off-by: Jin Hai --- api/apps/restful_apis/config_api.py | 71 ----------------------------- api/apps/restful_apis/system_api.py | 56 ++++++++++++++++++++++- internal/handler/api_token.go | 6 +-- internal/router/router.go | 26 +++-------- 4 files changed, 65 insertions(+), 94 deletions(-) delete mode 100644 api/apps/restful_apis/config_api.py diff --git a/api/apps/restful_apis/config_api.py b/api/apps/restful_apis/config_api.py deleted file mode 100644 index e5b8ed394e..0000000000 --- a/api/apps/restful_apis/config_api.py +++ /dev/null @@ -1,71 +0,0 @@ -# -# Copyright 2026 The InfiniFlow Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -from api.apps import login_required -from api.utils.api_utils import get_json_result, get_data_error_result -from common.log_utils import get_log_levels, set_log_level - -@manager.route("/config/log", methods=["GET"]) # noqa: F821 -@login_required -async def get_logger_levels(): - """ - Get current log levels for all packages. - --- - tags: - - System - responses: - 200: - description: Return current log levels - """ - return get_json_result(data=get_log_levels()) - - -@manager.route("/config/log", methods=["PUT"]) # noqa: F821 -@login_required -async def set_logger_level(): - """ - Set log level for a package. - --- - tags: - - System - parameters: - - in: body - name: body - required: true - schema: - type: object - properties: - pkg_name: - type: string - description: Package name (e.g., "rag.utils.es_conn") - level: - type: string - description: Log level (DEBUG, INFO, WARNING, ERROR) - responses: - 200: - description: Log level updated successfully - """ - from quart import request - data = await request.get_json() - if not data or "pkg_name" not in data or "level" not in data: - return get_data_error_result(message="pkg_name and level are required") - pkg_name = data["pkg_name"] - level = data["level"] - success = set_log_level(pkg_name, level) - if success: - return get_json_result(data={"pkg_name": pkg_name, "level": level}) - else: - return get_data_error_result(message=f"Invalid log level: {level}") diff --git a/api/apps/restful_apis/system_api.py b/api/apps/restful_apis/system_api.py index b65f2b6707..467d9111d9 100644 --- a/api/apps/restful_apis/system_api.py +++ b/api/apps/restful_apis/system_api.py @@ -25,6 +25,7 @@ from common.time_utils import current_timestamp, datetime_format from api.db.db_models import APIToken from api.db.services.api_service import APITokenService from api.db.services.user_service import UserTenantService +from common.log_utils import get_log_levels, set_log_level @manager.route("/system/ping", methods=["GET"]) # noqa: F821 async def ping(): @@ -190,4 +191,57 @@ def rm(token): APITokenService.filter_delete([APIToken.tenant_id == tenant_id, APIToken.token == token]) return get_json_result(data=True) except Exception as e: - return server_error_response(e) \ No newline at end of file + return server_error_response(e) + + +@manager.route("/system/config/log", methods=["GET"]) # noqa: F821 +@login_required +async def get_logger_levels(): + """ + Get current log levels for all packages. + --- + tags: + - System + responses: + 200: + description: Return current log levels + """ + return get_json_result(data=get_log_levels()) + + +@manager.route("/system/config/log", methods=["PUT"]) # noqa: F821 +@login_required +async def set_logger_level(): + """ + Set log level for a package. + --- + tags: + - System + parameters: + - in: body + name: body + required: true + schema: + type: object + properties: + pkg_name: + type: string + description: Package name (e.g., "rag.utils.es_conn") + level: + type: string + description: Log level (DEBUG, INFO, WARNING, ERROR) + responses: + 200: + description: Log level updated successfully + """ + from quart import request + data = await request.get_json() + if not data or "pkg_name" not in data or "level" not in data: + return get_data_error_result(message="pkg_name and level are required") + pkg_name = data["pkg_name"] + level = data["level"] + success = set_log_level(pkg_name, level) + if success: + return get_json_result(data={"pkg_name": pkg_name, "level": level}) + else: + return get_data_error_result(message=f"Invalid log level: {level}") diff --git a/internal/handler/api_token.go b/internal/handler/api_token.go index c6bf66c213..137e011c1e 100644 --- a/internal/handler/api_token.go +++ b/internal/handler/api_token.go @@ -34,7 +34,7 @@ import ( // @Produce json // @Security ApiKeyAuth // @Success 200 {object} map[string]interface{} -// @Router /v1/system/token_list [get] +// @Router /api/v1/system/tokens [get] func (h *SystemHandler) ListTokens(c *gin.Context) { // Get current user from context user, exists := c.Get("user") @@ -94,7 +94,7 @@ func (h *SystemHandler) ListTokens(c *gin.Context) { // @Security ApiKeyAuth // @Param name query string false "Name of the token" // @Success 200 {object} map[string]interface{} -// @Router /v1/system/new_token [post] +// @Router /api/v1/system/tokens [post] func (h *SystemHandler) CreateToken(c *gin.Context) { // Get current user from context user, exists := c.Get("user") @@ -164,7 +164,7 @@ func (h *SystemHandler) CreateToken(c *gin.Context) { // @Security ApiKeyAuth // @Param token path string true "The API token to remove" // @Success 200 {object} map[string]interface{} -// @Router /v1/system/token/{token} [delete] +// @Router /api/v1/system/tokens/{token} [delete] func (h *SystemHandler) DeleteToken(c *gin.Context) { // Get current user from context user, exists := c.Get("user") diff --git a/internal/router/router.go b/internal/router/router.go index 62244c7881..c2c22855e8 100644 --- a/internal/router/router.go +++ b/internal/router/router.go @@ -117,11 +117,6 @@ func (r *Router) Setup(engine *gin.Engine) { // User set tenant info endpoint authorized.POST("/v1/user/set_tenant_info", r.userHandler.SetTenantInfo) - // System token endpoints (requires authentication) - authorized.GET("/v1/system/token_list", r.systemHandler.ListTokens) - authorized.POST("/v1/system/new_token", r.systemHandler.CreateToken) - authorized.DELETE("/v1/system/token/:token", r.systemHandler.DeleteToken) - // API v1 route group v1 := authorized.Group("/api/v1") { @@ -134,13 +129,6 @@ func (r *Router) Setup(engine *gin.Engine) { // users.GET("/:id", r.userHandler.GetUserByID) //} - //apiTokens := v1.Group("/tokens") - //{ - // apiTokens.POST("", r.systemHandler.CreateToken) - // apiTokens.GET("", r.systemHandler.ListTokens) - // apiTokens.DELETE("/:token", r.systemHandler.DeleteToken) - //} - // Document routes documents := v1.Group("/documents") { @@ -193,13 +181,13 @@ func (r *Router) Setup(engine *gin.Engine) { chats.GET("/:chat_id", r.chatHandler.GetChat) } - searches := v1.Group("/searches") - { - searches.GET("", r.searchHandler.ListSearches) - searches.POST("", r.searchHandler.CreateSearch) - searches.GET("/:search_id", r.searchHandler.GetSearch) - searches.DELETE("/:search_id", r.searchHandler.DeleteSearch) - } + searches := v1.Group("/searches") + { + searches.GET("", r.searchHandler.ListSearches) + searches.POST("", r.searchHandler.CreateSearch) + searches.GET("/:search_id", r.searchHandler.GetSearch) + searches.DELETE("/:search_id", r.searchHandler.DeleteSearch) + } file := v1.Group("/files") {