pull/21891/head
ytqh 1 year ago
parent b7916227e2
commit 085992e617

@ -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:

@ -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.
---

@ -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.
---

@ -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.

@ -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.

@ -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.
---

@ -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:

@ -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):

Loading…
Cancel
Save