修复中控

This commit is contained in:
dekun
2026-05-30 12:33:20 +08:00
parent a084c272b9
commit 9115523df7
6 changed files with 158 additions and 17 deletions
+7 -2
View File
@@ -582,7 +582,9 @@ def _require_hub_logged_in(request: Request) -> None:
@app.get("/api/instance/open-url")
def api_instance_open_url(request: Request, exchange_id: str, next: str = "/"):
def api_instance_open_url(
request: Request, exchange_id: str, next: str = "/", embed: str = ""
):
"""已登录中控时生成实例 SSO 打开链接(2h 有效、单次使用,复用 HUB_BRIDGE_TOKEN)。"""
_require_hub_logged_in(request)
if not HUB_BRIDGE_TOKEN:
@@ -600,7 +602,10 @@ def api_instance_open_url(request: Request, exchange_id: str, next: str = "/"):
token = mint_hub_sso_token(ex_key, nxt)
if not token:
raise HTTPException(status_code=503, detail="签发 SSO 失败")
q = urlencode({"token": token, "next": nxt})
params = {"token": token, "next": nxt}
if (embed or "").strip().lower() in ("1", "true", "yes", "on"):
params["embed"] = "1"
q = urlencode(params)
return {
"ok": True,
"url": f"{base}/hub-sso?{q}",
+19 -4
View File
@@ -39,9 +39,11 @@
}
}
async function fetchInstanceOpenUrl(exchangeId, nextPath) {
async function fetchInstanceOpenUrl(exchangeId, nextPath, opts) {
const options = opts || {};
const next = nextPath || "/";
const q = new URLSearchParams({ exchange_id: String(exchangeId), next });
if (options.embed) q.set("embed", "1");
const r = await apiFetch("/api/instance/open-url?" + q.toString());
const j = await r.json();
if (!j.ok || !j.url) {
@@ -55,7 +57,8 @@
const newTab = !!options.newTab;
const next = nextPath || "/";
try {
const url = await fetchInstanceOpenUrl(exchangeId, next);
const embedded = isHubEmbedded();
const url = await fetchInstanceOpenUrl(exchangeId, next, { embed: embedded });
if (newTab) {
window.open(url, "_blank", "noopener");
return;
@@ -63,7 +66,18 @@
const row = lastMonitorRows.find((x) => String(x.id) === String(exchangeId));
const title = row ? row.name : exchangeId;
instanceFrameCtx = { exchangeId: String(exchangeId), nextPath: next, title };
if (isHubEmbedded()) {
if (embedded) {
try {
window.parent.postMessage(
{
type: "hub:open-instance-nav",
exchangeId: String(exchangeId),
nextPath: next,
title,
},
"*"
);
} catch (_) {}
if (openInstanceInParentFrame(url)) return;
}
openInstanceFrame(url, title);
@@ -83,7 +97,8 @@
try {
const url = await fetchInstanceOpenUrl(
instanceFrameCtx.exchangeId,
instanceFrameCtx.nextPath
instanceFrameCtx.nextPath,
{ embed: isHubEmbedded() }
);
instanceFrameUrl = url;
const frame = document.getElementById("instance-frame");
+1 -1
View File
@@ -120,6 +120,6 @@
</div>
<div id="toast"></div>
<script src="/assets/app.js?v=20260530-hub-embed-nav"></script>
<script src="/assets/app.js?v=20260530-hub-embed-sso"></script>
</body>
</html>