diff --git a/admin-server/main.go b/admin-server/main.go index ae8a9e1..e445c40 100644 --- a/admin-server/main.go +++ b/admin-server/main.go @@ -27,6 +27,8 @@ var ( // 所以默认**不校验**;只有当你把容器端口直接暴露给不受信的网段、 // 而没有外层认证时才设 NAVI_ADMIN_REQUIRE_TOKEN=1。 requireTokenForWrite = isTruthy(os.Getenv("NAVI_ADMIN_REQUIRE_TOKEN")) + // 浏览器插件同步用的令牌(供安装引导页展示,方便用户拷贝) + syncToken = os.Getenv("NAVI_SYNC_TOKEN") // 本地上传的图标目录(Dashy 通过 /item-icons/ 读取) iconDir = envOr("NAVI_ICON_DIR", filepath.Join(filepath.Dir(confFile), "item-icons")) // 壁纸目录(nginx 通过 /wallpapers/ 提供) @@ -456,6 +458,23 @@ func handleDeleteItem(w http.ResponseWriter, r *http.Request) { jsonResp(w, map[string]string{"status": "ok"}) } +// handleSyncInfo 把浏览器插件需要的接入信息给已登录用户。 +// +// 为何可以在这里返回令牌:/admin/ 整体在门户登录墙之内; +// 而 /api/history/sync 是被门户放行的(否则插件无法上报), +// 所以这个 token 仍然是有意义的凭据,并且不能挂在 /api/ 下暴露。 +func handleSyncInfo(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodGet { + jsonErr(w, 405, "method not allowed") + return + } + jsonResp(w, map[string]any{ + "syncToken": syncToken, + "hasToken": syncToken != "", + "requireAdminToken": requireTokenForWrite, + }) +} + // ── 站点信息:标题 / 副标题 / 顶部导航 / 页脚 ── // 这些东西原先只能在 conf.yml 里手改,现在可在 /admin/ 编辑。 func handlePageInfo(w http.ResponseWriter, r *http.Request) { @@ -628,6 +647,7 @@ func main() { http.HandleFunc("/api/pageinfo", cors(handlePageInfo)) http.HandleFunc("/api/icon", cors(handleIconUpload)) http.HandleFunc("/api/wallpaper", cors(handleWallpaper)) + http.HandleFunc("/api/sync-info", cors(handleSyncInfo)) http.HandleFunc("/api/reload", cors(func(w http.ResponseWriter, r *http.Request) { jsonResp(w, map[string]string{"status": "saved"}) })) diff --git a/web/extension/install.html b/web/extension/install.html index 667c586..6ce4ad1 100644 --- a/web/extension/install.html +++ b/web/extension/install.html @@ -42,6 +42,7 @@ .site input{flex:1;min-width:240px;background:#0b1220;border:1px solid #334155;border-radius:10px; padding:9px 12px;color:#e2e8f0;font-size:14px} .hint{font-size:13px;color:#94a3b8;margin-top:10px} + .lbl{display:block;font-size:12px;font-weight:600;color:#94a3b8;margin:12px 0 0} .done{font-size:13px;color:#86efac;margin-top:8px} @@ -51,12 +52,22 @@
安装后浏览记录会自动同步到本站,并据此把最常访问的服务排到「常用服务」最前面。
在插件设置里粘贴下面这个地址(点「复制」)。同步令牌从部署方的 NAVI_SYNC_TOKEN 环境变量获取。
在插件设置里填下面两项,各自点「复制」再粘贴。
+ +