refactor(backend): dify, minio等迁移到integration,清除无效文件
This commit is contained in:
1 parent
7fe7a39384
commit
faa554ade4
90 files changed
+7540
-9649
No files matched your search
@@ -0,0 +1,51 @@
|
||||
"""
|
||||
backend/app/core/http_context.py
|
||||
|
||||
用途:把 Flask request 读取收口在 core,避免 services 直接依赖 flask.request。
|
||||
依赖:flask.has_request_context / request(仅本模块)。
|
||||
逻辑:API 与 service 需要 Host、Header、客户端 IP 时调用本模块;无请求上下文时返回空值。
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
|
||||
def has_http_request() -> bool:
|
||||
"""
|
||||
当前是否处于 HTTP 请求上下文。
|
||||
返回:
|
||||
有请求上下文时 True,Worker / CLI 时 False。
|
||||
"""
|
||||
from flask import has_request_context
|
||||
|
||||
return bool(has_request_context())
|
||||
|
||||
|
||||
def header(name: str, default: str = "") -> str:
|
||||
"""
|
||||
读取请求头;无请求上下文时返回 default。
|
||||
参数:
|
||||
name: Header 名。
|
||||
default: 缺省值。
|
||||
"""
|
||||
if not has_http_request():
|
||||
return default
|
||||
from flask import request
|
||||
|
||||
return str(request.headers.get(name) or default)
|
||||
|
||||
|
||||
def host_url() -> str:
|
||||
"""返回当前请求 host_url(无尾斜杠);无请求时返回空字符串。"""
|
||||
if not has_http_request():
|
||||
return ""
|
||||
from flask import request
|
||||
|
||||
return str(request.host_url or "").rstrip("/")
|
||||
|
||||
|
||||
def remote_addr() -> str:
|
||||
"""返回 request.remote_addr;无请求时返回空字符串。"""
|
||||
if not has_http_request():
|
||||
return ""
|
||||
from flask import request
|
||||
|
||||
return str(request.remote_addr or "").strip()
|
||||
Reference in new issue
Block a user