mirror of
https://gitee.com/dify_ai/dify.git
synced 2024-12-02 11:18:19 +08:00
refactor(api): switch to dify_config with Pydantic in controllers and schedule (#6237)
This commit is contained in:
parent
a9ee52f2d7
commit
1df71ec64d
@ -3,8 +3,9 @@ from functools import wraps
|
|||||||
from hashlib import sha1
|
from hashlib import sha1
|
||||||
from hmac import new as hmac_new
|
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 extensions.ext_database import db
|
||||||
from models.model import EndUser
|
from models.model import EndUser
|
||||||
|
|
||||||
@ -12,12 +13,12 @@ from models.model import EndUser
|
|||||||
def inner_api_only(view):
|
def inner_api_only(view):
|
||||||
@wraps(view)
|
@wraps(view)
|
||||||
def decorated(*args, **kwargs):
|
def decorated(*args, **kwargs):
|
||||||
if not current_app.config['INNER_API']:
|
if not dify_config.INNER_API:
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
# get header 'X-Inner-Api-Key'
|
# get header 'X-Inner-Api-Key'
|
||||||
inner_api_key = request.headers.get('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)
|
abort(404)
|
||||||
|
|
||||||
return view(*args, **kwargs)
|
return view(*args, **kwargs)
|
||||||
@ -28,7 +29,7 @@ def inner_api_only(view):
|
|||||||
def inner_api_user_auth(view):
|
def inner_api_user_auth(view):
|
||||||
@wraps(view)
|
@wraps(view)
|
||||||
def decorated(*args, **kwargs):
|
def decorated(*args, **kwargs):
|
||||||
if not current_app.config['INNER_API']:
|
if not dify_config.INNER_API:
|
||||||
return view(*args, **kwargs)
|
return view(*args, **kwargs)
|
||||||
|
|
||||||
# get header 'X-Inner-Api-Key'
|
# get header 'X-Inner-Api-Key'
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
from flask import current_app
|
|
||||||
from flask_restful import Resource, fields, marshal_with
|
from flask_restful import Resource, fields, marshal_with
|
||||||
|
|
||||||
|
from configs import dify_config
|
||||||
from controllers.service_api import api
|
from controllers.service_api import api
|
||||||
from controllers.service_api.app.error import AppUnavailableError
|
from controllers.service_api.app.error import AppUnavailableError
|
||||||
from controllers.service_api.wraps import validate_app_token
|
from controllers.service_api.wraps import validate_app_token
|
||||||
@ -78,7 +78,7 @@ class AppParameterApi(Resource):
|
|||||||
"transfer_methods": ["remote_url", "local_file"]
|
"transfer_methods": ["remote_url", "local_file"]
|
||||||
}}),
|
}}),
|
||||||
'system_parameters': {
|
'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,6 +1,6 @@
|
|||||||
from flask import current_app
|
|
||||||
from flask_restful import Resource
|
from flask_restful import Resource
|
||||||
|
|
||||||
|
from configs import dify_config
|
||||||
from controllers.service_api import api
|
from controllers.service_api import api
|
||||||
|
|
||||||
|
|
||||||
@ -9,7 +9,7 @@ class IndexApi(Resource):
|
|||||||
return {
|
return {
|
||||||
"welcome": "Dify OpenAPI",
|
"welcome": "Dify OpenAPI",
|
||||||
"api_version": "v1",
|
"api_version": "v1",
|
||||||
"server_version": current_app.config['CURRENT_VERSION']
|
"server_version": dify_config.CURRENT_VERSION,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
from flask import current_app
|
|
||||||
from flask_restful import fields, marshal_with
|
from flask_restful import fields, marshal_with
|
||||||
|
|
||||||
|
from configs import dify_config
|
||||||
from controllers.web import api
|
from controllers.web import api
|
||||||
from controllers.web.error import AppUnavailableError
|
from controllers.web.error import AppUnavailableError
|
||||||
from controllers.web.wraps import WebApiResource
|
from controllers.web.wraps import WebApiResource
|
||||||
@ -75,7 +75,7 @@ class AppParameterApi(WebApiResource):
|
|||||||
"transfer_methods": ["remote_url", "local_file"]
|
"transfer_methods": ["remote_url", "local_file"]
|
||||||
}}),
|
}}),
|
||||||
'system_parameters': {
|
'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,8 @@
|
|||||||
|
|
||||||
from flask import current_app
|
|
||||||
from flask_restful import fields, marshal_with
|
from flask_restful import fields, marshal_with
|
||||||
from werkzeug.exceptions import Forbidden
|
from werkzeug.exceptions import Forbidden
|
||||||
|
|
||||||
|
from configs import dify_config
|
||||||
from controllers.web import api
|
from controllers.web import api
|
||||||
from controllers.web.wraps import WebApiResource
|
from controllers.web.wraps import WebApiResource
|
||||||
from extensions.ext_database import db
|
from extensions.ext_database import db
|
||||||
@ -84,7 +84,7 @@ class AppSiteInfo:
|
|||||||
self.can_replace_logo = can_replace_logo
|
self.can_replace_logo = can_replace_logo
|
||||||
|
|
||||||
if 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)
|
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
|
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 = {
|
self.custom_config = {
|
||||||
|
@ -2,10 +2,10 @@ import datetime
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
import click
|
import click
|
||||||
from flask import current_app
|
|
||||||
from werkzeug.exceptions import NotFound
|
from werkzeug.exceptions import NotFound
|
||||||
|
|
||||||
import app
|
import app
|
||||||
|
from configs import dify_config
|
||||||
from extensions.ext_database import db
|
from extensions.ext_database import db
|
||||||
from models.dataset import Embedding
|
from models.dataset import Embedding
|
||||||
|
|
||||||
@ -13,7 +13,7 @@ from models.dataset import Embedding
|
|||||||
@app.celery.task(queue='dataset')
|
@app.celery.task(queue='dataset')
|
||||||
def clean_embedding_cache_task():
|
def clean_embedding_cache_task():
|
||||||
click.echo(click.style('Start clean embedding cache.', fg='green'))
|
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()
|
start_at = time.perf_counter()
|
||||||
thirty_days_ago = datetime.datetime.now() - datetime.timedelta(days=clean_days)
|
thirty_days_ago = datetime.datetime.now() - datetime.timedelta(days=clean_days)
|
||||||
page = 1
|
page = 1
|
||||||
|
@ -2,10 +2,10 @@ import datetime
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
import click
|
import click
|
||||||
from flask import current_app
|
|
||||||
from werkzeug.exceptions import NotFound
|
from werkzeug.exceptions import NotFound
|
||||||
|
|
||||||
import app
|
import app
|
||||||
|
from configs import dify_config
|
||||||
from core.rag.index_processor.index_processor_factory import IndexProcessorFactory
|
from core.rag.index_processor.index_processor_factory import IndexProcessorFactory
|
||||||
from extensions.ext_database import db
|
from extensions.ext_database import db
|
||||||
from models.dataset import Dataset, DatasetQuery, Document
|
from models.dataset import Dataset, DatasetQuery, Document
|
||||||
@ -14,7 +14,7 @@ from models.dataset import Dataset, DatasetQuery, Document
|
|||||||
@app.celery.task(queue='dataset')
|
@app.celery.task(queue='dataset')
|
||||||
def clean_unused_datasets_task():
|
def clean_unused_datasets_task():
|
||||||
click.echo(click.style('Start clean unused datasets indexes.', fg='green'))
|
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()
|
start_at = time.perf_counter()
|
||||||
thirty_days_ago = datetime.datetime.now() - datetime.timedelta(days=clean_days)
|
thirty_days_ago = datetime.datetime.now() - datetime.timedelta(days=clean_days)
|
||||||
page = 1
|
page = 1
|
||||||
|
Loading…
Reference in New Issue
Block a user