mirror of
https://github.com/langgenius/dify.git
synced 2026-11-10 21:35:45 +08:00
Co-authored-by: zxhlyh <jasonapring2015@outlook.com> Co-authored-by: JzoNg <jzongcode@gmail.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
146 lines
3.4 KiB
Python
146 lines
3.4 KiB
Python
from types import ModuleType
|
|
|
|
from flask import Blueprint
|
|
from flask_restx import Namespace
|
|
|
|
from controllers.common.app_access_error import register_app_access_error_metadata
|
|
from controllers.common.errors import InternalServerError, NotFoundError, UnauthorizedError
|
|
from controllers.console.error import NotInitValidateError, NotSetupError
|
|
from controllers.web.error import (
|
|
WebAppAccessServiceUnavailableError,
|
|
WebAppAuthAccessDeniedError,
|
|
WebAppAuthRequiredError,
|
|
WebAppNotFoundError,
|
|
)
|
|
from libs.external_api import ExternalApi
|
|
|
|
bp = Blueprint("web", __name__, url_prefix="/api")
|
|
register_app_access_error_metadata(bp, surface="web")
|
|
|
|
api = ExternalApi(
|
|
bp,
|
|
version="1.0",
|
|
title="Web API",
|
|
description="Public APIs for web applications including file uploads, chat interactions, and app management",
|
|
)
|
|
# The passport guard on every Web API resource raises these; the web client answers them
|
|
# centrally (sign-in redirect, access-denied and not-found pages), so no operation lists them.
|
|
# ``not_found``, ``unauthorized`` and ``internal_server_error`` are the codes Werkzeug's own
|
|
# exceptions already produce on every operation.
|
|
api.document_generic_errors(
|
|
NotSetupError,
|
|
NotInitValidateError,
|
|
WebAppNotFoundError,
|
|
WebAppAuthRequiredError,
|
|
WebAppAuthAccessDeniedError,
|
|
WebAppAccessServiceUnavailableError,
|
|
NotFoundError,
|
|
UnauthorizedError,
|
|
InternalServerError,
|
|
)
|
|
|
|
# Create namespace
|
|
web_ns = Namespace("web", description="Web application API operations", path="/")
|
|
|
|
|
|
def _register_controllers() -> tuple[ModuleType, ...]:
|
|
"""Load route modules after their namespaces and schema models exist."""
|
|
|
|
from . import (
|
|
app,
|
|
audio,
|
|
completion,
|
|
conversation,
|
|
feature,
|
|
files,
|
|
forgot_password,
|
|
human_input_file_upload,
|
|
human_input_form,
|
|
human_input_form_access_request,
|
|
human_input_v2,
|
|
human_input_v2_file_upload,
|
|
login,
|
|
message,
|
|
passport,
|
|
remote_files,
|
|
saved_message,
|
|
site,
|
|
workflow,
|
|
workflow_events,
|
|
)
|
|
|
|
return (
|
|
app,
|
|
audio,
|
|
completion,
|
|
conversation,
|
|
feature,
|
|
files,
|
|
forgot_password,
|
|
human_input_file_upload,
|
|
human_input_form,
|
|
human_input_form_access_request,
|
|
human_input_v2,
|
|
human_input_v2_file_upload,
|
|
login,
|
|
message,
|
|
passport,
|
|
remote_files,
|
|
saved_message,
|
|
site,
|
|
workflow,
|
|
workflow_events,
|
|
)
|
|
|
|
|
|
(
|
|
app,
|
|
audio,
|
|
completion,
|
|
conversation,
|
|
feature,
|
|
files,
|
|
forgot_password,
|
|
human_input_file_upload,
|
|
human_input_form,
|
|
human_input_form_access_request,
|
|
human_input_v2,
|
|
human_input_v2_file_upload,
|
|
login,
|
|
message,
|
|
passport,
|
|
remote_files,
|
|
saved_message,
|
|
site,
|
|
workflow,
|
|
workflow_events,
|
|
) = _register_controllers()
|
|
|
|
api.add_namespace(web_ns)
|
|
|
|
__all__ = [
|
|
"api",
|
|
"app",
|
|
"audio",
|
|
"bp",
|
|
"completion",
|
|
"conversation",
|
|
"feature",
|
|
"files",
|
|
"forgot_password",
|
|
"human_input_file_upload",
|
|
"human_input_form",
|
|
"human_input_form_access_request",
|
|
"human_input_v2",
|
|
"human_input_v2_file_upload",
|
|
"login",
|
|
"message",
|
|
"passport",
|
|
"remote_files",
|
|
"saved_message",
|
|
"site",
|
|
"web_ns",
|
|
"workflow",
|
|
"workflow_events",
|
|
]
|