迁移/whoami视图
This commit is contained in:
1 parent
3f97dd92ef
commit
5839172dae
4 files changed
+139
-48
No files matched your search
+3
-2
@@ -68,9 +68,10 @@ static :9200 (Flask + CORS)
|
||||
| `POST /add_note` | 新增笔记(代理至 dnfs:8006) |
|
||||
| `POST /delete_note` | 删除笔记(代理至 dnfs:8006) |
|
||||
| `POST /update_note` | 更新笔记(代理至 dnfs:8006) |
|
||||
| `POST /whoami` | 当前用户身份查询(代理至 dnfs:8006) |
|
||||
|
||||
以上 5 个 dnfs 代理路由均支持 HttpOnly Cookie 模式:当请求携带 `q4_token` Cookie 时,自动转为 `Authorization: Bearer` 头转发。
|
||||
以上 4 个 dnfs 代理路由均支持 HttpOnly Cookie 模式:当请求携带 `q4_token` Cookie 时,自动转为 `Authorization: Bearer` 头转发。
|
||||
|
||||
> `/whoami` 已上移至 gateway,由 gateway 直接验签 Token 返回用户身份,不再经 static 代理到 dnfs。
|
||||
|
||||
## 功能
|
||||
|
||||
|
||||
@@ -474,22 +474,6 @@ def proxy_update_note():
|
||||
return _cors(make_response(_json.dumps({"error": str(e)}), 502, {"Content-Type": "application/json"}))
|
||||
|
||||
|
||||
@app.route('/whoami', methods=['POST', 'OPTIONS'])
|
||||
def proxy_whoami():
|
||||
if request.method == "OPTIONS": return _cors(make_response("", 204))
|
||||
try:
|
||||
data = request.get_json(force=True, silent=True) or {}
|
||||
h = {"Content-Type": "application/json"}
|
||||
if "Authorization" in request.headers: h["Authorization"] = request.headers["Authorization"]
|
||||
elif request.cookies.get("q4_token"): h["Authorization"] = f"Bearer {request.cookies['q4_token']}" # HttpOnly Cookie 模式:Cookie 转 Bearer
|
||||
req = _urlreq.Request(f"{DNFS_URL}/whoami", data=_json.dumps(data).encode(), headers=h, method="POST")
|
||||
with _urlreq.urlopen(req, timeout=15) as r:
|
||||
return _cors(make_response(r.read().decode(), 200, {"Content-Type": "application/json"}))
|
||||
except Exception as e:
|
||||
logs.warning("static", "dnfs whoami 代理失败", extra={"error": str(e)})
|
||||
return _cors(make_response(_json.dumps({"error": str(e)}), 502, {"Content-Type": "application/json"}))
|
||||
|
||||
|
||||
@app.route('/api/proxy_send_code', methods=['POST'])
|
||||
def proxy_send_code():
|
||||
from flask import request, jsonify
|
||||
|
||||
Reference in new issue
Block a user