Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

:wrench: Add env variable for time signature (#4650)

Patryk Garsteckif40743183e4d
diff --git a/api/.env.example b/api/.env.example
index cadb4761504..1f3478b4daa 100644
--- a/api/.env.example
+++ b/api/.env.example
@@ -17,6 +17,9 @@ APP_WEB_URL=http://127.0.0.1:3000
# Files URL
FILES_URL=http://127.0.0.1:5001
+# The time in seconds after the signature is rejected
+FILES_ACCESS_TIMEOUT=300
+
# celery configuration
CELERY_BROKER_URL=redis://:difyai123456@localhost:6379/1
diff --git a/api/config.py b/api/config.py
index 5ec2f6771c3..60dd0f171ec 100644
--- a/api/config.py
+++ b/api/config.py
@@ -23,6 +23,7 @@ DEFAULTS = {
'SERVICE_API_URL': 'https://api.dify.ai',
'APP_WEB_URL': 'https://udify.app',
'FILES_URL': '',
+ 'FILES_ACCESS_TIMEOUT': 300,
'S3_ADDRESS_STYLE': 'auto',
'STORAGE_TYPE': 'local',
'STORAGE_LOCAL_PATH': 'storage',
@@ -143,6 +144,10 @@ class Config:
# Url is signed and has expiration time.
self.FILES_URL = get_env('FILES_URL') if get_env('FILES_URL') else self.CONSOLE_API_URL
+ # File Access Time specifies a time interval in seconds for the file to be accessed.
+ # The default value is 300 seconds.
+ self.FILES_ACCESS_TIMEOUT = int(get_env('FILES_ACCESS_TIMEOUT'))
+
# Your App secret key will be used for securely signing the session cookie
# Make sure you are changing this key for your deployment with a strong key.
# You can generate a strong key using `openssl rand -base64 42`.
diff --git a/api/core/file/upload_file_parser.py b/api/core/file/upload_file_parser.py
index 974fde178b3..9e454f08d42 100644
--- a/api/core/file/upload_file_parser.py
+++ b/api/core/file/upload_file_parser.py
@@ -77,4 +77,4 @@ class UploadFileParser:
return False
current_time = int(time.time())
- return current_time - int(timestamp) <= 300 # expired after 5 minutes
+ return current_time - int(timestamp) <= current_app.config.get('FILES_ACCESS_TIMEOUT')
diff --git a/api/core/tools/tool_file_manager.py b/api/core/tools/tool_file_manager.py
index 8fc71f4711f..207f009eed0 100644
--- a/api/core/tools/tool_file_manager.py
+++ b/api/core/tools/tool_file_manager.py
@@ -53,7 +53,7 @@ class ToolFileManager:
return False
current_time = int(time.time())
- return current_time - int(timestamp) <= 300 # expired after 5 minutes
+ return current_time - int(timestamp) <= current_app.config.get('FILES_ACCESS_TIMEOUT')
@staticmethod
def create_file_by_raw(user_id: str, tenant_id: str,
diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml
index d130527682c..27d0c8505c9 100644
--- a/docker/docker-compose.yaml
+++ b/docker/docker-compose.yaml
@@ -36,6 +36,9 @@ services:
# used to display File preview or download Url to the front-end or as Multi-model inputs;
# Url is signed and has expiration time.
FILES_URL: ''
+ # File Access Time specifies a time interval in seconds for the file to be accessed.
+ # The default value is 300 seconds.
+ FILES_ACCESS_TIMEOUT: 300
# When enabled, migrations will be executed prior to application startup and the application will start after the migrations have completed.
MIGRATION_ENABLED: 'true'
# The configurations of postgres database connection.