Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:sparkles: Add a per-section settings read endpoint with revisions

Jeffrey Chen6ae3f69c7e48
diff --git a/app/src/types/api/index.d.ts b/app/src/types/api/index.d.ts
index bcb0d62943..b4e40b2202 100644
--- a/app/src/types/api/index.d.ts
+++ b/app/src/types/api/index.d.ts
@@ -2076,6 +2076,8 @@ export type SettingFlashcard = { "blockquote": boolean; "callout": boolean; "dec
export type SettingFlashcardInput = { "blockquote"?: boolean | null; "callout"?: boolean | null; "deck"?: boolean | null; "heading"?: boolean | null; "list"?: boolean | null; "mark"?: boolean | null; "maximumInterval"?: number | null; "newCardLimit"?: number | null; "requestRetention"?: number | null; "reviewCardLimit"?: number | null; "reviewMode"?: number | null; "superBlock"?: boolean | null; "weights"?: string | null; };
+export type SettingGetSectionRequestInput = { "namespace": string; };
+
export type SettingIconRequestInput = { "icon": string; };
export type SettingImageGeneration = { "modelId": string; "outputFormat": string; "quality": string; "requestTimeout": number; "size": string; };
@@ -2084,7 +2086,7 @@ export type SettingImageGenerationInput = { "modelId"?: string | null; "outputFo
export type SettingIssue = { "field": string; "message": string; "severity": string; };
-export type SettingKeymapRequestInput = { "data"?: { [key: string]: JSONValue } | null; };
+export type SettingKeymapRequestInput = { "data": { [key: string]: JSONValue }; };
export type SettingLogin2faRequestInput = { "code": string; "token": string; };
@@ -2112,7 +2114,7 @@ export type SettingNotifications = { "browserCompatibility": boolean; "docTreeMa
export type SettingNotificationsInput = { "browserCompatibility"?: boolean | null; "docTreeMaxList"?: boolean | null; "formatPainterTip"?: boolean | null; "selectAllIncompleteTip"?: boolean | null; "selectAllTip"?: boolean | null; "tagMaxList"?: boolean | null; "workspaceNotSSD"?: boolean | null; };
-export type SettingOCR = { "aiModelId"?: string; "auto": boolean; "model": string; "provider": string; "reasoningEffort"?: string; "showEmpty"?: boolean; "showError"?: boolean; "showText"?: boolean; "thresholds"?: OCRThresholds; };
+export type SettingOCR = { "aiModelId": string; "auto": boolean; "model": string; "provider": string; "reasoningEffort": string; "showEmpty": boolean; "showError": boolean; "showText"?: boolean; "thresholds": OCRThresholds; };
export type SettingOCRInput = { "aiModelId"?: string | null; "auto": boolean; "model": string; "provider": string; "reasoningEffort"?: string | null; "showEmpty"?: boolean | null; "showError"?: boolean | null; "showText"?: boolean | null; "thresholds"?: OCRThresholdsInput | null; };
@@ -2152,6 +2154,8 @@ export type SettingSecrets = { "items": Array<SettingSecret | null> | null; };
export type SettingSecretsInput = { "items"?: Array<SettingSecretInput | null> | null; };
+export type SettingSectionData = { "conf": SystemAppConf | null; "namespace": string; "revision": number; "settingTasks"?: SettingTaskState; };
+
export type SettingSnpt = { "enabledCSS": boolean; "enabledJS": boolean; };
export type SettingSnptInput = { "enabledCSS"?: boolean | null; "enabledJS"?: boolean | null; };
@@ -2282,7 +2286,7 @@ export type SystemChangelogRequestInput = { "force"?: boolean | null; };
export type SystemCheckUpdateRequestInput = { "showMsg": boolean; };
-export type SystemConfData = { "conf": SystemAppConf | null; "isPublish": boolean; "settingTasks"?: SettingTaskState; "start": boolean; };
+export type SystemConfData = { "conf": SystemAppConf | null; "isPublish": boolean; "revision": number; "settingTasks"?: SettingTaskState; "start": boolean; };
export type SystemCustomEmojiRequestInput = { "file"?: Blob; "name"?: string; "url"?: string; };
@@ -6790,6 +6794,17 @@ export interface APIPOSTRoutes {
/** 服务器路由要求;资源权限与笔记本租约仍由内核校验 */
authorization?: readonly ["authenticated","admin","writable"];
};
+ /**
+ * 读取单个配置段,字段与脱敏规则与 /api/system/getConf 一致,仅返回请求的配置段以减少传输量。
+ * namespace 必须是已注册的配置段;需要完整配置的启动和重连场景仍使用 /api/system/getConf。
+ */
+ "/api/setting/getSection": {
+ request: SettingGetSectionRequestInput;
+ response: { "code": 0; "data": SettingSectionData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "json";
+ /** 服务器路由要求;资源权限与笔记本租约仍由内核校验 */
+ authorization?: readonly ["authenticated"];
+ };
"/api/setting/login2faCloudUser": {
request: SettingLogin2faRequestInput;
response: Login2faEnvelope | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
@@ -6847,7 +6862,7 @@ export interface APIPOSTRoutes {
};
/**
* 使用共享规范化规则;智能体确认超时负数回退 600 秒,0 保留无限等待语义。
- * web 省略时保留当前配置;初始搜索为 Exa、抓取为直接请求,可独立切换到共用密钥的 DeepSeek。
+ * web 初始搜索为 Exa、抓取为直接请求,可独立切换到共用密钥的 DeepSeek。
* 工具调用轮数和输出 token 上限的负数归零;温度超出 0–2 回退 1。
* 嵌入并发数和批大小省略、null 或小于 1 时分别使用 8 和 10,超过上限时分别限制为 64 和 128。
* ChatGPT 账户绑定变化时与主配置一起可恢复提交,失败时回滚且不发布新配置;未变化时不访问绑定存储。
@@ -6891,8 +6906,8 @@ export interface APIPOSTRoutes {
authorization?: readonly ["authenticated","admin","writable"];
};
/**
- * 使用与启动、导入相同的规范化规则并同步保存。锚文本长度 1–5120 保持不变,小于 1 回退 64。
- * 字体大小超出 9–72 回退 16;省略字体列表和图片标题字段时继续保留原有兼容行为。
+ * 使用与启动、导入相同的规范化规则并同步保存。
+ * 锚文本长度 1–5120 保持不变,小于 1 回退 64;字体大小超出 9–72 回退 16。
* backlinkGlobalSort、backlinkBlockSort、floatWindowMode、headingEmbedMode 仅接受 0、1、2,越界值回退 0。
* databaseAttrClickMode、databaseAttrViewMode 仅接受 0、1;codeTabSpaces 仅接受 0、2、4、6、8,越界值回退 0。
*/
@@ -6941,7 +6956,7 @@ export interface APIPOSTRoutes {
authorization?: readonly ["authenticated","admin","writable"];
};
/**
- * 使用与启动、导入相同的路径和数值规范化规则;省略顶层笔记本文档和默认图标选项时保留当前值。
+ * 使用与启动、导入相同的路径和数值规范化规则。
* maxListCount 小于 1 回退 512,largeFileWarningSize 小于 2 回退 8,两者大于 10240 时截断至 10240。
*/
"/api/setting/setFiletree": {
@@ -6969,6 +6984,10 @@ export interface APIPOSTRoutes {
/** 服务器路由要求;资源权限与笔记本租约仍由内核校验 */
authorization?: readonly ["authenticated","admin","writable"];
};
+ /**
+ * 整体替换快捷键配置:data 必须提交完整的快捷键对象,只提交部分分组会清空未提交的快捷键。
+ * 单条快捷键请使用 /api/setting/patch 的 keymap 命名空间,该接口按对象递归合并。
+ */
"/api/setting/setKeymap": {
request: SettingKeymapRequestInput;
response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
@@ -6976,6 +6995,9 @@ export interface APIPOSTRoutes {
/** 服务器路由要求;资源权限与笔记本租约仍由内核校验 */
authorization?: readonly ["authenticated","admin","writable"];
};
+ /**
+ * 认证账户须提交完整数组,传 null 或空数组表示清空账户。
+ */
"/api/setting/setPublish": {
request: SetPublishRequestInput;
response: { "code": 0; "data": SettingPublishData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
@@ -6984,9 +7006,8 @@ export interface APIPOSTRoutes {
authorization?: readonly ["authenticated","admin","writable"];
};
/**
- * 使用与启动、导入相同的规范化规则;limit 小于 1 回退 64,1–31 提升至 32。
- * limit 大于 10240 时截断至 10240。
- * 省略汉字敏感、自定义块和脑图选项时保留当前值;反链提及关键词上限小于 1 回退 512。
+ * 使用与启动、导入相同的规范化规则;limit 小于 1 回退 64,1–31 提升至 32,大于 10240 时截断至 10240。
+ * 反链提及关键词上限小于 1 回退 512。
*/
"/api/setting/setSearch": {
request: SetSearchRequestInput;
diff --git a/kernel/api/router.go b/kernel/api/router.go
index 13f1c2f731..bc7f244686 100644
--- a/kernel/api/router.go
+++ b/kernel/api/router.go
@@ -694,6 +694,7 @@ func registerTransactionsRoutes(ginServer *gin.Engine) {
// registerSettingRoutes 注册本域的契约路由。
func registerSettingRoutes(ginServer *gin.Engine) {
ginServer.Handle("POST", "/api/setting/patch", contractRouteHandlers(apicontract.PatchSetting, patchSetting)...)
+ ginServer.Handle("POST", "/api/setting/getSection", contractRouteHandlers(apicontract.GetSettingSection, getSettingSection)...)
ginServer.Handle("POST", "/api/setting/resetSettings", contractRouteHandlers(apicontract.ResetSettings, resetSettings)...)
ginServer.Handle("POST", "/api/setting/confirmSettingsReset", contractRouteHandlers(apicontract.ConfirmSettingsReset, confirmSettingsReset)...)
ginServer.Handle("POST", "/api/setting/setEditor", contractRouteHandlers(apicontract.SetEditor, setEditor)...)
diff --git a/kernel/api/setting_read.go b/kernel/api/setting_read.go
new file mode 100644
index 0000000000..3b71dd7b86
--- /dev/null
+++ b/kernel/api/setting_read.go
@@ -0,0 +1,134 @@
+package api
+
+import (
+ "github.com/gin-gonic/gin"
+ "github.com/siyuan-note/siyuan/kernel/apicontract"
+ "github.com/siyuan-note/siyuan/kernel/conf"
+ "github.com/siyuan-note/siyuan/kernel/model"
+ "github.com/siyuan-note/siyuan/kernel/util"
+)
+
+// visibleConf 返回按请求角色和宿主环境裁剪后的配置副本。
+// 所有读取配置的端点共用这一套可见性规则,避免各端点自行裁剪导致凭据或路径泄露。
+func visibleConf(c *gin.Context) (masked *model.AppConf, isPublish bool, err error) {
+ masked, err = model.GetMaskedConf()
+ if err != nil {
+ return nil, false, err
+ }
+ if !masked.Sync.Load().Enabled || (0 == masked.Sync.Load().Provider && !model.IsSubscriber()) {
+ masked.Sync.Load().Stat = model.Conf.Language(53)
+ }
+
+ // REF: https://github.com/siyuan-note/siyuan/issues/11364
+ role := model.GetGinContextRole(c)
+ isPublish = model.IsReadOnlyRole(role)
+ if isPublish {
+ masked.ReadOnly = true
+ }
+ if !model.IsValidRole(role, []model.Role{model.RoleAdministrator}) {
+ model.HideConfSecret(masked)
+ }
+ if model.IsReadOnlyRoleContext(c) {
+ masked.UILayout.Store(&conf.UILayout{})
+ }
+
+ // 浏览器环境下不返回工作空间绝对路径,避免泄露用户名等敏感信息
+ // 原生客户端(桌面 Electron、移动端)UA 以 "SiYuan/" 开头,照常返回真实路径
+ // REF: https://github.com/siyuan-note/siyuan/issues/17410
+ if util.IsBrowserRequest(c) {
+ masked.System.Load().WorkspaceDir = ""
+ masked.System.Load().AppDir = ""
+ masked.System.Load().ConfDir = ""
+ masked.System.Load().DataDir = ""
+ masked.System.Load().HomeDir = ""
+ }
+ return masked, isPublish, nil
+}
+
+// sectionConfPayload 从完整配置的转换结果中取出单个配置段,返回 nil 表示命名空间不可读取。
+// 复用 systemConfPayload 保证字段投影与 /api/system/getConf 完全一致。
+func sectionConfPayload(value *apicontract.SystemAppConf, namespace string) *apicontract.SystemAppConf {
+ section := &apicontract.SystemAppConf{}
+ switch namespace {
+ case "appearance":
+ section.Appearance = value.Appearance
+ case "fileTree":
+ section.FileTree = value.FileTree
+ case "tag":
+ section.Tag = value.Tag
+ case "editor":
+ section.Editor = value.Editor
+ case "export":
+ section.Export = value.Export
+ case "graph":
+ section.Graph = value.Graph
+ case "uiLayout":
+ section.UILayout = value.UILayout
+ case "keymap":
+ section.Keymap = value.Keymap
+ case "sync":
+ section.Sync = value.Sync
+ case "search":
+ section.Search = value.Search
+ case "flashcard":
+ section.Flashcard = value.Flashcard
+ case "ai":
+ section.AI = value.AI
+ case "ocr":
+ section.OCR = value.OCR
+ case "secrets":
+ section.Secrets = value.Secrets
+ case "variables":
+ section.Variables = value.Variables
+ case "bazaar":
+ section.Bazaar = value.Bazaar
+ case "stat":
+ section.Stat = value.Stat
+ case "api":
+ section.Api = value.Api
+ case "repo":
+ section.Repo = value.Repo
+ case "publish":
+ section.Publish = value.Publish
+ case "onboarding":
+ section.Onboarding = value.Onboarding
+ case "snippet":
+ section.Snippet = value.Snippet
+ case "system":
+ // 访问授权由 system 段落驱动,同时返回对应的顶层字段。
+ section.System = value.System
+ section.Api = value.Api
+ section.OIDC = value.OIDC
+ section.AccessAuthCode = value.AccessAuthCode
+ section.ReadOnly = value.ReadOnly
+ default:
+ return nil
+ }
+ return section
+}
+
+var getSettingSection = contractHandler(apicontract.GetSettingSection, func(c *gin.Context, request apicontract.SettingGetSectionRequest) apicontract.Response[apicontract.SettingSectionData] {
+ if _, ok := model.SectionSpecByNamespace(request.Namespace); !ok {
+ return apicontract.Failure[apicontract.SettingSectionData](-1, "unsupported settings namespace: "+request.Namespace)
+ }
+ // 记录该段本次读取时的版本号再读取配置:版本号不大于该值的通知都已包含在本次响应中。
+ revision := model.ConfNamespaceRevision(request.Namespace)
+ masked, _, err := visibleConf(c)
+ if err != nil {
+ return apicontract.Failure[apicontract.SettingSectionData](-1, "get conf failed: "+err.Error())
+ }
+ full, err := systemConfPayload(masked)
+ if err != nil {
+ return apicontract.Failure[apicontract.SettingSectionData](-1, "get conf failed: "+err.Error())
+ }
+ section := sectionConfPayload(full, request.Namespace)
+ if nil == section {
+ return apicontract.Failure[apicontract.SettingSectionData](-1, "unsupported settings namespace: "+request.Namespace)
+ }
+ return apicontract.Success(apicontract.SettingSectionData{
+ Namespace: request.Namespace,
+ Conf: section,
+ SettingTasks: activeSettingTasks(),
+ Revision: revision,
+ })
+})
diff --git a/kernel/api/setting_read_test.go b/kernel/api/setting_read_test.go
new file mode 100644
index 0000000000..4ecb705d03
--- /dev/null
+++ b/kernel/api/setting_read_test.go
@@ -0,0 +1,125 @@
+package api
+
+import (
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "strings"
+ "testing"
+
+ "github.com/gin-gonic/gin"
+ "github.com/siyuan-note/siyuan/kernel/apicontract"
+ "github.com/siyuan-note/siyuan/kernel/conf"
+ "github.com/siyuan-note/siyuan/kernel/model"
+ "github.com/siyuan-note/siyuan/kernel/util"
+)
+
+func requestSettingSection(t *testing.T, role model.Role, body string) apicontract.SettingSectionData {
+ t.Helper()
+ gin.SetMode(gin.TestMode)
+ engine := gin.New()
+ engine.Use(func(c *gin.Context) { c.Set(model.RoleContextKey, role) })
+ engine.POST("/api/setting/getSection", getSettingSection)
+ recorder := httptest.NewRecorder()
+ engine.ServeHTTP(recorder, httptest.NewRequest(http.MethodPost, "/api/setting/getSection", strings.NewReader(body)))
+ requireAPIContract(t, "POST", "/api/setting/getSection", recorder)
+ var response struct {
+ Code int `json:"code"`
+ Data apicontract.SettingSectionData `json:"data"`
+ Msg string `json:"msg"`
+ }
+ if err := json.Unmarshal(recorder.Body.Bytes(), &response); err != nil {
+ t.Fatalf("unmarshal getSection response failed: %s (%v)", recorder.Body.String(), err)
+ }
+ if response.Code != 0 {
+ t.Fatalf("getSection failed: %s", response.Msg)
+ }
+ return response.Data
+}
+
+func TestAPIContractSettingSectionReadsSingleSection(t *testing.T) {
+ previousConf, previousReadOnly := model.Conf, util.ReadOnly
+ util.ReadOnly = true
+ t.Cleanup(func() { model.Conf, util.ReadOnly = previousConf, previousReadOnly })
+ model.Conf = model.NewAppConf()
+ model.Conf.Editor.Store(conf.NewEditor())
+ model.Conf.Editor.Load().FontSize = 18
+ model.Conf.FileTree.Store(conf.NewFileTree())
+ model.Conf.FileTree.Load().Sort = 3
+ model.Conf.AI.Store(conf.NewAI())
+ model.NormalizeAppConf(model.Conf)
+
+ data := requestSettingSection(t, model.RoleAdministrator, `{"namespace":"editor"}`)
+ if data.Namespace != "editor" || data.Conf == nil || data.Conf.Editor == nil {
+ t.Fatalf("missing editor section: %+v", data)
+ }
+ if data.Conf.Editor.FontSize != 18 {
+ t.Fatalf("editor section did not reflect the stored value: %+v", data.Conf.Editor)
+ }
+ // 其余配置段不随单段读取返回,避免重复传输完整配置。
+ if data.Conf.FileTree != nil || data.Conf.Appearance != nil || data.Conf.AI != nil || data.Conf.Keymap != nil {
+ t.Fatalf("unexpected sections in a single-section response: %+v", data.Conf)
+ }
+ if data.SettingTasks == nil {
+ t.Fatal("setting tasks snapshot missing")
+ }
+ if data.Revision != model.ConfNamespaceRevision("editor") {
+ t.Fatalf("revision %d is not the editor revision %d", data.Revision, model.ConfNamespaceRevision("editor"))
+ }
+}
+
+func TestAPIContractSettingSectionVisibility(t *testing.T) {
+ previousConf, previousReadOnly := model.Conf, util.ReadOnly
+ util.ReadOnly = true
+ t.Cleanup(func() { model.Conf, util.ReadOnly = previousConf, previousReadOnly })
+ model.Conf = model.NewAppConf()
+ ai := conf.NewAI()
+ ai.Providers = []*conf.Provider{{ID: "20261019120000-prov001", BaseURL: "https://example.com", APIKey: "secret-key", Enabled: true}}
+ model.Conf.AI.Store(ai)
+ model.Conf.System.Store(conf.NewSystem())
+ model.NormalizeAppConf(model.Conf)
+
+ admin := requestSettingSection(t, model.RoleAdministrator, `{"namespace":"ai"}`)
+ if admin.Conf == nil || admin.Conf.AI == nil || len(admin.Conf.AI.Providers) != 1 ||
+ admin.Conf.AI.Providers[0].APIKey != "secret-key" {
+ t.Fatalf("administrator did not receive AI credentials: %+v", admin.Conf)
+ }
+
+ // 非管理员使用与 getConf 相同的脱敏规则,不返回任何凭据。
+ reader := requestSettingSection(t, model.RoleReader, `{"namespace":"ai"}`)
+ if reader.Conf == nil || reader.Conf.AI == nil || len(reader.Conf.AI.Providers) != 0 {
+ t.Fatalf("non-administrator received AI credentials: %+v", reader.Conf)
+ }
+
+ system := requestSettingSection(t, model.RoleAdministrator, `{"namespace":"system"}`)
+ if system.Conf == nil || system.Conf.System == nil || system.Conf.Api == nil || system.Conf.OIDC == nil {
+ t.Fatalf("system section did not include the access authorization fields: %+v", system.Conf)
+ }
+ // 发布角色读取 system 段时与完整配置一致,带上只读标记。
+ publish := requestSettingSection(t, model.RoleReader, `{"namespace":"system"}`)
+ if publish.Conf == nil || !publish.Conf.ReadOnly {
+ t.Fatalf("system section lost the read-only flag: %+v", publish.Conf)
+ }
+}
+
+func TestAPIContractSettingSectionRejectsUnknownNamespace(t *testing.T) {
+ previousConf, previousReadOnly := model.Conf, util.ReadOnly
+ util.ReadOnly = true
+ gin.SetMode(gin.TestMode)
+ t.Cleanup(func() { model.Conf, util.ReadOnly = previousConf, previousReadOnly })
+ model.Conf = model.NewAppConf()
+ model.NormalizeAppConf(model.Conf)
+
+ engine := gin.New()
+ engine.POST("/api/setting/getSection", getSettingSection)
+ for _, body := range []string{`{"namespace":"unknown"}`, `{"namespace":""}`, `{}`} {
+ recorder := httptest.NewRecorder()
+ engine.ServeHTTP(recorder, httptest.NewRequest(http.MethodPost, "/api/setting/getSection", strings.NewReader(body)))
+ var response struct {
+ Code int `json:"code"`
+ }
+ if err := json.Unmarshal(recorder.Body.Bytes(), &response); err != nil || response.Code == 0 {
+ t.Fatalf("invalid namespace accepted: %s (%v)", body, err)
+ }
+ }
+}
diff --git a/kernel/api/system.go b/kernel/api/system.go
index 476cf3d187..3a673f47bd 100644
--- a/kernel/api/system.go
+++ b/kernel/api/system.go
@@ -800,49 +800,20 @@ func preserveImportedAISecrets(imported, current *conf.AI) {
var getConf = contractHandler(apicontract.SystemGetConf, func(c *gin.Context, request apicontract.EmptyRequest) (ret apicontract.Response[apicontract.SystemConfData]) {
ret = apicontract.Success(apicontract.SystemConfData{})
- maskedConf, err := model.GetMaskedConf()
+ // 先记录提交序号再读取配置:序号不大于该值的通知都已包含在本次响应中。
+ revision := model.ConfSettingRevision.Load()
+ maskedConf, isPublish, err := visibleConf(c)
if err != nil {
ret = apicontract.Failure[apicontract.SystemConfData](-1, "get conf failed: "+err.Error())
return
}
- if !maskedConf.Sync.Load().Enabled || (0 == maskedConf.Sync.Load().Provider && !model.IsSubscriber()) {
- maskedConf.Sync.Load().Stat = model.Conf.Language(53)
- }
-
- // REF: https://github.com/siyuan-note/siyuan/issues/11364
- role := model.GetGinContextRole(c)
- isPublish := model.IsReadOnlyRole(role)
- if isPublish {
- maskedConf.ReadOnly = true
- }
- if !model.IsValidRole(role, []model.Role{
- model.RoleAdministrator,
- }) {
- model.HideConfSecret(maskedConf)
- }
-
- if model.IsReadOnlyRoleContext(c) {
- maskedConf.UILayout.Store(&conf.UILayout{})
- }
-
- // 浏览器环境下不返回工作空间绝对路径,避免泄露用户名等敏感信息
- // 原生客户端(桌面 Electron、移动端)UA 以 "SiYuan/" 开头,照常返回真实路径
- // REF: https://github.com/siyuan-note/siyuan/issues/17410
- if util.IsBrowserRequest(c) {
- maskedConf.System.Load().WorkspaceDir = ""
- maskedConf.System.Load().AppDir = ""
- maskedConf.System.Load().ConfDir = ""
- maskedConf.System.Load().DataDir = ""
- maskedConf.System.Load().HomeDir = ""
- }
-
config, err := systemConfPayload(maskedConf)
if err != nil {
return apicontract.Failure[apicontract.SystemConfData](-1, "get conf failed: "+err.Error())
}
ret = apicontract.Success(apicontract.SystemConfData{Conf: config, Start: !util.IsUILoaded.Load(), IsPublish: isPublish,
- SettingTasks: activeSettingTasks()})
+ SettingTasks: activeSettingTasks(), Revision: revision})
return
})
diff --git a/kernel/apicontract/schema.json b/kernel/apicontract/schema.json
index bee7d18db9..ac43b5ab1b 100644
--- a/kernel/apicontract/schema.json
+++ b/kernel/apicontract/schema.json
@@ -47439,6 +47439,18 @@
},
"additionalProperties": false
},
+ "SettingGetSectionRequestInput": {
+ "type": "object",
+ "properties": {
+ "namespace": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "namespace"
+ ],
+ "additionalProperties": false
+ },
"SettingIconRequestInput": {
"type": "object",
"properties": {
@@ -47559,19 +47571,15 @@
"type": "object",
"properties": {
"data": {
- "anyOf": [
- {
- "type": "object",
- "additionalProperties": {
- "$ref": "#/$defs/JSONValue"
- }
- },
- {
- "type": "null"
- }
- ]
+ "type": "object",
+ "additionalProperties": {
+ "$ref": "#/$defs/JSONValue"
+ }
}
},
+ "required": [
+ "data"
+ ],
"additionalProperties": false
},
"SettingLogin2faRequestInput": {
@@ -48382,9 +48390,14 @@
}
},
"required": [
+ "aiModelId",
"auto",
"model",
- "provider"
+ "provider",
+ "reasoningEffort",
+ "showEmpty",
+ "showError",
+ "thresholds"
],
"additionalProperties": false
},
@@ -49772,6 +49785,36 @@
},
"additionalProperties": false
},
+ "SettingSectionData": {
+ "type": "object",
+ "properties": {
+ "conf": {
+ "anyOf": [
+ {
+ "$ref": "#/$defs/SystemAppConf"
+ },
+ {
+ "type": "null"
+ }
+ ]
+ },
+ "namespace": {
+ "type": "string"
+ },
+ "revision": {
+ "type": "integer"
+ },
+ "settingTasks": {
+ "$ref": "#/$defs/SettingTaskState"
+ }
+ },
+ "required": [
+ "conf",
+ "namespace",
+ "revision"
+ ],
+ "additionalProperties": false
+ },
"SettingSnpt": {
"type": "object",
"properties": {
@@ -51819,6 +51862,9 @@
"isPublish": {
"type": "boolean"
},
+ "revision": {
+ "type": "integer"
+ },
"settingTasks": {
"$ref": "#/$defs/SettingTaskState"
},
@@ -51829,6 +51875,7 @@
"required": [
"conf",
"isPublish",
+ "revision",
"start"
],
"additionalProperties": false
@@ -162891,6 +162938,84 @@
]
}
},
+ {
+ "method": "POST",
+ "path": "/api/setting/getSection",
+ "handler": "getSettingSection",
+ "authorization": [
+ "authenticated"
+ ],
+ "body": "json",
+ "request": {
+ "$ref": "#/$defs/SettingGetSectionRequestInput"
+ },
+ "response": {
+ "anyOf": [
+ {
+ "type": "object",
+ "properties": {
+ "code": {
+ "type": "integer",
+ "enum": [
+ 0
+ ]
+ },
+ "data": {
+ "$ref": "#/$defs/SettingSectionData"
+ },
+ "msg": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "code",
+ "msg",
+ "data"
+ ],
+ "additionalProperties": false
+ },
+ {
+ "type": "object",
+ "properties": {
+ "code": {
+ "type": "integer",
+ "enum": [
+ -1
+ ]
+ },
+ "data": {
+ "anyOf": [
+ {
+ "type": "object",
+ "properties": {
+ "closeTimeout": {
+ "type": "number"
+ }
+ },
+ "required": [
+ "closeTimeout"
+ ],
+ "additionalProperties": false
+ },
+ {
+ "type": "null"
+ }
+ ]
+ },
+ "msg": {
+ "type": "string"
+ }
+ },
+ "required": [
+ "code",
+ "msg",
+ "data"
+ ],
+ "additionalProperties": true
+ }
+ ]
+ }
+ },
{
"method": "POST",
"path": "/api/setting/login2faCloudUser",
diff --git a/kernel/apicontract/setting_read.go b/kernel/apicontract/setting_read.go
new file mode 100644
index 0000000000..44eb04c2af
--- /dev/null
+++ b/kernel/apicontract/setting_read.go
@@ -0,0 +1,19 @@
+package apicontract
+
+// SettingGetSectionRequest 读取单个配置段。namespace 与 SetConf/SettingsPatch 的命名空间一致。
+type SettingGetSectionRequest struct {
+ Namespace string `json:"namespace" api:"trim"`
+}
+
+// SettingSectionData 返回单个配置段的脱敏内容,其余字段为 null。
+// 可见字段与 /api/system/getConf 完全一致:非管理员不返回凭据,只读角色不返回界面布局,浏览器请求不返回工作空间路径。
+type SettingSectionData struct {
+ Namespace string `json:"namespace"`
+ // Conf 仅填充请求的配置段;system 同时带回 api、oidc、accessAuthCode 和 readOnly。
+ Conf *SystemAppConf `json:"conf"`
+ // SettingTasks 为当前仍执行的设置维护任务,用于恢复任务阻塞。
+ SettingTasks *SettingTaskState `json:"settingTasks,omitempty"`
+ // Revision 是该段最近一次提交的版本号,同一命名空间严格递增;
+ // 客户端据此丢弃版本号相等的重复通知,内核重启后版本号归零会重新触发读取。
+ Revision uint64 `json:"revision"`
+}
diff --git a/kernel/apicontract/system.go b/kernel/apicontract/system.go
index 5a87d6adaf..c327ecc563 100644
--- a/kernel/apicontract/system.go
+++ b/kernel/apicontract/system.go
@@ -50,6 +50,8 @@ type SystemConfData struct {
IsPublish bool `json:"isPublish"`
// SettingTasks 为当前仍执行的设置维护任务,前端初始化和重连时恢复任务阻塞。
SettingTasks *SettingTaskState `json:"settingTasks,omitempty"`
+ // Revision 是读取开始前的配置提交序号,客户端据此丢弃已包含在本次读取中的通知。
+ Revision uint64 `json:"revision"`
}
type SettingTask struct {