Skip to content

Commit

Permalink
is_enabled
Browse files Browse the repository at this point in the history
bowenliang123 committed Nov 28, 2024
1 parent dbd2b09 commit faf5f50
Showing 3 changed files with 19 additions and 11 deletions.
9 changes: 7 additions & 2 deletions api/app_factory.py
Original file line number Diff line number Diff line change
@@ -86,9 +86,14 @@ def initialize_extensions(app: DifyApp):
ext_commands,
]
for ext in extensions:
short_name = ext.__name__.split(".")[1]
is_enabled = ext.is_enabled() if hasattr(ext, "is_enabled") else True
if not is_enabled:
if dify_config.DEBUG:
logging.info(f"Skipped loading {short_name}")

start_time = time.perf_counter()
ext.init_app(app)
end_time = time.perf_counter()
ext_short_name = ext.__name__.split(".")[1]
if dify_config.DEBUG:
logging.info(f"Loaded {ext_short_name} ({round((end_time - start_time) * 1000, 2)} ms)")
logging.info(f"Loaded {short_name} ({round((end_time - start_time) * 1000, 2)} ms)")
19 changes: 10 additions & 9 deletions api/extensions/ext_compress.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from configs import dify_config
from dify_app import DifyApp

def is_enabled() -> bool:
return dify_config.API_COMPRESSION_ENABLED

def init_app(app: DifyApp):
if dify_config.API_COMPRESSION_ENABLED:
from flask_compress import Compress
from flask_compress import Compress

app.config["COMPRESS_MIMETYPES"] = [
"application/json",
"image/svg+xml",
"text/html",
]
app.config["COMPRESS_MIMETYPES"] = [
"application/json",
"image/svg+xml",
"text/html",
]

compress = Compress()
compress.init_app(app)
compress = Compress()
compress.init_app(app)
2 changes: 2 additions & 0 deletions api/extensions/ext_mail.py
Original file line number Diff line number Diff line change
@@ -85,6 +85,8 @@ def send(self, to: str, subject: str, html: str, from_: Optional[str] = None):
}
)

def is_enabled() -> bool:
return dify_config.MAIL_TYPE is not None

def init_app(app: DifyApp):
mail.init_app(app)

0 comments on commit faf5f50

Please sign in to comment.