diff --git a/api/controllers/inner_api/wraps.py b/api/controllers/inner_api/wraps.py index 07cd38bc8..2c3c870bc 100644 --- a/api/controllers/inner_api/wraps.py +++ b/api/controllers/inner_api/wraps.py @@ -3,8 +3,9 @@ from functools import wraps from hashlib import sha1 from hmac import new as hmac_new -from flask import abort, current_app, request +from flask import abort, request +from configs import dify_config from extensions.ext_database import db from models.model import EndUser @@ -12,12 +13,12 @@ from models.model import EndUser def inner_api_only(view): @wraps(view) def decorated(*args, **kwargs): - if not current_app.config['INNER_API']: + if not dify_config.INNER_API: abort(404) # get header 'X-Inner-Api-Key' inner_api_key = request.headers.get('X-Inner-Api-Key') - if not inner_api_key or inner_api_key != current_app.config['INNER_API_KEY']: + if not inner_api_key or inner_api_key != dify_config.INNER_API_KEY: abort(404) return view(*args, **kwargs) @@ -28,7 +29,7 @@ def inner_api_only(view): def inner_api_user_auth(view): @wraps(view) def decorated(*args, **kwargs): - if not current_app.config['INNER_API']: + if not dify_config.INNER_API: return view(*args, **kwargs) # get header 'X-Inner-Api-Key' diff --git a/api/controllers/service_api/app/app.py b/api/controllers/service_api/app/app.py index bccce9b55..3b3cf1b02 100644 --- a/api/controllers/service_api/app/app.py +++ b/api/controllers/service_api/app/app.py @@ -1,7 +1,7 @@ -from flask import current_app from flask_restful import Resource, fields, marshal_with +from configs import dify_config from controllers.service_api import api from controllers.service_api.app.error import AppUnavailableError from controllers.service_api.wraps import validate_app_token @@ -78,7 +78,7 @@ class AppParameterApi(Resource): "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 } } diff --git a/api/controllers/service_api/index.py b/api/controllers/service_api/index.py index 932388b56..c910063eb 100644 --- a/api/controllers/service_api/index.py +++ b/api/controllers/service_api/index.py @@ -1,6 +1,6 @@ -from flask import current_app from flask_restful import Resource +from configs import dify_config from controllers.service_api import api @@ -9,7 +9,7 @@ class IndexApi(Resource): return { "welcome": "Dify OpenAPI", "api_version": "v1", - "server_version": current_app.config['CURRENT_VERSION'] + "server_version": dify_config.CURRENT_VERSION, } diff --git a/api/controllers/web/app.py b/api/controllers/web/app.py index 91d9015c3..f4db82552 100644 --- a/api/controllers/web/app.py +++ b/api/controllers/web/app.py @@ -1,6 +1,6 @@ -from flask import current_app from flask_restful import fields, marshal_with +from configs import dify_config from controllers.web import api from controllers.web.error import AppUnavailableError from controllers.web.wraps import WebApiResource @@ -75,7 +75,7 @@ class AppParameterApi(WebApiResource): "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 } } diff --git a/api/controllers/web/site.py b/api/controllers/web/site.py index c307959b2..99ec86e93 100644 --- a/api/controllers/web/site.py +++ b/api/controllers/web/site.py @@ -1,8 +1,8 @@ -from flask import current_app from flask_restful import fields, marshal_with from werkzeug.exceptions import Forbidden +from configs import dify_config from controllers.web import api from controllers.web.wraps import WebApiResource from extensions.ext_database import db @@ -84,7 +84,7 @@ class AppSiteInfo: self.can_replace_logo = can_replace_logo if can_replace_logo: - base_url = current_app.config.get('FILES_URL') + base_url = dify_config.FILES_URL remove_webapp_brand = tenant.custom_config_dict.get('remove_webapp_brand', False) replace_webapp_logo = f'{base_url}/files/workspaces/{tenant.id}/webapp-logo' if tenant.custom_config_dict.get('replace_webapp_logo') else None self.custom_config = { diff --git a/api/schedule/clean_embedding_cache_task.py b/api/schedule/clean_embedding_cache_task.py index 0daf651d2..3d49b487c 100644 --- a/api/schedule/clean_embedding_cache_task.py +++ b/api/schedule/clean_embedding_cache_task.py @@ -2,10 +2,10 @@ import datetime import time import click -from flask import current_app from werkzeug.exceptions import NotFound import app +from configs import dify_config from extensions.ext_database import db from models.dataset import Embedding @@ -13,7 +13,7 @@ from models.dataset import Embedding @app.celery.task(queue='dataset') def clean_embedding_cache_task(): click.echo(click.style('Start clean embedding cache.', fg='green')) - clean_days = int(current_app.config.get('CLEAN_DAY_SETTING')) + clean_days = int(dify_config.CLEAN_DAY_SETTING) start_at = time.perf_counter() thirty_days_ago = datetime.datetime.now() - datetime.timedelta(days=clean_days) page = 1 diff --git a/api/schedule/clean_unused_datasets_task.py b/api/schedule/clean_unused_datasets_task.py index cdcb3121b..2033791ac 100644 --- a/api/schedule/clean_unused_datasets_task.py +++ b/api/schedule/clean_unused_datasets_task.py @@ -2,10 +2,10 @@ import datetime import time import click -from flask import current_app from werkzeug.exceptions import NotFound import app +from configs import dify_config from core.rag.index_processor.index_processor_factory import IndexProcessorFactory from extensions.ext_database import db from models.dataset import Dataset, DatasetQuery, Document @@ -14,7 +14,7 @@ from models.dataset import Dataset, DatasetQuery, Document @app.celery.task(queue='dataset') def clean_unused_datasets_task(): click.echo(click.style('Start clean unused datasets indexes.', fg='green')) - clean_days = int(current_app.config.get('CLEAN_DAY_SETTING')) + clean_days = int(dify_config.CLEAN_DAY_SETTING) start_at = time.perf_counter() thirty_days_ago = datetime.datetime.now() - datetime.timedelta(days=clean_days) page = 1