chore: 纳入本地 Dify 1.19.0 源码及品牌与免登改动
演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
60158935f4
commit
6519682885
15831 files changed
+3063428
No files matched your search
@@ -0,0 +1,46 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from contextlib import AbstractContextManager, nullcontext
|
||||
from typing import TYPE_CHECKING, Any, override
|
||||
|
||||
from flask import Flask
|
||||
from flask.ctx import AppContext
|
||||
|
||||
from graphon.file.runtime import use_workflow_file_runtime
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from extensions.ext_login import DifyLoginManager
|
||||
|
||||
|
||||
class DifyApp(Flask):
|
||||
"""Flask application type with Dify-specific extension attributes."""
|
||||
|
||||
login_manager: DifyLoginManager
|
||||
|
||||
@override
|
||||
def app_context(self) -> AppContext:
|
||||
return DifyAppContext(self)
|
||||
|
||||
|
||||
class DifyAppContext(AppContext):
|
||||
"""Keep the file adapter available through Flask teardown, including failures."""
|
||||
|
||||
def __init__(self, app: DifyApp) -> None:
|
||||
super().__init__(app)
|
||||
self._file_scopes: list[AbstractContextManager[None]] = []
|
||||
|
||||
@override
|
||||
def push(self) -> None:
|
||||
super().push()
|
||||
runtime = self.app.extensions.get("workflow_file_runtime")
|
||||
scope = use_workflow_file_runtime(runtime) if runtime is not None else nullcontext()
|
||||
scope.__enter__()
|
||||
self._file_scopes.append(scope)
|
||||
|
||||
@override
|
||||
def pop(self, *args: Any, **kwargs: Any) -> None:
|
||||
# Forward omitted arguments unchanged so Flask can infer the active exception.
|
||||
try:
|
||||
super().pop(*args, **kwargs)
|
||||
finally:
|
||||
self._file_scopes.pop().__exit__(None, None, None)
|
||||
Reference in new issue
Block a user