From 085992e617538b8030678509fcaf15340fe83490 Mon Sep 17 00:00:00 2001 From: ytqh Date: Sun, 2 Mar 2025 13:29:48 +0800 Subject: [PATCH] fix --- api/controllers/service_api_with_auth/app/app.py | 16 ++++++++-------- .../service_api_with_auth/app/audio.py | 6 +++--- .../service_api_with_auth/app/completion.py | 10 +++++----- .../service_api_with_auth/app/conversation.py | 8 ++++---- .../service_api_with_auth/app/file.py | 4 ++-- .../service_api_with_auth/app/message.py | 8 ++++---- .../service_api_with_auth/app/workflow.py | 14 +++++++------- api/controllers/service_api_with_auth/wraps.py | 2 +- 8 files changed, 34 insertions(+), 34 deletions(-) diff --git a/api/controllers/service_api_with_auth/app/app.py b/api/controllers/service_api_with_auth/app/app.py index 7fe73d4f0c..8239b88de8 100644 --- a/api/controllers/service_api_with_auth/app/app.py +++ b/api/controllers/service_api_with_auth/app/app.py @@ -2,18 +2,18 @@ from controllers.common import fields from controllers.common import helpers as controller_helpers from controllers.service_api_with_auth import api from controllers.service_api_with_auth.app.error import AppUnavailableError -from controllers.service_api_with_auth.wraps import validate_app_token +from controllers.service_api_with_auth.wraps import validate_user_token_and_extract_info from flask_restful import Resource, marshal_with # type: ignore -from models.model import App, AppMode +from models.model import App, AppMode, EndUser from services.app_service import AppService class AppParameterApi(Resource): """Resource for app variables.""" - @validate_app_token + @validate_user_token_and_extract_info @marshal_with(fields.parameters_fields) - def get(self, app_model: App): + def get(self, app_model: App, end_user: EndUser): """Retrieve app parameters. --- tags: @@ -56,8 +56,8 @@ class AppParameterApi(Resource): class AppMetaApi(Resource): - @validate_app_token - def get(self, app_model: App): + @validate_user_token_and_extract_info + def get(self, app_model: App, end_user: EndUser): """Get app meta information. --- tags: @@ -78,8 +78,8 @@ class AppMetaApi(Resource): class AppInfoApi(Resource): - @validate_app_token - def get(self, app_model: App): + @validate_user_token_and_extract_info + def get(self, app_model: App, end_user: EndUser): """Get app information. --- tags: diff --git a/api/controllers/service_api_with_auth/app/audio.py b/api/controllers/service_api_with_auth/app/audio.py index 03b6bbb2d3..2387a79e27 100644 --- a/api/controllers/service_api_with_auth/app/audio.py +++ b/api/controllers/service_api_with_auth/app/audio.py @@ -13,7 +13,7 @@ from controllers.service_api_with_auth.app.error import ( ProviderQuotaExceededError, UnsupportedAudioTypeError, ) -from controllers.service_api_with_auth.wraps import validate_app_token +from controllers.service_api_with_auth.wraps import validate_user_token_and_extract_info from core.errors.error import ModelCurrentlyNotSupportError, ProviderTokenNotInitError, QuotaExceededError from core.model_runtime.errors.invoke import InvokeError from flask import request @@ -30,7 +30,7 @@ from werkzeug.exceptions import InternalServerError class AudioApi(Resource): - @validate_app_token + @validate_user_token_and_extract_info def post(self, app_model: App, end_user: EndUser): """Transcribe audio to text. --- @@ -99,7 +99,7 @@ class AudioApi(Resource): class TextApi(Resource): - @validate_app_token + @validate_user_token_and_extract_info def post(self, app_model: App, end_user: EndUser): """Convert text to speech. --- diff --git a/api/controllers/service_api_with_auth/app/completion.py b/api/controllers/service_api_with_auth/app/completion.py index df964cfd65..f0ec984ce0 100644 --- a/api/controllers/service_api_with_auth/app/completion.py +++ b/api/controllers/service_api_with_auth/app/completion.py @@ -11,7 +11,7 @@ from controllers.service_api_with_auth.app.error import ( ProviderNotInitializeError, ProviderQuotaExceededError, ) -from controllers.service_api_with_auth.wraps import FetchUserArg, WhereisUserArg, validate_app_token +from controllers.service_api_with_auth.wraps import FetchUserArg, WhereisUserArg, validate_user_token_and_extract_info from core.app.apps.base_app_queue_manager import AppQueueManager from core.app.entities.app_invoke_entities import InvokeFrom from core.errors.error import ModelCurrentlyNotSupportError, ProviderTokenNotInitError, QuotaExceededError @@ -26,7 +26,7 @@ from werkzeug.exceptions import InternalServerError, NotFound class CompletionApi(Resource): - @validate_app_token + @validate_user_token_and_extract_info def post(self, app_model: App, end_user: EndUser): """Generate completion response. --- @@ -121,7 +121,7 @@ class CompletionApi(Resource): class CompletionStopApi(Resource): - @validate_app_token + @validate_user_token_and_extract_info def post(self, app_model: App, end_user: EndUser, task_id): """Stop a running completion task. --- @@ -160,7 +160,7 @@ class CompletionStopApi(Resource): class ChatApi(Resource): - @validate_app_token + @validate_user_token_and_extract_info def post(self, app_model: App, end_user: EndUser): """Generate chat response. --- @@ -261,7 +261,7 @@ class ChatApi(Resource): class ChatStopApi(Resource): - @validate_app_token + @validate_user_token_and_extract_info def post(self, app_model: App, end_user: EndUser, task_id): """Stop a running chat task. --- diff --git a/api/controllers/service_api_with_auth/app/conversation.py b/api/controllers/service_api_with_auth/app/conversation.py index a652d62b99..849bdb3f6b 100644 --- a/api/controllers/service_api_with_auth/app/conversation.py +++ b/api/controllers/service_api_with_auth/app/conversation.py @@ -1,7 +1,7 @@ import services from controllers.service_api_with_auth import api from controllers.service_api_with_auth.app.error import NotChatAppError -from controllers.service_api_with_auth.wraps import FetchUserArg, WhereisUserArg, validate_app_token +from controllers.service_api_with_auth.wraps import FetchUserArg, WhereisUserArg, validate_user_token_and_extract_info from core.app.entities.app_invoke_entities import InvokeFrom from extensions.ext_database import db from fields.conversation_fields import ( @@ -19,7 +19,7 @@ from werkzeug.exceptions import NotFound class ConversationApi(Resource): - @validate_app_token + @validate_user_token_and_extract_info @marshal_with(conversation_infinite_scroll_pagination_fields) def get(self, app_model: App, end_user: EndUser): """Get conversations list. @@ -99,7 +99,7 @@ class ConversationApi(Resource): class ConversationDetailApi(Resource): - @validate_app_token + @validate_user_token_and_extract_info @marshal_with(conversation_delete_fields) def delete(self, app_model: App, end_user: EndUser, c_id): """Delete a conversation. @@ -145,7 +145,7 @@ class ConversationDetailApi(Resource): class ConversationRenameApi(Resource): - @validate_app_token + @validate_user_token_and_extract_info @marshal_with(simple_conversation_fields) def post(self, app_model: App, end_user: EndUser, c_id): """Rename a conversation. diff --git a/api/controllers/service_api_with_auth/app/file.py b/api/controllers/service_api_with_auth/app/file.py index 94c7e692b5..0949c5941d 100644 --- a/api/controllers/service_api_with_auth/app/file.py +++ b/api/controllers/service_api_with_auth/app/file.py @@ -7,7 +7,7 @@ from controllers.service_api_with_auth.app.error import ( TooManyFilesError, UnsupportedFileTypeError, ) -from controllers.service_api_with_auth.wraps import FetchUserArg, WhereisUserArg, validate_app_token +from controllers.service_api_with_auth.wraps import FetchUserArg, WhereisUserArg, validate_user_token_and_extract_info from fields.file_fields import file_fields from flask import request from flask_restful import Resource, marshal_with # type: ignore @@ -16,7 +16,7 @@ from services.file_service import FileService class FileApi(Resource): - @validate_app_token + @validate_user_token_and_extract_info @marshal_with(file_fields) def post(self, app_model: App, end_user: EndUser): """Upload a file. diff --git a/api/controllers/service_api_with_auth/app/message.py b/api/controllers/service_api_with_auth/app/message.py index 1c66bd44a9..0d57b69c45 100644 --- a/api/controllers/service_api_with_auth/app/message.py +++ b/api/controllers/service_api_with_auth/app/message.py @@ -3,7 +3,7 @@ import logging import services from controllers.service_api_with_auth import api from controllers.service_api_with_auth.app.error import NotChatAppError -from controllers.service_api_with_auth.wraps import FetchUserArg, WhereisUserArg, validate_app_token +from controllers.service_api_with_auth.wraps import FetchUserArg, WhereisUserArg, validate_user_token_and_extract_info from core.app.entities.app_invoke_entities import InvokeFrom from fields.conversation_fields import message_file_fields from fields.raws import FilesContainedField @@ -73,7 +73,7 @@ class MessageListApi(Resource): "data": fields.List(fields.Nested(message_fields)), } - @validate_app_token + @validate_user_token_and_extract_info @marshal_with(message_infinite_scroll_pagination_fields) def get(self, app_model: App, end_user: EndUser): """Get messages list. @@ -145,7 +145,7 @@ class MessageListApi(Resource): class MessageFeedbackApi(Resource): - @validate_app_token + @validate_user_token_and_extract_info def post(self, app_model: App, end_user: EndUser, message_id): """Submit feedback for a message. --- @@ -215,7 +215,7 @@ class MessageFeedbackApi(Resource): class MessageSuggestedApi(Resource): - @validate_app_token + @validate_user_token_and_extract_info def get(self, app_model: App, end_user: EndUser, message_id): """Get suggested questions for a message. --- diff --git a/api/controllers/service_api_with_auth/app/workflow.py b/api/controllers/service_api_with_auth/app/workflow.py index 7de44df751..b772ba8bab 100644 --- a/api/controllers/service_api_with_auth/app/workflow.py +++ b/api/controllers/service_api_with_auth/app/workflow.py @@ -8,7 +8,7 @@ from controllers.service_api_with_auth.app.error import ( ProviderNotInitializeError, ProviderQuotaExceededError, ) -from controllers.service_api_with_auth.wraps import FetchUserArg, WhereisUserArg, validate_app_token +from controllers.service_api_with_auth.wraps import FetchUserArg, WhereisUserArg, validate_user_token_and_extract_info from core.app.apps.base_app_queue_manager import AppQueueManager from core.app.entities.app_invoke_entities import InvokeFrom from core.errors.error import ModelCurrentlyNotSupportError, ProviderTokenNotInitError, QuotaExceededError @@ -42,9 +42,9 @@ workflow_run_fields = { class WorkflowRunDetailApi(Resource): - @validate_app_token + @validate_user_token_and_extract_info @marshal_with(workflow_run_fields) - def get(self, app_model: App, workflow_id: str): + def get(self, app_model: App, end_user: EndUser, workflow_id: str): """Get workflow run details. --- tags: @@ -104,7 +104,7 @@ class WorkflowRunDetailApi(Resource): class WorkflowRunApi(Resource): - @validate_app_token + @validate_user_token_and_extract_info def post(self, app_model: App, end_user: EndUser): """Run a workflow. --- @@ -174,7 +174,7 @@ class WorkflowRunApi(Resource): class WorkflowTaskStopApi(Resource): - @validate_app_token + @validate_user_token_and_extract_info def post(self, app_model: App, end_user: EndUser, task_id: str): """Stop a running workflow task. --- @@ -214,9 +214,9 @@ class WorkflowTaskStopApi(Resource): class WorkflowAppLogApi(Resource): - @validate_app_token + @validate_user_token_and_extract_info @marshal_with(workflow_app_log_pagination_fields) - def get(self, app_model: App): + def get(self, app_model: App, end_user: EndUser): """Get workflow app logs. --- tags: diff --git a/api/controllers/service_api_with_auth/wraps.py b/api/controllers/service_api_with_auth/wraps.py index 1b44f55051..45625016c5 100644 --- a/api/controllers/service_api_with_auth/wraps.py +++ b/api/controllers/service_api_with_auth/wraps.py @@ -35,7 +35,7 @@ class FetchUserArg(BaseModel): required: bool = False -def validate_app_token(view: Optional[Callable] = None): +def validate_user_token_and_extract_info(view: Optional[Callable] = None): def decorator(view_func): @wraps(view_func) def decorated_view(*args, **kwargs):