Quellcode durchsuchen

Restructure the File errors in controller (#23801)

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
Yongtao Huang vor 2 Monaten
Ursprung
Commit
bf2f03f911
Es ist kein Account mit der E-Mail-Adresse des Committers verbunden

+ 26
- 0
api/controllers/common/errors.py Datei anzeigen

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

+ 1
- 2
api/controllers/console/app/annotation.py Datei anzeigen

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,

+ 0
- 12
api/controllers/console/app/error.py Datei anzeigen

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

+ 0
- 24
api/controllers/console/datasets/error.py Datei anzeigen

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

+ 0
- 24
api/controllers/console/error.py Datei anzeigen

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

+ 7
- 8
api/controllers/console/files.py Datei anzeigen

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





+ 5
- 6
api/controllers/console/remote_files.py Datei anzeigen



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)

+ 4
- 4
api/controllers/console/workspace/workspace.py Datei anzeigen

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,

+ 0
- 7
api/controllers/files/error.py Datei anzeigen

from libs.exception import BaseHTTPException


class UnsupportedFileTypeError(BaseHTTPException):
error_code = "unsupported_file_type"
description = "File type not allowed."
code = 415

+ 1
- 1
api/controllers/files/image_preview.py Datei anzeigen

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



+ 1
- 1
api/controllers/files/tool_files.py Datei anzeigen

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

+ 4
- 2
api/controllers/files/upload.py Datei anzeigen

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

+ 0
- 24
api/controllers/service_api/app/error.py Datei anzeigen

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

+ 3
- 3
api/controllers/service_api/app/file.py Datei anzeigen

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

+ 4
- 4
api/controllers/service_api/dataset/document.py Datei anzeigen

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,

+ 0
- 24
api/controllers/service_api/dataset/error.py Datei anzeigen

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

+ 0
- 24
api/controllers/web/error.py Datei anzeigen

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

+ 7
- 2
api/controllers/web/files.py Datei anzeigen

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

+ 5
- 3
api/controllers/web/remote_files.py Datei anzeigen



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)

+ 2
- 2
api/tests/unit_tests/controllers/console/test_files_security.py Datei anzeigen

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,

Laden…
Abbrechen
Speichern