()
| 2731 | } |
| 2732 | |
| 2733 | private resolveHubConnection(): { hubUrl: string; userToken: string } | null { |
| 2734 | if (!this.ctx) return null; |
| 2735 | |
| 2736 | // Hub 模式:连接自己,用 bootstrap admin token |
| 2737 | const sharing = this.ctx.config.sharing; |
| 2738 | if (sharing?.role === "hub") { |
| 2739 | const hubPort = this.getHubPort(); |
| 2740 | const hubUrl = `http://127.0.0.1:${hubPort}`; |
| 2741 | try { |
| 2742 | const authPath = path.join(this.dataDir, "hub-auth.json"); |
| 2743 | const authData = JSON.parse(fs.readFileSync(authPath, "utf8")); |
| 2744 | const adminToken = authData?.bootstrapAdminToken; |
| 2745 | if (adminToken) return { hubUrl, userToken: adminToken }; |
| 2746 | } catch { |
| 2747 | // hub-auth.json 不存在或读取失败,fall through |
| 2748 | } |
| 2749 | } |
| 2750 | |
| 2751 | // Client 模式:用配置的 hubAddress + userToken |
| 2752 | const conn = this.store.getClientHubConnection(); |
| 2753 | const hubUrl = conn?.hubUrl || this.ctx.config.sharing?.client?.hubAddress || ""; |
| 2754 | const userToken = conn?.userToken || this.ctx.config.sharing?.client?.userToken || ""; |
| 2755 | if (!hubUrl || !userToken) return null; |
| 2756 | return { hubUrl: normalizeHubUrl(hubUrl), userToken }; |
| 2757 | } |
| 2758 | |
| 2759 | /** resolveHubClient 的 viewer 版本:hub 模式下使用 bootstrap admin 身份 */ |
| 2760 | private async resolveHubClientAware(): Promise<ResolvedHubClient> { |
no test coverage detected