| @@ -1,10 +1,11 @@ | |||
| import flask_restful | |||
| from flask import current_app, request | |||
| from flask import request | |||
| from flask_login import current_user | |||
| from flask_restful import Resource, marshal, marshal_with, reqparse | |||
| from werkzeug.exceptions import Forbidden, NotFound | |||
| import services | |||
| from configs import dify_config | |||
| from controllers.console import api | |||
| from controllers.console.apikey import api_key_fields, api_key_list | |||
| from controllers.console.app.error import ProviderNotInitializeError | |||
| @@ -530,7 +531,7 @@ class DatasetApiBaseUrlApi(Resource): | |||
| @account_initialization_required | |||
| def get(self): | |||
| return { | |||
| 'api_base_url': (current_app.config['SERVICE_API_URL'] if current_app.config['SERVICE_API_URL'] | |||
| 'api_base_url': (dify_config.SERVICE_API_URL if dify_config.SERVICE_API_URL | |||
| else request.host_url.rstrip('/')) + '/v1' | |||
| } | |||
| @@ -540,7 +541,7 @@ class DatasetRetrievalSettingApi(Resource): | |||
| @login_required | |||
| @account_initialization_required | |||
| def get(self): | |||
| vector_type = current_app.config['VECTOR_STORE'] | |||
| vector_type = dify_config.VECTOR_STORE | |||
| match vector_type: | |||
| case VectorType.MILVUS | VectorType.RELYT | VectorType.PGVECTOR | VectorType.TIDB_VECTOR | VectorType.CHROMA | VectorType.TENCENT | VectorType.ORACLE: | |||
| return { | |||
| @@ -1,8 +1,9 @@ | |||
| from flask import current_app, request | |||
| from flask import request | |||
| from flask_login import current_user | |||
| from flask_restful import Resource, marshal_with | |||
| import services | |||
| from configs import dify_config | |||
| from controllers.console import api | |||
| from controllers.console.datasets.error import ( | |||
| FileTooLargeError, | |||
| @@ -26,9 +27,9 @@ class FileApi(Resource): | |||
| @account_initialization_required | |||
| @marshal_with(upload_config_fields) | |||
| def get(self): | |||
| file_size_limit = current_app.config.get("UPLOAD_FILE_SIZE_LIMIT") | |||
| batch_count_limit = current_app.config.get("UPLOAD_FILE_BATCH_LIMIT") | |||
| image_file_size_limit = current_app.config.get("UPLOAD_IMAGE_FILE_SIZE_LIMIT") | |||
| file_size_limit = dify_config.UPLOAD_FILE_SIZE_LIMIT | |||
| batch_count_limit = dify_config.UPLOAD_FILE_BATCH_LIMIT | |||
| image_file_size_limit = dify_config.UPLOAD_IMAGE_FILE_SIZE_LIMIT | |||
| return { | |||
| 'file_size_limit': file_size_limit, | |||
| 'batch_count_limit': batch_count_limit, | |||
| @@ -76,7 +77,7 @@ class FileSupportTypeApi(Resource): | |||
| @login_required | |||
| @account_initialization_required | |||
| def get(self): | |||
| etl_type = current_app.config['ETL_TYPE'] | |||
| etl_type = dify_config.ETL_TYPE | |||
| allowed_extensions = UNSTRUCTURED_ALLOWED_EXTENSIONS if etl_type == 'Unstructured' else ALLOWED_EXTENSIONS | |||
| return {'allowed_extensions': allowed_extensions} | |||
| @@ -1,7 +1,7 @@ | |||
| from flask import current_app | |||
| from flask_restful import fields, marshal_with | |||
| from configs import dify_config | |||
| from controllers.console import api | |||
| from controllers.console.app.error import AppUnavailableError | |||
| from controllers.console.explore.wraps import InstalledAppResource | |||
| @@ -78,7 +78,7 @@ class AppParameterApi(InstalledAppResource): | |||
| "transfer_methods": ["remote_url", "local_file"] | |||
| }}), | |||
| 'system_parameters': { | |||
| 'image_file_size_limit': current_app.config.get('UPLOAD_IMAGE_FILE_SIZE_LIMIT') | |||
| 'image_file_size_limit': dify_config.UPLOAD_IMAGE_FILE_SIZE_LIMIT | |||
| } | |||
| } | |||
| @@ -1,8 +1,9 @@ | |||
| import os | |||
| from flask import current_app, session | |||
| from flask import session | |||
| from flask_restful import Resource, reqparse | |||
| from configs import dify_config | |||
| from libs.helper import str_len | |||
| from models.model import DifySetup | |||
| from services.account_service import TenantService | |||
| @@ -40,7 +41,7 @@ class InitValidateAPI(Resource): | |||
| return {'result': 'success'}, 201 | |||
| def get_init_validate_status(): | |||
| if current_app.config['EDITION'] == 'SELF_HOSTED': | |||
| if dify_config.EDITION == 'SELF_HOSTED': | |||
| if os.environ.get('INIT_PASSWORD'): | |||
| return session.get('is_init_validated') or DifySetup.query.first() | |||
| @@ -1,8 +1,9 @@ | |||
| from functools import wraps | |||
| from flask import current_app, request | |||
| from flask import request | |||
| from flask_restful import Resource, reqparse | |||
| from configs import dify_config | |||
| from libs.helper import email, get_remote_ip, str_len | |||
| from libs.password import valid_password | |||
| from models.model import DifySetup | |||
| @@ -17,7 +18,7 @@ from .wraps import only_edition_self_hosted | |||
| class SetupApi(Resource): | |||
| def get(self): | |||
| if current_app.config['EDITION'] == 'SELF_HOSTED': | |||
| if dify_config.EDITION == 'SELF_HOSTED': | |||
| setup_status = get_setup_status() | |||
| if setup_status: | |||
| return { | |||
| @@ -77,7 +78,7 @@ def setup_required(view): | |||
| def get_setup_status(): | |||
| if current_app.config['EDITION'] == 'SELF_HOSTED': | |||
| if dify_config.EDITION == 'SELF_HOSTED': | |||
| return DifySetup.query.first() | |||
| else: | |||
| return True | |||
| @@ -3,9 +3,10 @@ import json | |||
| import logging | |||
| import requests | |||
| from flask import current_app | |||
| from flask_restful import Resource, reqparse | |||
| from configs import dify_config | |||
| from . import api | |||
| @@ -15,16 +16,16 @@ class VersionApi(Resource): | |||
| parser = reqparse.RequestParser() | |||
| parser.add_argument('current_version', type=str, required=True, location='args') | |||
| args = parser.parse_args() | |||
| check_update_url = current_app.config['CHECK_UPDATE_URL'] | |||
| check_update_url = dify_config.CHECK_UPDATE_URL | |||
| result = { | |||
| 'version': current_app.config['CURRENT_VERSION'], | |||
| 'version': dify_config.CURRENT_VERSION, | |||
| 'release_date': '', | |||
| 'release_notes': '', | |||
| 'can_auto_update': False, | |||
| 'features': { | |||
| 'can_replace_logo': current_app.config['CAN_REPLACE_LOGO'], | |||
| 'model_load_balancing_enabled': current_app.config['MODEL_LB_ENABLED'] | |||
| 'can_replace_logo': dify_config.CAN_REPLACE_LOGO, | |||
| 'model_load_balancing_enabled': dify_config.MODEL_LB_ENABLED | |||
| } | |||
| } | |||
| @@ -1,10 +1,11 @@ | |||
| import datetime | |||
| import pytz | |||
| from flask import current_app, request | |||
| from flask import request | |||
| from flask_login import current_user | |||
| from flask_restful import Resource, fields, marshal_with, reqparse | |||
| from configs import dify_config | |||
| from constants.languages import supported_language | |||
| from controllers.console import api | |||
| from controllers.console.setup import setup_required | |||
| @@ -36,7 +37,7 @@ class AccountInitApi(Resource): | |||
| parser = reqparse.RequestParser() | |||
| if current_app.config['EDITION'] == 'CLOUD': | |||
| if dify_config.EDITION == 'CLOUD': | |||
| parser.add_argument('invitation_code', type=str, location='json') | |||
| parser.add_argument( | |||
| @@ -45,7 +46,7 @@ class AccountInitApi(Resource): | |||
| required=True, location='json') | |||
| args = parser.parse_args() | |||
| if current_app.config['EDITION'] == 'CLOUD': | |||
| if dify_config.EDITION == 'CLOUD': | |||
| if not args['invitation_code']: | |||
| raise ValueError('invitation_code is required') | |||
| @@ -1,8 +1,8 @@ | |||
| from flask import current_app | |||
| from flask_login import current_user | |||
| from flask_restful import Resource, abort, marshal_with, reqparse | |||
| import services | |||
| from configs import dify_config | |||
| from controllers.console import api | |||
| from controllers.console.setup import setup_required | |||
| from controllers.console.wraps import account_initialization_required, cloud_edition_billing_resource_check | |||
| @@ -48,7 +48,7 @@ class MemberInviteEmailApi(Resource): | |||
| inviter = current_user | |||
| invitation_results = [] | |||
| console_web_url = current_app.config.get("CONSOLE_WEB_URL") | |||
| console_web_url = dify_config.CONSOLE_WEB_URL | |||
| for invitee_email in invitee_emails: | |||
| try: | |||
| token = RegisterService.invite_new_member(inviter.current_tenant, invitee_email, interface_language, role=invitee_role, inviter=inviter) | |||
| @@ -1,10 +1,11 @@ | |||
| import io | |||
| from flask import current_app, send_file | |||
| from flask import send_file | |||
| from flask_login import current_user | |||
| from flask_restful import Resource, reqparse | |||
| from werkzeug.exceptions import Forbidden | |||
| from configs import dify_config | |||
| from controllers.console import api | |||
| from controllers.console.setup import setup_required | |||
| from controllers.console.wraps import account_initialization_required | |||
| @@ -104,7 +105,7 @@ class ToolBuiltinProviderIconApi(Resource): | |||
| @setup_required | |||
| def get(self, provider): | |||
| icon_bytes, mimetype = BuiltinToolManageService.get_builtin_tool_provider_icon(provider) | |||
| icon_cache_max_age = current_app.config.get('TOOL_ICON_CACHE_MAX_AGE') | |||
| icon_cache_max_age = dify_config.TOOL_ICON_CACHE_MAX_AGE | |||
| return send_file(io.BytesIO(icon_bytes), mimetype=mimetype, max_age=icon_cache_max_age) | |||
| class ToolApiProviderAddApi(Resource): | |||
| @@ -1,9 +1,10 @@ | |||
| import json | |||
| from functools import wraps | |||
| from flask import abort, current_app, request | |||
| from flask import abort, request | |||
| from flask_login import current_user | |||
| from configs import dify_config | |||
| from controllers.console.workspace.error import AccountNotInitializedError | |||
| from services.feature_service import FeatureService | |||
| from services.operation_service import OperationService | |||
| @@ -26,7 +27,7 @@ def account_initialization_required(view): | |||
| def only_edition_cloud(view): | |||
| @wraps(view) | |||
| def decorated(*args, **kwargs): | |||
| if current_app.config['EDITION'] != 'CLOUD': | |||
| if dify_config.EDITION != 'CLOUD': | |||
| abort(404) | |||
| return view(*args, **kwargs) | |||
| @@ -37,7 +38,7 @@ def only_edition_cloud(view): | |||
| def only_edition_self_hosted(view): | |||
| @wraps(view) | |||
| def decorated(*args, **kwargs): | |||
| if current_app.config['EDITION'] != 'SELF_HOSTED': | |||
| if dify_config.EDITION != 'SELF_HOSTED': | |||
| abort(404) | |||
| return view(*args, **kwargs) | |||