Co-authored-by: Yongtao Huang <99629139+hyongtao-db@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>tags/1.8.0
| from werkzeug.exceptions import HTTPException | from werkzeug.exceptions import HTTPException | ||||
| from libs.exception import BaseHTTPException | |||||
| class FilenameNotExistsError(HTTPException): | class FilenameNotExistsError(HTTPException): | ||||
| code = 400 | code = 400 | ||||
| class RemoteFileUploadError(HTTPException): | class RemoteFileUploadError(HTTPException): | ||||
| code = 400 | code = 400 | ||||
| description = "Error uploading remote file." | description = "Error uploading remote file." | ||||
| class FileTooLargeError(BaseHTTPException): | |||||
| error_code = "file_too_large" | |||||
| description = "File size exceeded. {message}" | |||||
| code = 413 | |||||
| class UnsupportedFileTypeError(BaseHTTPException): | |||||
| error_code = "unsupported_file_type" | |||||
| description = "File type not allowed." | |||||
| code = 415 | |||||
| class TooManyFilesError(BaseHTTPException): | |||||
| error_code = "too_many_files" | |||||
| description = "Only one file is allowed." | |||||
| code = 400 | |||||
| class NoFileUploadedError(BaseHTTPException): | |||||
| error_code = "no_file_uploaded" | |||||
| description = "Please upload your file." | |||||
| code = 400 |
| from flask_restful import Resource, marshal, marshal_with, reqparse | from flask_restful import Resource, marshal, marshal_with, reqparse | ||||
| from werkzeug.exceptions import Forbidden | from werkzeug.exceptions import Forbidden | ||||
| from controllers.common.errors import NoFileUploadedError, TooManyFilesError | |||||
| from controllers.console import api | from controllers.console import api | ||||
| from controllers.console.app.error import NoFileUploadedError | |||||
| from controllers.console.datasets.error import TooManyFilesError | |||||
| from controllers.console.wraps import ( | from controllers.console.wraps import ( | ||||
| account_initialization_required, | account_initialization_required, | ||||
| cloud_edition_billing_resource_check, | cloud_edition_billing_resource_check, |
| code = 400 | code = 400 | ||||
| class NoFileUploadedError(BaseHTTPException): | |||||
| error_code = "no_file_uploaded" | |||||
| description = "Please upload your file." | |||||
| code = 400 | |||||
| class TooManyFilesError(BaseHTTPException): | |||||
| error_code = "too_many_files" | |||||
| description = "Only one file is allowed." | |||||
| code = 400 | |||||
| class DraftWorkflowNotExist(BaseHTTPException): | class DraftWorkflowNotExist(BaseHTTPException): | ||||
| error_code = "draft_workflow_not_exist" | error_code = "draft_workflow_not_exist" | ||||
| description = "Draft workflow need to be initialized." | description = "Draft workflow need to be initialized." |
| from libs.exception import BaseHTTPException | from libs.exception import BaseHTTPException | ||||
| class NoFileUploadedError(BaseHTTPException): | |||||
| error_code = "no_file_uploaded" | |||||
| description = "Please upload your file." | |||||
| code = 400 | |||||
| class TooManyFilesError(BaseHTTPException): | |||||
| error_code = "too_many_files" | |||||
| description = "Only one file is allowed." | |||||
| code = 400 | |||||
| class FileTooLargeError(BaseHTTPException): | |||||
| error_code = "file_too_large" | |||||
| description = "File size exceeded. {message}" | |||||
| code = 413 | |||||
| class UnsupportedFileTypeError(BaseHTTPException): | |||||
| error_code = "unsupported_file_type" | |||||
| description = "File type not allowed." | |||||
| code = 415 | |||||
| class DatasetNotInitializedError(BaseHTTPException): | class DatasetNotInitializedError(BaseHTTPException): | ||||
| error_code = "dataset_not_initialized" | error_code = "dataset_not_initialized" | ||||
| description = "The dataset is still being initialized or indexing. Please wait a moment." | description = "The dataset is still being initialized or indexing. Please wait a moment." |
| code = 429 | code = 429 | ||||
| class FileTooLargeError(BaseHTTPException): | |||||
| error_code = "file_too_large" | |||||
| description = "File size exceeded. {message}" | |||||
| code = 413 | |||||
| class UnsupportedFileTypeError(BaseHTTPException): | |||||
| error_code = "unsupported_file_type" | |||||
| description = "File type not allowed." | |||||
| code = 415 | |||||
| class TooManyFilesError(BaseHTTPException): | |||||
| error_code = "too_many_files" | |||||
| description = "Only one file is allowed." | |||||
| code = 400 | |||||
| class NoFileUploadedError(BaseHTTPException): | |||||
| error_code = "no_file_uploaded" | |||||
| description = "Please upload your file." | |||||
| code = 400 | |||||
| class UnauthorizedAndForceLogout(BaseHTTPException): | class UnauthorizedAndForceLogout(BaseHTTPException): | ||||
| error_code = "unauthorized_and_force_logout" | error_code = "unauthorized_and_force_logout" | ||||
| description = "Unauthorized and force logout." | description = "Unauthorized and force logout." |
| import services | import services | ||||
| from configs import dify_config | from configs import dify_config | ||||
| from constants import DOCUMENT_EXTENSIONS | from constants import DOCUMENT_EXTENSIONS | ||||
| from controllers.common.errors import FilenameNotExistsError | |||||
| from controllers.common.errors import ( | |||||
| FilenameNotExistsError, | |||||
| FileTooLargeError, | |||||
| NoFileUploadedError, | |||||
| TooManyFilesError, | |||||
| UnsupportedFileTypeError, | |||||
| ) | |||||
| from controllers.console.wraps import ( | from controllers.console.wraps import ( | ||||
| account_initialization_required, | account_initialization_required, | ||||
| cloud_edition_billing_resource_check, | cloud_edition_billing_resource_check, | ||||
| from libs.login import login_required | from libs.login import login_required | ||||
| from services.file_service import FileService | from services.file_service import FileService | ||||
| from .error import ( | |||||
| FileTooLargeError, | |||||
| NoFileUploadedError, | |||||
| TooManyFilesError, | |||||
| UnsupportedFileTypeError, | |||||
| ) | |||||
| PREVIEW_WORDS_LIMIT = 3000 | PREVIEW_WORDS_LIMIT = 3000 | ||||
| import services | import services | ||||
| from controllers.common import helpers | from controllers.common import helpers | ||||
| from controllers.common.errors import RemoteFileUploadError | |||||
| from controllers.common.errors import ( | |||||
| FileTooLargeError, | |||||
| RemoteFileUploadError, | |||||
| UnsupportedFileTypeError, | |||||
| ) | |||||
| from core.file import helpers as file_helpers | from core.file import helpers as file_helpers | ||||
| from core.helper import ssrf_proxy | from core.helper import ssrf_proxy | ||||
| from fields.file_fields import file_fields_with_signed_url, remote_file_info_fields | from fields.file_fields import file_fields_with_signed_url, remote_file_info_fields | ||||
| from models.account import Account | from models.account import Account | ||||
| from services.file_service import FileService | from services.file_service import FileService | ||||
| from .error import ( | |||||
| FileTooLargeError, | |||||
| UnsupportedFileTypeError, | |||||
| ) | |||||
| class RemoteFileInfoApi(Resource): | class RemoteFileInfoApi(Resource): | ||||
| @marshal_with(remote_file_info_fields) | @marshal_with(remote_file_info_fields) |
| from werkzeug.exceptions import Unauthorized | from werkzeug.exceptions import Unauthorized | ||||
| import services | import services | ||||
| from controllers.common.errors import FilenameNotExistsError | |||||
| from controllers.console import api | |||||
| from controllers.console.admin import admin_required | |||||
| from controllers.console.datasets.error import ( | |||||
| from controllers.common.errors import ( | |||||
| FilenameNotExistsError, | |||||
| FileTooLargeError, | FileTooLargeError, | ||||
| NoFileUploadedError, | NoFileUploadedError, | ||||
| TooManyFilesError, | TooManyFilesError, | ||||
| UnsupportedFileTypeError, | UnsupportedFileTypeError, | ||||
| ) | ) | ||||
| from controllers.console import api | |||||
| from controllers.console.admin import admin_required | |||||
| from controllers.console.error import AccountNotLinkTenantError | from controllers.console.error import AccountNotLinkTenantError | ||||
| from controllers.console.wraps import ( | from controllers.console.wraps import ( | ||||
| account_initialization_required, | account_initialization_required, |
| from libs.exception import BaseHTTPException | |||||
| class UnsupportedFileTypeError(BaseHTTPException): | |||||
| error_code = "unsupported_file_type" | |||||
| description = "File type not allowed." | |||||
| code = 415 |
| from werkzeug.exceptions import NotFound | from werkzeug.exceptions import NotFound | ||||
| import services | import services | ||||
| from controllers.common.errors import UnsupportedFileTypeError | |||||
| from controllers.files import api | from controllers.files import api | ||||
| from controllers.files.error import UnsupportedFileTypeError | |||||
| from services.account_service import TenantService | from services.account_service import TenantService | ||||
| from services.file_service import FileService | from services.file_service import FileService | ||||
| from flask_restful import Resource, reqparse | from flask_restful import Resource, reqparse | ||||
| from werkzeug.exceptions import Forbidden, NotFound | from werkzeug.exceptions import Forbidden, NotFound | ||||
| from controllers.common.errors import UnsupportedFileTypeError | |||||
| from controllers.files import api | from controllers.files import api | ||||
| from controllers.files.error import UnsupportedFileTypeError | |||||
| from core.tools.signature import verify_tool_file_signature | from core.tools.signature import verify_tool_file_signature | ||||
| from core.tools.tool_file_manager import ToolFileManager | from core.tools.tool_file_manager import ToolFileManager | ||||
| from models import db as global_db | from models import db as global_db |
| from werkzeug.exceptions import Forbidden | from werkzeug.exceptions import Forbidden | ||||
| import services | import services | ||||
| from controllers.common.errors import ( | |||||
| FileTooLargeError, | |||||
| UnsupportedFileTypeError, | |||||
| ) | |||||
| from controllers.console.wraps import setup_required | from controllers.console.wraps import setup_required | ||||
| from controllers.files import api | from controllers.files import api | ||||
| from controllers.files.error import UnsupportedFileTypeError | |||||
| from controllers.inner_api.plugin.wraps import get_user | from controllers.inner_api.plugin.wraps import get_user | ||||
| from controllers.service_api.app.error import FileTooLargeError | |||||
| from core.file.helpers import verify_plugin_file_signature | from core.file.helpers import verify_plugin_file_signature | ||||
| from core.tools.tool_file_manager import ToolFileManager | from core.tools.tool_file_manager import ToolFileManager | ||||
| from fields.file_fields import file_fields | from fields.file_fields import file_fields |
| code = 400 | code = 400 | ||||
| class NoFileUploadedError(BaseHTTPException): | |||||
| error_code = "no_file_uploaded" | |||||
| description = "Please upload your file." | |||||
| code = 400 | |||||
| class TooManyFilesError(BaseHTTPException): | |||||
| error_code = "too_many_files" | |||||
| description = "Only one file is allowed." | |||||
| code = 400 | |||||
| class FileTooLargeError(BaseHTTPException): | |||||
| error_code = "file_too_large" | |||||
| description = "File size exceeded. {message}" | |||||
| code = 413 | |||||
| class UnsupportedFileTypeError(BaseHTTPException): | |||||
| error_code = "unsupported_file_type" | |||||
| description = "File type not allowed." | |||||
| code = 415 | |||||
| class FileNotFoundError(BaseHTTPException): | class FileNotFoundError(BaseHTTPException): | ||||
| error_code = "file_not_found" | error_code = "file_not_found" | ||||
| description = "The requested file was not found." | description = "The requested file was not found." |
| from flask_restful import Resource, marshal_with | from flask_restful import Resource, marshal_with | ||||
| import services | import services | ||||
| from controllers.common.errors import FilenameNotExistsError | |||||
| from controllers.service_api import api | |||||
| from controllers.service_api.app.error import ( | |||||
| from controllers.common.errors import ( | |||||
| FilenameNotExistsError, | |||||
| FileTooLargeError, | FileTooLargeError, | ||||
| NoFileUploadedError, | NoFileUploadedError, | ||||
| TooManyFilesError, | TooManyFilesError, | ||||
| UnsupportedFileTypeError, | UnsupportedFileTypeError, | ||||
| ) | ) | ||||
| from controllers.service_api import api | |||||
| from controllers.service_api.wraps import FetchUserArg, WhereisUserArg, validate_app_token | from controllers.service_api.wraps import FetchUserArg, WhereisUserArg, validate_app_token | ||||
| from fields.file_fields import file_fields | from fields.file_fields import file_fields | ||||
| from models.model import App, EndUser | from models.model import App, EndUser |
| from werkzeug.exceptions import Forbidden, NotFound | from werkzeug.exceptions import Forbidden, NotFound | ||||
| import services | import services | ||||
| from controllers.common.errors import FilenameNotExistsError | |||||
| from controllers.service_api import api | |||||
| from controllers.service_api.app.error import ( | |||||
| from controllers.common.errors import ( | |||||
| FilenameNotExistsError, | |||||
| FileTooLargeError, | FileTooLargeError, | ||||
| NoFileUploadedError, | NoFileUploadedError, | ||||
| ProviderNotInitializeError, | |||||
| TooManyFilesError, | TooManyFilesError, | ||||
| UnsupportedFileTypeError, | UnsupportedFileTypeError, | ||||
| ) | ) | ||||
| from controllers.service_api import api | |||||
| from controllers.service_api.app.error import ProviderNotInitializeError | |||||
| from controllers.service_api.dataset.error import ( | from controllers.service_api.dataset.error import ( | ||||
| ArchivedDocumentImmutableError, | ArchivedDocumentImmutableError, | ||||
| DocumentIndexingError, | DocumentIndexingError, |
| from libs.exception import BaseHTTPException | from libs.exception import BaseHTTPException | ||||
| class NoFileUploadedError(BaseHTTPException): | |||||
| error_code = "no_file_uploaded" | |||||
| description = "Please upload your file." | |||||
| code = 400 | |||||
| class TooManyFilesError(BaseHTTPException): | |||||
| error_code = "too_many_files" | |||||
| description = "Only one file is allowed." | |||||
| code = 400 | |||||
| class FileTooLargeError(BaseHTTPException): | |||||
| error_code = "file_too_large" | |||||
| description = "File size exceeded. {message}" | |||||
| code = 413 | |||||
| class UnsupportedFileTypeError(BaseHTTPException): | |||||
| error_code = "unsupported_file_type" | |||||
| description = "File type not allowed." | |||||
| code = 415 | |||||
| class DatasetNotInitializedError(BaseHTTPException): | class DatasetNotInitializedError(BaseHTTPException): | ||||
| error_code = "dataset_not_initialized" | error_code = "dataset_not_initialized" | ||||
| description = "The dataset is still being initialized or indexing. Please wait a moment." | description = "The dataset is still being initialized or indexing. Please wait a moment." |
| code = 400 | code = 400 | ||||
| class NoFileUploadedError(BaseHTTPException): | |||||
| error_code = "no_file_uploaded" | |||||
| description = "Please upload your file." | |||||
| code = 400 | |||||
| class TooManyFilesError(BaseHTTPException): | |||||
| error_code = "too_many_files" | |||||
| description = "Only one file is allowed." | |||||
| code = 400 | |||||
| class FileTooLargeError(BaseHTTPException): | |||||
| error_code = "file_too_large" | |||||
| description = "File size exceeded. {message}" | |||||
| code = 413 | |||||
| class UnsupportedFileTypeError(BaseHTTPException): | |||||
| error_code = "unsupported_file_type" | |||||
| description = "File type not allowed." | |||||
| code = 415 | |||||
| class WebAppAuthRequiredError(BaseHTTPException): | class WebAppAuthRequiredError(BaseHTTPException): | ||||
| error_code = "web_sso_auth_required" | error_code = "web_sso_auth_required" | ||||
| description = "Web app authentication required." | description = "Web app authentication required." |
| from flask_restful import marshal_with | from flask_restful import marshal_with | ||||
| import services | import services | ||||
| from controllers.common.errors import FilenameNotExistsError | |||||
| from controllers.web.error import FileTooLargeError, NoFileUploadedError, TooManyFilesError, UnsupportedFileTypeError | |||||
| from controllers.common.errors import ( | |||||
| FilenameNotExistsError, | |||||
| FileTooLargeError, | |||||
| NoFileUploadedError, | |||||
| TooManyFilesError, | |||||
| UnsupportedFileTypeError, | |||||
| ) | |||||
| from controllers.web.wraps import WebApiResource | from controllers.web.wraps import WebApiResource | ||||
| from fields.file_fields import file_fields | from fields.file_fields import file_fields | ||||
| from services.file_service import FileService | from services.file_service import FileService |
| import services | import services | ||||
| from controllers.common import helpers | from controllers.common import helpers | ||||
| from controllers.common.errors import RemoteFileUploadError | |||||
| from controllers.common.errors import ( | |||||
| FileTooLargeError, | |||||
| RemoteFileUploadError, | |||||
| UnsupportedFileTypeError, | |||||
| ) | |||||
| from controllers.web.wraps import WebApiResource | from controllers.web.wraps import WebApiResource | ||||
| from core.file import helpers as file_helpers | from core.file import helpers as file_helpers | ||||
| from core.helper import ssrf_proxy | from core.helper import ssrf_proxy | ||||
| from fields.file_fields import file_fields_with_signed_url, remote_file_info_fields | from fields.file_fields import file_fields_with_signed_url, remote_file_info_fields | ||||
| from services.file_service import FileService | from services.file_service import FileService | ||||
| from .error import FileTooLargeError, UnsupportedFileTypeError | |||||
| class RemoteFileInfoApi(WebApiResource): | class RemoteFileInfoApi(WebApiResource): | ||||
| @marshal_with(remote_file_info_fields) | @marshal_with(remote_file_info_fields) |
| import pytest | import pytest | ||||
| from werkzeug.exceptions import Forbidden | from werkzeug.exceptions import Forbidden | ||||
| from controllers.common.errors import FilenameNotExistsError | |||||
| from controllers.console.error import ( | |||||
| from controllers.common.errors import ( | |||||
| FilenameNotExistsError, | |||||
| FileTooLargeError, | FileTooLargeError, | ||||
| NoFileUploadedError, | NoFileUploadedError, | ||||
| TooManyFilesError, | TooManyFilesError, |