feat(install): show the sync token on the install page
插件必须填 NAVI_SYNC_TOKEN,但页面上没有任何地方能看到它 —— 用户只能去翻 .env,实际就是配不起来。 - admin-server 新增 GET /admin/api/sync-info,返回 syncToken / hasToken。 放在 /admin/ 下而不是 /api/ 下是必须的:插件上报用的 /api/history/sync 被门户 auth_request 放行,若令牌挂在同一前缀下就等于公开。 实测 /api/history/sync-info 返回 401,只有 /admin/api/sync-info 能取到。 - 安装引导页把「第一步」改为填写两项(服务地址 + 同步令牌),各自可复制; 服务端未设令牌时提示留空即可;未登录时提示需先登录门户。 - README 补充对应说明。
This commit is contained in:
@ -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"})
|
||||
}))
|
||||
|
||||
Reference in New Issue
Block a user