From fc85ab2ef7dde1a6acf8e557f8f71d5190845adc Mon Sep 17 00:00:00 2001 From: yongtenglei Date: Mon, 1 Dec 2025 12:20:28 +0800 Subject: [PATCH] rename request_json to get_request_json --- api/apps/api_app.py | 6 +++--- api/apps/canvas_app.py | 18 +++++++++--------- api/apps/chunk_app.py | 14 +++++++------- api/apps/connector_app.py | 10 +++++----- api/apps/conversation_app.py | 20 ++++++++++---------- api/apps/dialog_app.py | 8 ++++---- api/apps/document_app.py | 24 ++++++++++++------------ api/apps/file2document_app.py | 6 +++--- api/apps/file_app.py | 10 +++++----- api/apps/kb_app.py | 30 +++++++++++++++--------------- api/apps/langfuse_app.py | 4 ++-- api/apps/llm_app.py | 12 ++++++------ api/apps/mcp_server_app.py | 22 +++++++++++----------- api/apps/sdk/agents.py | 8 ++++---- api/apps/sdk/chat.py | 8 ++++---- api/apps/sdk/dify_retrieval.py | 4 ++-- api/apps/sdk/doc.py | 32 ++++++++++++++++---------------- api/apps/sdk/files.py | 12 ++++++------ api/apps/sdk/session.py | 34 +++++++++++++++++----------------- api/apps/search_app.py | 10 +++++----- api/apps/tenant_app.py | 4 ++-- api/apps/user_app.py | 14 +++++++------- api/utils/api_utils.py | 2 +- 23 files changed, 156 insertions(+), 156 deletions(-) diff --git a/api/apps/api_app.py b/api/apps/api_app.py index ba538a4f0..97d7dc943 100644 --- a/api/apps/api_app.py +++ b/api/apps/api_app.py @@ -18,7 +18,7 @@ from quart import request from api.db.db_models import APIToken from api.db.services.api_service import APITokenService, API4ConversationService from api.db.services.user_service import UserTenantService -from api.utils.api_utils import generate_confirmation_token, get_data_error_result, get_json_result, request_json, server_error_response, validate_request +from api.utils.api_utils import generate_confirmation_token, get_data_error_result, get_json_result, get_request_json, server_error_response, validate_request from common.time_utils import current_timestamp, datetime_format from api.apps import login_required, current_user @@ -26,7 +26,7 @@ from api.apps import login_required, current_user @manager.route('/new_token', methods=['POST']) # noqa: F821 @login_required async def new_token(): - req = await request_json() + req = await get_request_json() try: tenants = UserTenantService.query(user_id=current_user.id) if not tenants: @@ -72,7 +72,7 @@ def token_list(): @validate_request("tokens", "tenant_id") @login_required async def rm(): - req = await request_json() + req = await get_request_json() try: for token in req["tokens"]: APITokenService.filter_delete( diff --git a/api/apps/canvas_app.py b/api/apps/canvas_app.py index 5e578e401..fe32dca0b 100644 --- a/api/apps/canvas_app.py +++ b/api/apps/canvas_app.py @@ -30,7 +30,7 @@ from api.db.services.user_canvas_version import UserCanvasVersionService from common.constants import RetCode from common.misc_utils import get_uuid from api.utils.api_utils import get_json_result, server_error_response, validate_request, get_data_error_result, \ - request_json + get_request_json from agent.canvas import Canvas from peewee import MySQLDatabase, PostgresqlDatabase from api.db.db_models import APIToken, Task @@ -53,7 +53,7 @@ def templates(): @validate_request("canvas_ids") @login_required async def rm(): - req = await request_json() + req = await get_request_json() for i in req["canvas_ids"]: if not UserCanvasService.accessible(i, current_user.id): return get_json_result( @@ -67,7 +67,7 @@ async def rm(): @validate_request("dsl", "title") @login_required async def save(): - req = await request_json() + req = await get_request_json() if not isinstance(req["dsl"], str): req["dsl"] = json.dumps(req["dsl"], ensure_ascii=False) req["dsl"] = json.loads(req["dsl"]) @@ -126,7 +126,7 @@ def getsse(canvas_id): @validate_request("id") @login_required async def run(): - req = await request_json() + req = await get_request_json() query = req.get("query", "") files = req.get("files", []) inputs = req.get("inputs", {}) @@ -183,7 +183,7 @@ async def run(): @validate_request("id", "dsl", "component_id") @login_required async def rerun(): - req = await request_json() + req = await get_request_json() doc = PipelineOperationLogService.get_documents_info(req["id"]) if not doc: return get_data_error_result(message="Document not found.") @@ -221,7 +221,7 @@ def cancel(task_id): @validate_request("id") @login_required async def reset(): - req = await request_json() + req = await get_request_json() if not UserCanvasService.accessible(req["id"], current_user.id): return get_json_result( data=False, message='Only owner of canvas authorized for this operation.', @@ -279,7 +279,7 @@ def input_form(): @validate_request("id", "component_id", "params") @login_required async def debug(): - req = await request_json() + req = await get_request_json() if not UserCanvasService.accessible(req["id"], current_user.id): return get_json_result( data=False, message='Only owner of canvas authorized for this operation.', @@ -311,7 +311,7 @@ async def debug(): @validate_request("db_type", "database", "username", "host", "port", "password") @login_required async def test_db_connect(): - req = await request_json() + req = await get_request_json() try: if req["db_type"] in ["mysql", "mariadb"]: db = MySQLDatabase(req["database"], user=req["username"], host=req["host"], port=req["port"], @@ -456,7 +456,7 @@ def list_canvas(): @validate_request("id", "title", "permission") @login_required async def setting(): - req = await request_json() + req = await get_request_json() req["user_id"] = current_user.id if not UserCanvasService.accessible(req["id"], current_user.id): diff --git a/api/apps/chunk_app.py b/api/apps/chunk_app.py index b43fb9af1..d5d928342 100644 --- a/api/apps/chunk_app.py +++ b/api/apps/chunk_app.py @@ -27,7 +27,7 @@ from api.db.services.llm_service import LLMBundle from api.db.services.search_service import SearchService from api.db.services.user_service import UserTenantService from api.utils.api_utils import get_data_error_result, get_json_result, server_error_response, validate_request, \ - request_json + get_request_json from rag.app.qa import beAdoc, rmPrefix from rag.app.tag import label_question from rag.nlp import rag_tokenizer, search @@ -42,7 +42,7 @@ from api.apps import login_required, current_user @login_required @validate_request("doc_id") async def list_chunk(): - req = await request_json() + req = await get_request_json() doc_id = req["doc_id"] page = int(req.get("page", 1)) size = int(req.get("size", 30)) @@ -123,7 +123,7 @@ def get(): @login_required @validate_request("doc_id", "chunk_id", "content_with_weight") async def set(): - req = await request_json() + req = await get_request_json() d = { "id": req["chunk_id"], "content_with_weight": req["content_with_weight"]} @@ -180,7 +180,7 @@ async def set(): @login_required @validate_request("chunk_ids", "available_int", "doc_id") async def switch(): - req = await request_json() + req = await get_request_json() try: e, doc = DocumentService.get_by_id(req["doc_id"]) if not e: @@ -200,7 +200,7 @@ async def switch(): @login_required @validate_request("chunk_ids", "doc_id") async def rm(): - req = await request_json() + req = await get_request_json() try: e, doc = DocumentService.get_by_id(req["doc_id"]) if not e: @@ -224,7 +224,7 @@ async def rm(): @login_required @validate_request("doc_id", "content_with_weight") async def create(): - req = await request_json() + req = await get_request_json() chunck_id = xxhash.xxh64((req["content_with_weight"] + req["doc_id"]).encode("utf-8")).hexdigest() d = {"id": chunck_id, "content_ltks": rag_tokenizer.tokenize(req["content_with_weight"]), "content_with_weight": req["content_with_weight"]} @@ -282,7 +282,7 @@ async def create(): @login_required @validate_request("kb_id", "question") async def retrieval_test(): - req = await request_json() + req = await get_request_json() page = int(req.get("page", 1)) size = int(req.get("size", 30)) question = req["question"] diff --git a/api/apps/connector_app.py b/api/apps/connector_app.py index fb7024757..49d8005a6 100644 --- a/api/apps/connector_app.py +++ b/api/apps/connector_app.py @@ -26,7 +26,7 @@ from google_auth_oauthlib.flow import Flow from api.db import InputType from api.db.services.connector_service import ConnectorService, SyncLogsService -from api.utils.api_utils import get_data_error_result, get_json_result, request_json, validate_request +from api.utils.api_utils import get_data_error_result, get_json_result, get_request_json, validate_request from common.constants import RetCode, TaskStatus from common.data_source.config import GOOGLE_DRIVE_WEB_OAUTH_REDIRECT_URI, GMAIL_WEB_OAUTH_REDIRECT_URI, DocumentSource from common.data_source.google_util.constant import GOOGLE_WEB_OAUTH_POPUP_TEMPLATE, GOOGLE_SCOPES @@ -38,7 +38,7 @@ from api.apps import login_required, current_user @manager.route("/set", methods=["POST"]) # noqa: F821 @login_required async def set_connector(): - req = await request_json() + req = await get_request_json() if req.get("id"): conn = {fld: req[fld] for fld in ["prune_freq", "refresh_freq", "config", "timeout_secs"] if fld in req} ConnectorService.update_by_id(req["id"], conn) @@ -90,7 +90,7 @@ def list_logs(connector_id): @manager.route("//resume", methods=["PUT"]) # noqa: F821 @login_required async def resume(connector_id): - req = await request_json() + req = await get_request_json() if req.get("resume"): ConnectorService.resume(connector_id, TaskStatus.SCHEDULE) else: @@ -102,7 +102,7 @@ async def resume(connector_id): @login_required @validate_request("kb_id") async def rebuild(connector_id): - req = await request_json() + req = await get_request_json() err = ConnectorService.rebuild(req["kb_id"], connector_id, current_user.id) if err: return get_json_result(data=False, message=err, code=RetCode.SERVER_ERROR) @@ -211,7 +211,7 @@ async def start_google_web_oauth(): message="Google OAuth redirect URI is not configured on the server.", ) - req = await request_json() + req = await get_request_json() raw_credentials = req.get("credentials", "") try: diff --git a/api/apps/conversation_app.py b/api/apps/conversation_app.py index 9fecda18a..a2ac131f3 100644 --- a/api/apps/conversation_app.py +++ b/api/apps/conversation_app.py @@ -26,7 +26,7 @@ from api.db.services.llm_service import LLMBundle from api.db.services.search_service import SearchService from api.db.services.tenant_llm_service import TenantLLMService from api.db.services.user_service import TenantService, UserTenantService -from api.utils.api_utils import get_data_error_result, get_json_result, request_json, server_error_response, validate_request +from api.utils.api_utils import get_data_error_result, get_json_result, get_request_json, server_error_response, validate_request from rag.prompts.template import load_prompt from rag.prompts.generator import chunks_format from common.constants import RetCode, LLMType @@ -35,7 +35,7 @@ from common.constants import RetCode, LLMType @manager.route("/set", methods=["POST"]) # noqa: F821 @login_required async def set_conversation(): - req = await request_json() + req = await get_request_json() conv_id = req.get("conversation_id") is_new = req.get("is_new") name = req.get("name", "New conversation") @@ -129,7 +129,7 @@ def getsse(dialog_id): @manager.route("/rm", methods=["POST"]) # noqa: F821 @login_required async def rm(): - req = await request_json() + req = await get_request_json() conv_ids = req["conversation_ids"] try: for cid in conv_ids: @@ -167,7 +167,7 @@ async def list_conversation(): @login_required @validate_request("conversation_id", "messages") async def completion(): - req = await request_json() + req = await get_request_json() msg = [] for m in req["messages"]: if m["role"] == "system": @@ -252,7 +252,7 @@ async def completion(): @manager.route("/tts", methods=["POST"]) # noqa: F821 @login_required async def tts(): - req = await request_json() + req = await get_request_json() text = req["text"] tenants = TenantService.get_info_by(current_user.id) @@ -285,7 +285,7 @@ async def tts(): @login_required @validate_request("conversation_id", "message_id") async def delete_msg(): - req = await request_json() + req = await get_request_json() e, conv = ConversationService.get_by_id(req["conversation_id"]) if not e: return get_data_error_result(message="Conversation not found!") @@ -308,7 +308,7 @@ async def delete_msg(): @login_required @validate_request("conversation_id", "message_id") async def thumbup(): - req = await request_json() + req = await get_request_json() e, conv = ConversationService.get_by_id(req["conversation_id"]) if not e: return get_data_error_result(message="Conversation not found!") @@ -335,7 +335,7 @@ async def thumbup(): @login_required @validate_request("question", "kb_ids") async def ask_about(): - req = await request_json() + req = await get_request_json() uid = current_user.id search_id = req.get("search_id", "") @@ -367,7 +367,7 @@ async def ask_about(): @login_required @validate_request("question", "kb_ids") async def mindmap(): - req = await request_json() + req = await get_request_json() search_id = req.get("search_id", "") search_app = SearchService.get_detail(search_id) if search_id else {} search_config = search_app.get("search_config", {}) if search_app else {} @@ -385,7 +385,7 @@ async def mindmap(): @login_required @validate_request("question") async def related_questions(): - req = await request_json() + req = await get_request_json() search_id = req.get("search_id", "") search_config = {} diff --git a/api/apps/dialog_app.py b/api/apps/dialog_app.py index d5868311b..0f5aebe0b 100644 --- a/api/apps/dialog_app.py +++ b/api/apps/dialog_app.py @@ -21,7 +21,7 @@ from common.constants import StatusEnum from api.db.services.tenant_llm_service import TenantLLMService from api.db.services.knowledgebase_service import KnowledgebaseService from api.db.services.user_service import TenantService, UserTenantService -from api.utils.api_utils import get_data_error_result, get_json_result, request_json, server_error_response, validate_request +from api.utils.api_utils import get_data_error_result, get_json_result, get_request_json, server_error_response, validate_request from common.misc_utils import get_uuid from common.constants import RetCode from api.apps import login_required, current_user @@ -31,7 +31,7 @@ from api.apps import login_required, current_user @validate_request("prompt_config") @login_required async def set_dialog(): - req = await request_json() + req = await get_request_json() dialog_id = req.get("dialog_id", "") is_create = not dialog_id name = req.get("name", "New Dialog") @@ -180,7 +180,7 @@ async def list_dialogs_next(): else: desc = True - req = await request_json() + req = await get_request_json() owner_ids = req.get("owner_ids", []) try: if not owner_ids: @@ -208,7 +208,7 @@ async def list_dialogs_next(): @login_required @validate_request("dialog_ids") async def rm(): - req = await request_json() + req = await get_request_json() dialog_list=[] tenants = UserTenantService.query(user_id=current_user.id) try: diff --git a/api/apps/document_app.py b/api/apps/document_app.py index 16100d395..cbda09e6a 100644 --- a/api/apps/document_app.py +++ b/api/apps/document_app.py @@ -36,7 +36,7 @@ from api.utils.api_utils import ( get_data_error_result, get_json_result, server_error_response, - validate_request, request_json, + validate_request, get_request_json, ) from api.utils.file_utils import filename_type, thumbnail from common.file_utils import get_project_base_directory @@ -153,7 +153,7 @@ async def web_crawl(): @login_required @validate_request("name", "kb_id") async def create(): - req = await request_json() + req = await get_request_json() kb_id = req["kb_id"] if not kb_id: return get_json_result(data=False, message='Lack of "KB ID"', code=RetCode.ARGUMENT_ERROR) @@ -230,7 +230,7 @@ async def list_docs(): create_time_from = int(request.args.get("create_time_from", 0)) create_time_to = int(request.args.get("create_time_to", 0)) - req = await request_json() + req = await get_request_json() run_status = req.get("run_status", []) if run_status: @@ -271,7 +271,7 @@ async def list_docs(): @manager.route("/filter", methods=["POST"]) # noqa: F821 @login_required async def get_filter(): - req = await request_json() + req = await get_request_json() kb_id = req.get("kb_id") if not kb_id: @@ -309,7 +309,7 @@ async def get_filter(): @manager.route("/infos", methods=["POST"]) # noqa: F821 @login_required async def doc_infos(): - req = await request_json() + req = await get_request_json() doc_ids = req["doc_ids"] for doc_id in doc_ids: if not DocumentService.accessible(doc_id, current_user.id): @@ -341,7 +341,7 @@ def thumbnails(): @login_required @validate_request("doc_ids", "status") async def change_status(): - req = await request_json() + req = await get_request_json() doc_ids = req.get("doc_ids", []) status = str(req.get("status", "")) @@ -381,7 +381,7 @@ async def change_status(): @login_required @validate_request("doc_id") async def rm(): - req = await request_json() + req = await get_request_json() doc_ids = req["doc_id"] if isinstance(doc_ids, str): doc_ids = [doc_ids] @@ -402,7 +402,7 @@ async def rm(): @login_required @validate_request("doc_ids", "run") async def run(): - req = await request_json() + req = await get_request_json() for doc_id in req["doc_ids"]: if not DocumentService.accessible(doc_id, current_user.id): return get_json_result(data=False, message="No authorization.", code=RetCode.AUTHENTICATION_ERROR) @@ -449,7 +449,7 @@ async def run(): @login_required @validate_request("doc_id", "name") async def rename(): - req = await request_json() + req = await get_request_json() if not DocumentService.accessible(req["doc_id"], current_user.id): return get_json_result(data=False, message="No authorization.", code=RetCode.AUTHENTICATION_ERROR) try: @@ -539,7 +539,7 @@ async def download_attachment(attachment_id): @validate_request("doc_id") async def change_parser(): - req = await request_json() + req = await get_request_json() if not DocumentService.accessible(req["doc_id"], current_user.id): return get_json_result(data=False, message="No authorization.", code=RetCode.AUTHENTICATION_ERROR) @@ -624,7 +624,7 @@ async def upload_and_parse(): @manager.route("/parse", methods=["POST"]) # noqa: F821 @login_required async def parse(): - req = await request_json() + req = await get_request_json() url = req.get("url", "") if url: if not is_valid_url(url): @@ -680,7 +680,7 @@ async def parse(): @login_required @validate_request("doc_id", "meta") async def set_meta(): - req = await request_json() + req = await get_request_json() if not DocumentService.accessible(req["doc_id"], current_user.id): return get_json_result(data=False, message="No authorization.", code=RetCode.AUTHENTICATION_ERROR) try: diff --git a/api/apps/file2document_app.py b/api/apps/file2document_app.py index d5b378e51..54c314e74 100644 --- a/api/apps/file2document_app.py +++ b/api/apps/file2document_app.py @@ -21,7 +21,7 @@ from api.db.services.file_service import FileService from api.apps import login_required, current_user from api.db.services.knowledgebase_service import KnowledgebaseService -from api.utils.api_utils import get_data_error_result, get_json_result, request_json, server_error_response, validate_request +from api.utils.api_utils import get_data_error_result, get_json_result, get_request_json, server_error_response, validate_request from common.misc_utils import get_uuid from common.constants import RetCode from api.db import FileType @@ -32,7 +32,7 @@ from api.db.services.document_service import DocumentService @login_required @validate_request("file_ids", "kb_ids") async def convert(): - req = await request_json() + req = await get_request_json() kb_ids = req["kb_ids"] file_ids = req["file_ids"] file2documents = [] @@ -102,7 +102,7 @@ async def convert(): @login_required @validate_request("file_ids") async def rm(): - req = await request_json() + req = await get_request_json() file_ids = req["file_ids"] if not file_ids: return get_json_result( diff --git a/api/apps/file_app.py b/api/apps/file_app.py index 953bf6523..bbb5b3ddb 100644 --- a/api/apps/file_app.py +++ b/api/apps/file_app.py @@ -29,7 +29,7 @@ from common.constants import RetCode, FileSource from api.db import FileType from api.db.services import duplicate_name from api.db.services.file_service import FileService -from api.utils.api_utils import get_json_result, request_json +from api.utils.api_utils import get_json_result, get_request_json from api.utils.file_utils import filename_type from api.utils.web_utils import CONTENT_TYPE_MAP from common import settings @@ -124,7 +124,7 @@ async def upload(): @login_required @validate_request("name") async def create(): - req = await request_json() + req = await get_request_json() pf_id = req.get("parent_id") input_file_type = req.get("type") if not pf_id: @@ -239,7 +239,7 @@ def get_all_parent_folders(): @login_required @validate_request("file_ids") async def rm(): - req = await request_json() + req = await get_request_json() file_ids = req["file_ids"] def _delete_single_file(file): @@ -300,7 +300,7 @@ async def rm(): @login_required @validate_request("file_id", "name") async def rename(): - req = await request_json() + req = await get_request_json() try: e, file = FileService.get_by_id(req["file_id"]) if not e: @@ -369,7 +369,7 @@ async def get(file_id): @login_required @validate_request("src_file_ids", "dest_file_id") async def move(): - req = await request_json() + req = await get_request_json() try: file_ids = req["src_file_ids"] dest_parent_id = req["dest_file_id"] diff --git a/api/apps/kb_app.py b/api/apps/kb_app.py index 4e8015d7f..7ff01cc19 100644 --- a/api/apps/kb_app.py +++ b/api/apps/kb_app.py @@ -30,7 +30,7 @@ from api.db.services.pipeline_operation_log_service import PipelineOperationLogS from api.db.services.task_service import TaskService, GRAPH_RAPTOR_FAKE_DOC_ID from api.db.services.user_service import TenantService, UserTenantService from api.utils.api_utils import get_error_data_result, server_error_response, get_data_error_result, validate_request, not_allowed_parameters, \ - request_json + get_request_json from api.db import VALID_FILE_TYPES from api.db.services.knowledgebase_service import KnowledgebaseService from api.db.db_models import File @@ -48,7 +48,7 @@ from api.apps import login_required, current_user @login_required @validate_request("name") async def create(): - req = await request_json() + req = await get_request_json() e, res = KnowledgebaseService.create_with_name( name = req.pop("name", None), tenant_id = current_user.id, @@ -72,7 +72,7 @@ async def create(): @validate_request("kb_id", "name", "description", "parser_id") @not_allowed_parameters("id", "tenant_id", "created_by", "create_time", "update_time", "create_date", "update_date", "created_by") async def update(): - req = await request_json() + req = await get_request_json() if not isinstance(req["name"], str): return get_data_error_result(message="Dataset name must be string.") if req["name"].strip() == "": @@ -182,7 +182,7 @@ async def list_kbs(): else: desc = True - req = await request_json() + req = await get_request_json() owner_ids = req.get("owner_ids", []) try: if not owner_ids: @@ -209,7 +209,7 @@ async def list_kbs(): @login_required @validate_request("kb_id") async def rm(): - req = await request_json() + req = await get_request_json() if not KnowledgebaseService.accessible4deletion(req["kb_id"], current_user.id): return get_json_result( data=False, @@ -286,7 +286,7 @@ def list_tags_from_kbs(): @manager.route('//rm_tags', methods=['POST']) # noqa: F821 @login_required async def rm_tags(kb_id): - req = await request_json() + req = await get_request_json() if not KnowledgebaseService.accessible(kb_id, current_user.id): return get_json_result( data=False, @@ -306,7 +306,7 @@ async def rm_tags(kb_id): @manager.route('//rename_tag', methods=['POST']) # noqa: F821 @login_required async def rename_tags(kb_id): - req = await request_json() + req = await get_request_json() if not KnowledgebaseService.accessible(kb_id, current_user.id): return get_json_result( data=False, @@ -428,7 +428,7 @@ async def list_pipeline_logs(): if create_date_to > create_date_from: return get_data_error_result(message="Create data filter is abnormal.") - req = await request_json() + req = await get_request_json() operation_status = req.get("operation_status", []) if operation_status: @@ -470,7 +470,7 @@ async def list_pipeline_dataset_logs(): if create_date_to > create_date_from: return get_data_error_result(message="Create data filter is abnormal.") - req = await request_json() + req = await get_request_json() operation_status = req.get("operation_status", []) if operation_status: @@ -492,7 +492,7 @@ async def delete_pipeline_logs(): if not kb_id: return get_json_result(data=False, message='Lack of "KB ID"', code=RetCode.ARGUMENT_ERROR) - req = await request_json() + req = await get_request_json() log_ids = req.get("log_ids", []) PipelineOperationLogService.delete_by_ids(log_ids) @@ -517,7 +517,7 @@ def pipeline_log_detail(): @manager.route("/run_graphrag", methods=["POST"]) # noqa: F821 @login_required async def run_graphrag(): - req = await request_json() + req = await get_request_json() kb_id = req.get("kb_id", "") if not kb_id: @@ -586,7 +586,7 @@ def trace_graphrag(): @manager.route("/run_raptor", methods=["POST"]) # noqa: F821 @login_required async def run_raptor(): - req = await request_json() + req = await get_request_json() kb_id = req.get("kb_id", "") if not kb_id: @@ -655,7 +655,7 @@ def trace_raptor(): @manager.route("/run_mindmap", methods=["POST"]) # noqa: F821 @login_required async def run_mindmap(): - req = await request_json() + req = await get_request_json() kb_id = req.get("kb_id", "") if not kb_id: @@ -857,11 +857,11 @@ async def check_embedding(): "question_kwd": full_doc.get("question_kwd") or [] }) return out - + def _clean(s: str) -> str: s = re.sub(r"]{0,12})?>", " ", s or "") return s if s else "None" - req = await request_json() + req = await get_request_json() kb_id = req.get("kb_id", "") embd_id = req.get("embd_id", "") n = int(req.get("check_num", 5)) diff --git a/api/apps/langfuse_app.py b/api/apps/langfuse_app.py index a3e6fde86..8a05c0d4c 100644 --- a/api/apps/langfuse_app.py +++ b/api/apps/langfuse_app.py @@ -20,14 +20,14 @@ from langfuse import Langfuse from api.db.db_models import DB from api.db.services.langfuse_service import TenantLangfuseService -from api.utils.api_utils import get_error_data_result, get_json_result, request_json, server_error_response, validate_request +from api.utils.api_utils import get_error_data_result, get_json_result, get_request_json, server_error_response, validate_request @manager.route("/api_key", methods=["POST", "PUT"]) # noqa: F821 @login_required @validate_request("secret_key", "public_key", "host") async def set_api_key(): - req = await request_json() + req = await get_request_json() secret_key = req.get("secret_key", "") public_key = req.get("public_key", "") host = req.get("host", "") diff --git a/api/apps/llm_app.py b/api/apps/llm_app.py index c4c80b9e1..018fb4bca 100644 --- a/api/apps/llm_app.py +++ b/api/apps/llm_app.py @@ -21,7 +21,7 @@ from quart import request from api.apps import login_required, current_user from api.db.services.tenant_llm_service import LLMFactoriesService, TenantLLMService from api.db.services.llm_service import LLMService -from api.utils.api_utils import get_allowed_llm_factories, get_data_error_result, get_json_result, request_json, server_error_response, validate_request +from api.utils.api_utils import get_allowed_llm_factories, get_data_error_result, get_json_result, get_request_json, server_error_response, validate_request from common.constants import StatusEnum, LLMType from api.db.db_models import TenantLLM from rag.utils.base64_image import test_image @@ -53,7 +53,7 @@ def factories(): @login_required @validate_request("llm_factory", "api_key") async def set_api_key(): - req = await request_json() + req = await get_request_json() # test if api key works chat_passed, embd_passed, rerank_passed = False, False, False factory = req["llm_factory"] @@ -123,7 +123,7 @@ async def set_api_key(): @login_required @validate_request("llm_factory") async def add_llm(): - req = await request_json() + req = await get_request_json() factory = req["llm_factory"] api_key = req.get("api_key", "x") llm_name = req.get("llm_name") @@ -268,7 +268,7 @@ async def add_llm(): @login_required @validate_request("llm_factory", "llm_name") async def delete_llm(): - req = await request_json() + req = await get_request_json() TenantLLMService.filter_delete([TenantLLM.tenant_id == current_user.id, TenantLLM.llm_factory == req["llm_factory"], TenantLLM.llm_name == req["llm_name"]]) return get_json_result(data=True) @@ -277,7 +277,7 @@ async def delete_llm(): @login_required @validate_request("llm_factory", "llm_name") async def enable_llm(): - req = await request_json() + req = await get_request_json() TenantLLMService.filter_update( [TenantLLM.tenant_id == current_user.id, TenantLLM.llm_factory == req["llm_factory"], TenantLLM.llm_name == req["llm_name"]], {"status": str(req.get("status", "1"))} ) @@ -288,7 +288,7 @@ async def enable_llm(): @login_required @validate_request("llm_factory") async def delete_factory(): - req = await request_json() + req = await get_request_json() TenantLLMService.filter_delete([TenantLLM.tenant_id == current_user.id, TenantLLM.llm_factory == req["llm_factory"]]) return get_json_result(data=True) diff --git a/api/apps/mcp_server_app.py b/api/apps/mcp_server_app.py index dec429a09..863aac963 100644 --- a/api/apps/mcp_server_app.py +++ b/api/apps/mcp_server_app.py @@ -22,7 +22,7 @@ from api.db.services.user_service import TenantService from common.constants import RetCode, VALID_MCP_SERVER_TYPES from common.misc_utils import get_uuid -from api.utils.api_utils import get_data_error_result, get_json_result, get_mcp_tools, request_json, server_error_response, validate_request +from api.utils.api_utils import get_data_error_result, get_json_result, get_mcp_tools, get_request_json, server_error_response, validate_request from api.utils.web_utils import get_float, safe_json_parse from common.mcp_tool_call_conn import MCPToolCallSession, close_multiple_mcp_toolcall_sessions @@ -39,7 +39,7 @@ async def list_mcp() -> Response: else: desc = True - req = await request_json() + req = await get_request_json() mcp_ids = req.get("mcp_ids", []) try: servers = MCPServerService.get_servers(current_user.id, mcp_ids, 0, 0, orderby, desc, keywords) or [] @@ -72,7 +72,7 @@ def detail() -> Response: @login_required @validate_request("name", "url", "server_type") async def create() -> Response: - req = await request_json() + req = await get_request_json() server_type = req.get("server_type", "") if server_type not in VALID_MCP_SERVER_TYPES: @@ -127,7 +127,7 @@ async def create() -> Response: @login_required @validate_request("mcp_id") async def update() -> Response: - req = await request_json() + req = await get_request_json() mcp_id = req.get("mcp_id", "") e, mcp_server = MCPServerService.get_by_id(mcp_id) @@ -183,7 +183,7 @@ async def update() -> Response: @login_required @validate_request("mcp_ids") async def rm() -> Response: - req = await request_json() + req = await get_request_json() mcp_ids = req.get("mcp_ids", []) try: @@ -201,7 +201,7 @@ async def rm() -> Response: @login_required @validate_request("mcpServers") async def import_multiple() -> Response: - req = await request_json() + req = await get_request_json() servers = req.get("mcpServers", {}) if not servers: return get_data_error_result(message="No MCP servers provided.") @@ -268,7 +268,7 @@ async def import_multiple() -> Response: @login_required @validate_request("mcp_ids") async def export_multiple() -> Response: - req = await request_json() + req = await get_request_json() mcp_ids = req.get("mcp_ids", []) if not mcp_ids: @@ -300,7 +300,7 @@ async def export_multiple() -> Response: @login_required @validate_request("mcp_ids") async def list_tools() -> Response: - req = await request_json() + req = await get_request_json() mcp_ids = req.get("mcp_ids", []) if not mcp_ids: return get_data_error_result(message="No MCP server IDs provided.") @@ -347,7 +347,7 @@ async def list_tools() -> Response: @login_required @validate_request("mcp_id", "tool_name", "arguments") async def test_tool() -> Response: - req = await request_json() + req = await get_request_json() mcp_id = req.get("mcp_id", "") if not mcp_id: return get_data_error_result(message="No MCP server ID provided.") @@ -380,7 +380,7 @@ async def test_tool() -> Response: @login_required @validate_request("mcp_id", "tools") async def cache_tool() -> Response: - req = await request_json() + req = await get_request_json() mcp_id = req.get("mcp_id", "") if not mcp_id: return get_data_error_result(message="No MCP server ID provided.") @@ -403,7 +403,7 @@ async def cache_tool() -> Response: @manager.route("/test_mcp", methods=["POST"]) # noqa: F821 @validate_request("url", "server_type") async def test_mcp() -> Response: - req = await request_json() + req = await get_request_json() url = req.get("url", "") if not url: diff --git a/api/apps/sdk/agents.py b/api/apps/sdk/agents.py index d9ce86d2f..20e897388 100644 --- a/api/apps/sdk/agents.py +++ b/api/apps/sdk/agents.py @@ -25,7 +25,7 @@ from api.db.services.canvas_service import UserCanvasService from api.db.services.user_canvas_version import UserCanvasVersionService from common.constants import RetCode from common.misc_utils import get_uuid -from api.utils.api_utils import get_data_error_result, get_error_data_result, get_json_result, request_json, token_required +from api.utils.api_utils import get_data_error_result, get_error_data_result, get_json_result, get_request_json, token_required from api.utils.api_utils import get_result from quart import request, Response @@ -53,7 +53,7 @@ def list_agents(tenant_id): @manager.route("/agents", methods=["POST"]) # noqa: F821 @token_required async def create_agent(tenant_id: str): - req: dict[str, Any] = cast(dict[str, Any], await request_json()) + req: dict[str, Any] = cast(dict[str, Any], await get_request_json()) req["user_id"] = tenant_id if req.get("dsl") is not None: @@ -90,7 +90,7 @@ async def create_agent(tenant_id: str): @manager.route("/agents/", methods=["PUT"]) # noqa: F821 @token_required async def update_agent(tenant_id: str, agent_id: str): - req: dict[str, Any] = {k: v for k, v in cast(dict[str, Any], (await request_json())).items() if v is not None} + req: dict[str, Any] = {k: v for k, v in cast(dict[str, Any], (await get_request_json())).items() if v is not None} req["user_id"] = tenant_id if req.get("dsl") is not None: @@ -136,7 +136,7 @@ def delete_agent(tenant_id: str, agent_id: str): @manager.route('/webhook/', methods=['POST']) # noqa: F821 @token_required async def webhook(tenant_id: str, agent_id: str): - req = await request_json() + req = await get_request_json() if not UserCanvasService.accessible(req["id"], tenant_id): return get_json_result( data=False, message='Only owner of canvas authorized for this operation.', diff --git a/api/apps/sdk/chat.py b/api/apps/sdk/chat.py index 0abf7374d..8c9619555 100644 --- a/api/apps/sdk/chat.py +++ b/api/apps/sdk/chat.py @@ -21,13 +21,13 @@ from api.db.services.tenant_llm_service import TenantLLMService from api.db.services.user_service import TenantService from common.misc_utils import get_uuid from common.constants import RetCode, StatusEnum -from api.utils.api_utils import check_duplicate_ids, get_error_data_result, get_result, token_required, request_json +from api.utils.api_utils import check_duplicate_ids, get_error_data_result, get_result, token_required, get_request_json @manager.route("/chats", methods=["POST"]) # noqa: F821 @token_required async def create(tenant_id): - req = await request_json() + req = await get_request_json() ids = [i for i in req.get("dataset_ids", []) if i] for kb_id in ids: kbs = KnowledgebaseService.accessible(kb_id=kb_id, user_id=tenant_id) @@ -146,7 +146,7 @@ async def create(tenant_id): async def update(tenant_id, chat_id): if not DialogService.query(tenant_id=tenant_id, id=chat_id, status=StatusEnum.VALID.value): return get_error_data_result(message="You do not own the chat") - req = await request_json() + req = await get_request_json() ids = req.get("dataset_ids", []) if "show_quotation" in req: req["do_refer"] = req.pop("show_quotation") @@ -229,7 +229,7 @@ async def update(tenant_id, chat_id): async def delete_chats(tenant_id): errors = [] success_count = 0 - req = await request_json() + req = await get_request_json() if not req: ids = None else: diff --git a/api/apps/sdk/dify_retrieval.py b/api/apps/sdk/dify_retrieval.py index 4ddbf9a74..9665754eb 100644 --- a/api/apps/sdk/dify_retrieval.py +++ b/api/apps/sdk/dify_retrieval.py @@ -20,7 +20,7 @@ from quart import jsonify from api.db.services.document_service import DocumentService from api.db.services.knowledgebase_service import KnowledgebaseService from api.db.services.llm_service import LLMBundle -from api.utils.api_utils import apikey_required, build_error_result, request_json, validate_request +from api.utils.api_utils import apikey_required, build_error_result, get_request_json, validate_request from rag.app.tag import label_question from api.db.services.dialog_service import meta_filter, convert_conditions from common.constants import RetCode, LLMType @@ -113,7 +113,7 @@ async def retrieval(tenant_id): 404: description: Knowledge base or document not found """ - req = await request_json() + req = await get_request_json() question = req["query"] kb_id = req["knowledge_id"] use_kg = req.get("use_kg", False) diff --git a/api/apps/sdk/doc.py b/api/apps/sdk/doc.py index aebf925cc..0a007f148 100644 --- a/api/apps/sdk/doc.py +++ b/api/apps/sdk/doc.py @@ -36,7 +36,7 @@ from api.db.services.tenant_llm_service import TenantLLMService from api.db.services.task_service import TaskService, queue_tasks from api.db.services.dialog_service import meta_filter, convert_conditions from api.utils.api_utils import check_duplicate_ids, construct_json_result, get_error_data_result, get_parser_config, get_result, server_error_response, token_required, \ - request_json + get_request_json from rag.app.qa import beAdoc, rmPrefix from rag.app.tag import label_question from rag.nlp import rag_tokenizer, search @@ -231,7 +231,7 @@ async def update_doc(tenant_id, dataset_id, document_id): schema: type: object """ - req = await request_json() + req = await get_request_json() if not KnowledgebaseService.query(id=dataset_id, tenant_id=tenant_id): return get_error_data_result(message="You don't own the dataset.") e, kb = KnowledgebaseService.get_by_id(dataset_id) @@ -536,7 +536,7 @@ def list_docs(dataset_id, tenant_id): return get_error_data_result(message=f"You don't own the dataset {dataset_id}. ") q = request.args - document_id = q.get("id") + document_id = q.get("id") name = q.get("name") if document_id and not DocumentService.query(id=document_id, kb_id=dataset_id): @@ -545,16 +545,16 @@ def list_docs(dataset_id, tenant_id): return get_error_data_result(message=f"You don't own the document {name}.") page = int(q.get("page", 1)) - page_size = int(q.get("page_size", 30)) + page_size = int(q.get("page_size", 30)) orderby = q.get("orderby", "create_time") desc = str(q.get("desc", "true")).strip().lower() != "false" keywords = q.get("keywords", "") # filters - align with OpenAPI parameter names - suffix = q.getlist("suffix") - run_status = q.getlist("run") - create_time_from = int(q.get("create_time_from", 0)) - create_time_to = int(q.get("create_time_to", 0)) + suffix = q.getlist("suffix") + run_status = q.getlist("run") + create_time_from = int(q.get("create_time_from", 0)) + create_time_to = int(q.get("create_time_to", 0)) # map run status (accept text or numeric) - align with API parameter run_status_text_to_numeric = {"UNSTART": "0", "RUNNING": "1", "CANCEL": "2", "DONE": "3", "FAIL": "4"} @@ -575,7 +575,7 @@ def list_docs(dataset_id, tenant_id): # rename keys + map run status back to text for output key_mapping = { "chunk_num": "chunk_count", - "kb_id": "dataset_id", + "kb_id": "dataset_id", "token_num": "token_count", "parser_id": "chunk_method", } @@ -631,7 +631,7 @@ async def delete(tenant_id, dataset_id): """ if not KnowledgebaseService.accessible(kb_id=dataset_id, user_id=tenant_id): return get_error_data_result(message=f"You don't own the dataset {dataset_id}. ") - req = await request_json() + req = await get_request_json() if not req: doc_ids = None else: @@ -741,7 +741,7 @@ async def parse(tenant_id, dataset_id): """ if not KnowledgebaseService.accessible(kb_id=dataset_id, user_id=tenant_id): return get_error_data_result(message=f"You don't own the dataset {dataset_id}.") - req = await request_json() + req = await get_request_json() if not req.get("document_ids"): return get_error_data_result("`document_ids` is required") doc_list = req.get("document_ids") @@ -824,7 +824,7 @@ async def stop_parsing(tenant_id, dataset_id): """ if not KnowledgebaseService.accessible(kb_id=dataset_id, user_id=tenant_id): return get_error_data_result(message=f"You don't own the dataset {dataset_id}.") - req = await request_json() + req = await get_request_json() if not req.get("document_ids"): return get_error_data_result("`document_ids` is required") @@ -1096,7 +1096,7 @@ async def add_chunk(tenant_id, dataset_id, document_id): if not doc: return get_error_data_result(message=f"You don't own the document {document_id}.") doc = doc[0] - req = await request_json() + req = await get_request_json() if not str(req.get("content", "")).strip(): return get_error_data_result(message="`content` is required") if "important_keywords" in req: @@ -1202,7 +1202,7 @@ async def rm_chunk(tenant_id, dataset_id, document_id): docs = DocumentService.get_by_ids([document_id]) if not docs: raise LookupError(f"Can't find the document with ID {document_id}!") - req = await request_json() + req = await get_request_json() condition = {"doc_id": document_id} if "chunk_ids" in req: unique_chunk_ids, duplicate_messages = check_duplicate_ids(req["chunk_ids"], "chunk") @@ -1288,7 +1288,7 @@ async def update_chunk(tenant_id, dataset_id, document_id, chunk_id): if not doc: return get_error_data_result(message=f"You don't own the document {document_id}.") doc = doc[0] - req = await request_json() + req = await get_request_json() if "content" in req and req["content"] is not None: content = req["content"] else: @@ -1411,7 +1411,7 @@ async def retrieval_test(tenant_id): format: float description: Similarity score. """ - req = await request_json() + req = await get_request_json() if not req.get("dataset_ids"): return get_error_data_result("`dataset_ids` is required.") kb_ids = req["dataset_ids"] diff --git a/api/apps/sdk/files.py b/api/apps/sdk/files.py index d67f1d072..fde3befa8 100644 --- a/api/apps/sdk/files.py +++ b/api/apps/sdk/files.py @@ -23,7 +23,7 @@ from pathlib import Path from api.db.services.document_service import DocumentService from api.db.services.file2document_service import File2DocumentService from api.db.services.knowledgebase_service import KnowledgebaseService -from api.utils.api_utils import get_json_result, request_json, server_error_response, token_required +from api.utils.api_utils import get_json_result, get_request_json, server_error_response, token_required from common.misc_utils import get_uuid from api.db import FileType from api.db.services import duplicate_name @@ -192,7 +192,7 @@ async def create(tenant_id): type: type: string """ - req = await request_json() + req = await get_request_json() pf_id = req.get("parent_id") input_file_type = req.get("type") if not pf_id: @@ -480,7 +480,7 @@ async def rm(tenant_id): type: boolean example: true """ - req = await request_json() + req = await get_request_json() file_ids = req["file_ids"] try: for file_id in file_ids: @@ -555,7 +555,7 @@ async def rename(tenant_id): type: boolean example: true """ - req = await request_json() + req = await get_request_json() try: e, file = FileService.get_by_id(req["file_id"]) if not e: @@ -666,7 +666,7 @@ async def move(tenant_id): type: boolean example: true """ - req = await request_json() + req = await get_request_json() try: file_ids = req["src_file_ids"] parent_id = req["dest_file_id"] @@ -693,7 +693,7 @@ async def move(tenant_id): @manager.route('/file/convert', methods=['POST']) # noqa: F821 @token_required async def convert(tenant_id): - req = await request_json() + req = await get_request_json() kb_ids = req["kb_ids"] file_ids = req["file_ids"] file2documents = [] diff --git a/api/apps/sdk/session.py b/api/apps/sdk/session.py index 138833936..6276877a2 100644 --- a/api/apps/sdk/session.py +++ b/api/apps/sdk/session.py @@ -35,7 +35,7 @@ from api.db.services.search_service import SearchService from api.db.services.user_service import UserTenantService from common.misc_utils import get_uuid from api.utils.api_utils import check_duplicate_ids, get_data_openai, get_error_data_result, get_json_result, \ - get_result, request_json, server_error_response, token_required, validate_request + get_result, get_request_json, server_error_response, token_required, validate_request from rag.app.tag import label_question from rag.prompts.template import load_prompt from rag.prompts.generator import cross_languages, gen_meta_filter, keyword_extraction, chunks_format @@ -45,7 +45,7 @@ from common import settings @manager.route("/chats//sessions", methods=["POST"]) # noqa: F821 @token_required async def create(tenant_id, chat_id): - req = await request_json() + req = await get_request_json() req["dialog_id"] = chat_id dia = DialogService.query(tenant_id=tenant_id, id=req["dialog_id"], status=StatusEnum.VALID.value) if not dia: @@ -98,7 +98,7 @@ async def create_agent_session(tenant_id, agent_id): @manager.route("/chats//sessions/", methods=["PUT"]) # noqa: F821 @token_required async def update(tenant_id, chat_id, session_id): - req = await request_json() + req = await get_request_json() req["dialog_id"] = chat_id conv_id = session_id conv = ConversationService.query(id=conv_id, dialog_id=chat_id) @@ -120,7 +120,7 @@ async def update(tenant_id, chat_id, session_id): @manager.route("/chats//completions", methods=["POST"]) # noqa: F821 @token_required async def chat_completion(tenant_id, chat_id): - req = await request_json() + req = await get_request_json() if not req: req = {"question": ""} if not req.get("session_id"): @@ -206,7 +206,7 @@ async def chat_completion_openai_like(tenant_id, chat_id): if reference: print(completion.choices[0].message.reference) """ - req = await request_json() + req = await get_request_json() need_reference = bool(req.get("reference", False)) @@ -384,7 +384,7 @@ async def chat_completion_openai_like(tenant_id, chat_id): @validate_request("model", "messages") # noqa: F821 @token_required async def agents_completion_openai_compatibility(tenant_id, agent_id): - req = await request_json() + req = await get_request_json() tiktokenenc = tiktoken.get_encoding("cl100k_base") messages = req.get("messages", []) if not messages: @@ -442,7 +442,7 @@ async def agents_completion_openai_compatibility(tenant_id, agent_id): @manager.route("/agents//completions", methods=["POST"]) # noqa: F821 @token_required async def agent_completions(tenant_id, agent_id): - req = await request_json() + req = await get_request_json() if req.get("stream", True): @@ -614,7 +614,7 @@ async def delete(tenant_id, chat_id): errors = [] success_count = 0 - req = await request_json() + req = await get_request_json() convs = ConversationService.query(dialog_id=chat_id) if not req: ids = None @@ -662,7 +662,7 @@ async def delete(tenant_id, chat_id): async def delete_agent_session(tenant_id, agent_id): errors = [] success_count = 0 - req = await request_json() + req = await get_request_json() cvs = UserCanvasService.query(user_id=tenant_id, id=agent_id) if not cvs: return get_error_data_result(f"You don't own the agent {agent_id}") @@ -715,7 +715,7 @@ async def delete_agent_session(tenant_id, agent_id): @manager.route("/sessions/ask", methods=["POST"]) # noqa: F821 @token_required async def ask_about(tenant_id): - req = await request_json() + req = await get_request_json() if not req.get("question"): return get_error_data_result("`question` is required.") if not req.get("dataset_ids"): @@ -754,7 +754,7 @@ async def ask_about(tenant_id): @manager.route("/sessions/related_questions", methods=["POST"]) # noqa: F821 @token_required async def related_questions(tenant_id): - req = await request_json() + req = await get_request_json() if not req.get("question"): return get_error_data_result("`question` is required.") question = req["question"] @@ -805,7 +805,7 @@ Related search terms: @manager.route("/chatbots//completions", methods=["POST"]) # noqa: F821 async def chatbot_completions(dialog_id): - req = await request_json() + req = await get_request_json() token = request.headers.get("Authorization").split() if len(token) != 2: @@ -855,7 +855,7 @@ async def chatbots_inputs(dialog_id): @manager.route("/agentbots//completions", methods=["POST"]) # noqa: F821 async def agent_bot_completions(agent_id): - req = await request_json() + req = await get_request_json() token = request.headers.get("Authorization").split() if len(token) != 2: @@ -908,7 +908,7 @@ async def ask_about_embedded(): if not objs: return get_error_data_result(message='Authentication error: API key is invalid!"') - req = await request_json() + req = await get_request_json() uid = objs[0].tenant_id search_id = req.get("search_id", "") @@ -947,7 +947,7 @@ async def retrieval_test_embedded(): if not objs: return get_error_data_result(message='Authentication error: API key is invalid!"') - req = await request_json() + req = await get_request_json() page = int(req.get("page", 1)) size = int(req.get("size", 30)) question = req["question"] @@ -1046,7 +1046,7 @@ async def related_questions_embedded(): if not objs: return get_error_data_result(message='Authentication error: API key is invalid!"') - req = await request_json() + req = await get_request_json() tenant_id = objs[0].tenant_id if not tenant_id: return get_error_data_result(message="permission denined.") @@ -1123,7 +1123,7 @@ async def mindmap(): return get_error_data_result(message='Authentication error: API key is invalid!"') tenant_id = objs[0].tenant_id - req = await request_json() + req = await get_request_json() search_id = req.get("search_id", "") search_app = SearchService.get_detail(search_id) if search_id else {} diff --git a/api/apps/search_app.py b/api/apps/search_app.py index 3b0da3fe1..d82c3b27d 100644 --- a/api/apps/search_app.py +++ b/api/apps/search_app.py @@ -24,14 +24,14 @@ from api.db.services.search_service import SearchService from api.db.services.user_service import TenantService, UserTenantService from common.misc_utils import get_uuid from common.constants import RetCode, StatusEnum -from api.utils.api_utils import get_data_error_result, get_json_result, not_allowed_parameters, request_json, server_error_response, validate_request +from api.utils.api_utils import get_data_error_result, get_json_result, not_allowed_parameters, get_request_json, server_error_response, validate_request @manager.route("/create", methods=["post"]) # noqa: F821 @login_required @validate_request("name") async def create(): - req = await request_json() + req = await get_request_json() search_name = req["name"] description = req.get("description", "") if not isinstance(search_name, str): @@ -66,7 +66,7 @@ async def create(): @validate_request("search_id", "name", "search_config", "tenant_id") @not_allowed_parameters("id", "created_by", "create_time", "update_time", "create_date", "update_date", "created_by") async def update(): - req = await request_json() + req = await get_request_json() if not isinstance(req["name"], str): return get_data_error_result(message="Search name must be string.") if req["name"].strip() == "": @@ -150,7 +150,7 @@ async def list_search_app(): else: desc = True - req = await request_json() + req = await get_request_json() owner_ids = req.get("owner_ids", []) try: if not owner_ids: @@ -174,7 +174,7 @@ async def list_search_app(): @login_required @validate_request("search_id") async def rm(): - req = await request_json() + req = await get_request_json() search_id = req["search_id"] if not SearchService.accessible4deletion(search_id, current_user.id): return get_json_result(data=False, message="No authorization.", code=RetCode.AUTHENTICATION_ERROR) diff --git a/api/apps/tenant_app.py b/api/apps/tenant_app.py index 837c812c1..fdb764e65 100644 --- a/api/apps/tenant_app.py +++ b/api/apps/tenant_app.py @@ -21,7 +21,7 @@ from api.db.services.user_service import UserTenantService, UserService from common.constants import RetCode, StatusEnum from common.misc_utils import get_uuid from common.time_utils import delta_seconds -from api.utils.api_utils import get_data_error_result, get_json_result, request_json, server_error_response, validate_request +from api.utils.api_utils import get_data_error_result, get_json_result, get_request_json, server_error_response, validate_request from api.utils.web_utils import send_invite_email from common import settings from api.apps import smtp_mail_server, login_required, current_user @@ -55,7 +55,7 @@ async def create(tenant_id): message='No authorization.', code=RetCode.AUTHENTICATION_ERROR) - req = await request_json() + req = await get_request_json() invite_user_email = req["email"] invite_users = UserService.query(email=invite_user_email) if not invite_users: diff --git a/api/apps/user_app.py b/api/apps/user_app.py index 4b32e59d5..78407b242 100644 --- a/api/apps/user_app.py +++ b/api/apps/user_app.py @@ -39,7 +39,7 @@ from common.connection_utils import construct_response from api.utils.api_utils import ( get_data_error_result, get_json_result, - request_json, + get_request_json, server_error_response, validate_request, ) @@ -92,7 +92,7 @@ async def login(): schema: type: object """ - json_body = await request_json() + json_body = await get_request_json() if not json_body: return get_json_result(data=False, code=RetCode.AUTHENTICATION_ERROR, message="Unauthorized!") @@ -536,7 +536,7 @@ async def setting_user(): type: object """ update_dict = {} - request_data = await request_json() + request_data = await get_request_json() if request_data.get("password"): new_password = request_data.get("new_password") if not check_password_hash(current_user.password, decrypt(request_data["password"])): @@ -703,7 +703,7 @@ async def user_add(): code=RetCode.OPERATING_ERROR, ) - req = await request_json() + req = await get_request_json() email_address = req["email"] # Validate the email address @@ -836,7 +836,7 @@ async def set_tenant_info(): schema: type: object """ - req = await request_json() + req = await get_request_json() try: tid = req.pop("tenant_id") TenantService.update_by_id(tid, req) @@ -880,7 +880,7 @@ async def forget_send_otp(): - Verify the image captcha stored at captcha:{email} (case-insensitive). - On success, generate an email OTP (A–Z with length = OTP_LENGTH), store hash + salt (and timestamp) in Redis with TTL, reset attempts and cooldown, and send the OTP via email. """ - req = await request_json() + req = await get_request_json() email = req.get("email") or "" captcha = (req.get("captcha") or "").strip() @@ -946,7 +946,7 @@ async def forget(): POST: Verify email + OTP and reset password, then log the user in. Request JSON: { email, otp, new_password, confirm_new_password } """ - req = await request_json() + req = await get_request_json() email = req.get("email") or "" otp = (req.get("otp") or "").strip() new_pwd = req.get("new_password") diff --git a/api/utils/api_utils.py b/api/utils/api_utils.py index d3bfdb920..c23d03a22 100644 --- a/api/utils/api_utils.py +++ b/api/utils/api_utils.py @@ -58,7 +58,7 @@ async def _coerce_request_data() -> dict: return payload or {} -async def request_json(): +async def get_request_json(): return await _coerce_request_data() def serialize_for_json(obj):