mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-14 03:45:55 +08:00
improve: cache tool icons by setting max-age HTTP header and enable gzip compression SVG icons from backend (#2971)
This commit is contained in:
parent
58e4702b14
commit
1f98a4fff3
@ -59,7 +59,8 @@ DEFAULTS = {
|
|||||||
'CAN_REPLACE_LOGO': 'False',
|
'CAN_REPLACE_LOGO': 'False',
|
||||||
'ETL_TYPE': 'dify',
|
'ETL_TYPE': 'dify',
|
||||||
'KEYWORD_STORE': 'jieba',
|
'KEYWORD_STORE': 'jieba',
|
||||||
'BATCH_UPLOAD_LIMIT': 20
|
'BATCH_UPLOAD_LIMIT': 20,
|
||||||
|
'TOOL_ICON_CACHE_MAX_AGE': 3600,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -298,6 +299,7 @@ class Config:
|
|||||||
self.BATCH_UPLOAD_LIMIT = get_env('BATCH_UPLOAD_LIMIT')
|
self.BATCH_UPLOAD_LIMIT = get_env('BATCH_UPLOAD_LIMIT')
|
||||||
|
|
||||||
self.API_COMPRESSION_ENABLED = get_bool_env('API_COMPRESSION_ENABLED')
|
self.API_COMPRESSION_ENABLED = get_bool_env('API_COMPRESSION_ENABLED')
|
||||||
|
self.TOOL_ICON_CACHE_MAX_AGE = get_env('TOOL_ICON_CACHE_MAX_AGE')
|
||||||
|
|
||||||
|
|
||||||
class CloudEditionConfig(Config):
|
class CloudEditionConfig(Config):
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import io
|
import io
|
||||||
|
|
||||||
from flask import send_file
|
from flask import current_app, send_file
|
||||||
from flask_login import current_user
|
from flask_login import current_user
|
||||||
from flask_restful import Resource, reqparse
|
from flask_restful import Resource, reqparse
|
||||||
from werkzeug.exceptions import Forbidden
|
from werkzeug.exceptions import Forbidden
|
||||||
@ -80,7 +80,8 @@ class ToolBuiltinProviderIconApi(Resource):
|
|||||||
@setup_required
|
@setup_required
|
||||||
def get(self, provider):
|
def get(self, provider):
|
||||||
icon_bytes, minetype = ToolManageService.get_builtin_tool_provider_icon(provider)
|
icon_bytes, minetype = ToolManageService.get_builtin_tool_provider_icon(provider)
|
||||||
return send_file(io.BytesIO(icon_bytes), mimetype=minetype)
|
icon_cache_max_age = int(current_app.config.get('TOOL_ICON_CACHE_MAX_AGE'))
|
||||||
|
return send_file(io.BytesIO(icon_bytes), mimetype=minetype, max_age=icon_cache_max_age)
|
||||||
|
|
||||||
class ToolModelProviderIconApi(Resource):
|
class ToolModelProviderIconApi(Resource):
|
||||||
@setup_required
|
@setup_required
|
||||||
|
@ -5,6 +5,12 @@ def init_app(app: Flask):
|
|||||||
if app.config.get('API_COMPRESSION_ENABLED', False):
|
if app.config.get('API_COMPRESSION_ENABLED', False):
|
||||||
from flask_compress import Compress
|
from flask_compress import Compress
|
||||||
|
|
||||||
|
app.config['COMPRESS_MIMETYPES'] = [
|
||||||
|
'application/json',
|
||||||
|
'image/svg+xml',
|
||||||
|
'text/html',
|
||||||
|
]
|
||||||
|
|
||||||
compress = Compress()
|
compress = Compress()
|
||||||
compress.init_app(app)
|
compress.init_app(app)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user