An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
♻️ Complete Lute conversion API contracts https://github.com/siyuan-note/siyuan/issues/19378
Danielfa408bcc6913
diff --git a/app/src/types/api/index.d.ts b/app/src/types/api/index.d.tsindex 2dc4bb4690..cf86e5bb63 100644--- a/app/src/types/api/index.d.ts+++ b/app/src/types/api/index.d.ts@@ -94,6 +94,8 @@ export type CloseNotebookRequestInput = { "notebook": string; };export type ContentWordCountRequestInput = { "content": string; "reqId"?: JSONValue | null; };+export type CopyStdMarkdownRequestInput = { "adjustHeadingLevel"?: boolean | null; "assetsDestSpace2Underscore"?: boolean | null; "fillCSSVar"?: boolean | null; "id": string; "imgTag"?: boolean | null; };+export type CreateEncryptedNotebookRequestInput = { "name": string; "password": string; };export type CreateNotebookData = { "notebook": Notebook | null; };@@ -116,6 +118,8 @@ export type CriterionTypes = { "audioBlock": boolean; "blockquote": boolean; "caexport type CriterionTypesInput = { "audioBlock"?: boolean | null; "blockquote"?: boolean | null; "callout"?: boolean | null; "codeBlock"?: boolean | null; "databaseBlock"?: boolean | null; "document"?: boolean | null; "embedBlock"?: boolean | null; "heading"?: boolean | null; "htmlBlock"?: boolean | null; "iframeBlock"?: boolean | null; "list"?: boolean | null; "listItem"?: boolean | null; "mathBlock"?: boolean | null; "paragraph"?: boolean | null; "superBlock"?: boolean | null; "table"?: boolean | null; "videoBlock"?: boolean | null; "widgetBlock"?: boolean | null; };+export type DOMData = { "dom": string; };+export type DOMTextRequestInput = { "dom": string; };export type DailyNoteBlockRequestInput = { "data": string; "dataType": string; "notebook": string; };@@ -154,6 +158,12 @@ export type GetSnippetRequestInput = { "enabled": number; "keyword"?: string | nexport type GetTagRequestInput = { "app"?: string | null; "ignoreMaxListHint"?: boolean | null; "sort"?: number | null; };+export type HTMLClipboardPreflight = { "converted": boolean; "dom"?: string; "normalizedHTML"?: string; "useHTML": boolean; };++export type HTMLClipboardRequestInput = { "dom": string; "mathML"?: string | null; "notebook"?: string | null; "office"?: string | null; "officeMathHTML"?: string | null; "preflight"?: boolean | null; "preparedHTML"?: boolean | null; "preserveSourceFormat"?: boolean | null; "skipBase64Assets"?: boolean | null; "skipInlineSVGAssets"?: boolean | null; "skipLocalAssets"?: boolean | null; "text"?: string | null; "wps"?: string | null; };++export type HTMLData = { "html": string; };+export type HeadingChildrenRequestInput = { "id": string; "removeFoldAttr"?: boolean | null; };export type HeadingFoldRequestInput = { "id": string; "scope": string; };@@ -208,6 +218,8 @@ export type ListNotebooksRequestInput = { "flashcard"?: boolean | null; };export type LockScreenRequestInput = { "lockScreenMode": number; };+export type MarkdownHTMLRequestInput = { "markdown": string; "mode"?: string | null; };+export type MoveBlockRequestInput = { "id": string; "parentID"?: string | null; "previousID"?: string | null; };export type NetImageAssetsRequestInput = { "id": string; "url"?: string | null; };@@ -382,6 +394,10 @@ export type ViewStatePatchRequestInput = { "key": string; "removeKeys"?: Array<sexport type VirtualBlockRefRequestInput = { "keywords": Array<string>; };+export type WPSPresentationData = { "converted": boolean; "dom": string; };++export type WPSPresentationRequestInput = { "data": string; "text"?: string | null; "type": string; };+export type WordCountData = { "reqId": JSONValue; "stat": BlockStat | null; };export type WorkspaceAVBuiltinColorUpdateInput = { "customized"?: boolean | null; "dark"?: InlineStyleThemeInput | null; "hidden"?: boolean | null; "index"?: number | null; "light"?: InlineStyleThemeInput | null; };@@ -686,11 +702,6 @@ export type APILegacyPOSTPath ="/api/inbox/getShorthand" |"/api/inbox/getShorthands" |"/api/inbox/removeShorthands" |- "/api/lute/copyStdMarkdown" |- "/api/lute/html2BlockDOM" |- "/api/lute/md2html" |- "/api/lute/spinBlockDOM" |- "/api/lute/wpsPresentation2BlockDOM" |"/api/network/echo" |"/api/network/echo/*path" |"/api/network/forwardProxy" |@@ -1275,6 +1286,31 @@ export interface APIPOSTRoutes {response: { "code": 0; "data": SearchHistoryData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };body: "json";};+ "/api/lute/copyStdMarkdown": {+ request: CopyStdMarkdownRequestInput;+ response: { "code": 0; "data": string; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/lute/html2BlockDOM": {+ request: HTMLClipboardRequestInput;+ response: { "code": 0; "data": string | HTMLClipboardPreflight; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/lute/md2html": {+ request: MarkdownHTMLRequestInput;+ response: { "code": 0; "data": HTMLData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/lute/spinBlockDOM": {+ request: DOMTextRequestInput;+ response: { "code": 0; "data": DOMData; "msg": string; } | { "code": -1 | 413; "data": { "closeTimeout": number; } | null; "msg": string; };+ body: "json";+ };+ "/api/lute/wpsPresentation2BlockDOM": {+ request: WPSPresentationRequestInput;+ response: { "code": 0; "data": WPSPresentationData; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null | WPSPresentationData; "msg": string; };+ body: "json";+ };"/api/notebook/changeMasterPassword": {request: ChangeMasterPasswordRequestInput;response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };diff --git a/kernel/api/contract.go b/kernel/api/contract.goindex 69f7eb8e69..ce231a51a4 100644--- a/kernel/api/contract.go+++ b/kernel/api/contract.go@@ -61,7 +61,7 @@ func contractHandler[Request, Data any](endpoint apicontract.Endpoint[Request, Drequest, err = endpoint.Decode(c.Request.Body)}if err != nil {- c.JSON(http.StatusOK, apicontract.Failure[Data](-1, err.Error()))+ c.JSON(http.StatusOK, endpoint.DecodeFailure(err))return}c.JSON(http.StatusOK, handler(c, request))diff --git a/kernel/api/contract_utility_test.go b/kernel/api/contract_utility_test.gonew file mode 100644index 0000000000..30abce8eca--- /dev/null+++ b/kernel/api/contract_utility_test.go@@ -0,0 +1,40 @@+package api++import (+ "encoding/json"+ "net/http/httptest"+ "strings"+ "testing"++ "github.com/gin-gonic/gin"+ "github.com/siyuan-note/siyuan/kernel/util"+)++func TestAPIContractUtilityResponses(t *testing.T) {+ previous := util.SnippetsPath+ util.SnippetsPath = t.TempDir()+ t.Cleanup(func() { util.SnippetsPath = previous })+ engine := gin.New()+ engine.POST("/api/lute/md2html", md2HTML)+ engine.POST("/api/notification/pushMsg", pushMsg)+ engine.POST("/api/notification/pushErrMsg", pushErrMsg)+ for _, entry := range []struct {+ path, body string+ code int+ }{+ {"/api/lute/md2html", `{"markdown":"hello","mode":null}`, 0},+ {"/api/lute/md2html", `{"markdown":"","mode":"invalid"}`, -1},+ {"/api/notification/pushMsg", `{"msg":" hello ","timeout":1.9}`, 0},+ {"/api/notification/pushErrMsg", `{"msg":"hello","timeout":null}`, 0},+ } {+ recorder := httptest.NewRecorder()+ engine.ServeHTTP(recorder, httptest.NewRequest("POST", entry.path, strings.NewReader(entry.body)))+ requireAPIContract(t, "POST", entry.path, recorder)+ var response struct {+ Code int `json:"code"`+ }+ if err := json.Unmarshal(recorder.Body.Bytes(), &response); err != nil || response.Code != entry.code {+ t.Fatalf("%s: %s, %v", entry.path, recorder.Body.String(), err)+ }+ }+}diff --git a/kernel/api/contract_wps_test.go b/kernel/api/contract_wps_test.gonew file mode 100644index 0000000000..0c931813d9--- /dev/null+++ b/kernel/api/contract_wps_test.go@@ -0,0 +1,22 @@+package api++import (+ "net/http/httptest"+ "strings"+ "testing"++ "github.com/gin-gonic/gin"+)++func TestAPIContractWPSFailurePayload(t *testing.T) {+ engine := gin.New()+ engine.POST("/api/lute/wpsPresentation2BlockDOM", wpsPresentation2BlockDOM)+ for _, body := range []string{"{", `{}`, `{"data":null,"type":"objects"}`, `{"data":"x","text":42,"type":"objects"}`} {+ recorder := httptest.NewRecorder()+ engine.ServeHTTP(recorder, httptest.NewRequest("POST", "/api/lute/wpsPresentation2BlockDOM", strings.NewReader(body)))+ requireAPIContract(t, "POST", "/api/lute/wpsPresentation2BlockDOM", recorder)+ if !strings.Contains(recorder.Body.String(), `"code":-1`) || !strings.Contains(recorder.Body.String(), `"data":{"converted":false,"dom":""}`) {+ t.Fatalf("WPS failure payload changed: %s", recorder.Body.String())+ }+ }+}diff --git a/kernel/api/lute.go b/kernel/api/lute.goindex cde7112fdf..b82b57f29b 100644--- a/kernel/api/lute.go+++ b/kernel/api/lute.go@@ -17,6 +17,7 @@package apiimport (+ "github.com/siyuan-note/siyuan/kernel/apicontract""html""net/http""os"@@ -42,36 +43,10 @@ const maxSpinBlockDOMBytes = 1024 * 1024// maxHTML2BlockDOMRequestBytes 限制 html2BlockDOM 请求体的最大字节数。const maxHTML2BlockDOMRequestBytes int64 = 128 * 1024 * 1024-func copyStdMarkdown(c *gin.Context) {- ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- id := arg["id"].(string)- assetsDestSpace2Underscore := false- if nil != arg["assetsDestSpace2Underscore"] {- assetsDestSpace2Underscore = arg["assetsDestSpace2Underscore"].(bool)- }-- fillCSSVar := false- if nil != arg["fillCSSVar"] {- fillCSSVar = arg["fillCSSVar"].(bool)- }-- adjustHeadingLevel := false- if nil != arg["adjustHeadingLevel"] {- adjustHeadingLevel = arg["adjustHeadingLevel"].(bool)- }-- imgTag := false- if nil != arg["imgTag"] {- imgTag = arg["imgTag"].(bool)- }+var copyStdMarkdown = contractHandler(apicontract.CopyStdMarkdown, func(c *gin.Context, request apicontract.CopyStdMarkdownRequest) apicontract.Response[string] {+ id := request.ID+ assetsDestSpace2Underscore, fillCSSVar, adjustHeadingLevel, imgTag := request.AssetsDestSpace2Underscore, request.FillCSSVar, request.AdjustHeadingLevel, request.ImgTagisReadOnlyRole := model.IsReadOnlyRoleContext(c)var publishAccess model.PublishAccessvar accessChecker model.EmbedBlockAccessChecker@@ -88,46 +63,32 @@ func copyStdMarkdown(c *gin.Context) {markdownContent = model.FilterContentByPublishAccess(c, publishAccess, bt.BoxID, bt.Path, markdownContent, true)}}- ret.Data = markdownContent-}--func html2BlockDOM(c *gin.Context) {- ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)- limitHTML2BlockDOMRequestBody(c, maxHTML2BlockDOMRequestBytes)+ return apicontract.Success(markdownContent)+})- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- var dom string- if !util.ParseJsonArgs(arg, ret, util.BindJsonArg("dom", &dom, true, false)) {- return- }+var html2BlockDOM = contractHandler(apicontract.HTML2BlockDOM, func(c *gin.Context, request apicontract.HTMLClipboardRequest) apicontract.Response[apicontract.HTMLClipboardData] {+ dom := request.DOM// 可选 notebook 参数:指定目标加密笔记本时资源写入 box 内并加密boxID := ""- if notebook, ok := arg["notebook"].(string); ok && notebook != "" {+ if notebook := request.Notebook; notebook != "" {if model.IsEncryptedBox(notebook) {boxID = notebook}}if err := holdEncryptedBoxRequest(c, boxID); err != nil {- ret.Code = -1- ret.Msg = err.Error()- return- }- text, _ := arg["text"].(string)- mathML, _ := arg["mathML"].(string)- office, _ := arg["office"].(string)- officeMathHTML, _ := arg["officeMathHTML"].(string)- wps, _ := arg["wps"].(string)- skipLocalAssets, _ := arg["skipLocalAssets"].(bool)- skipBase64Assets, _ := arg["skipBase64Assets"].(bool)- skipInlineSVGAssets, _ := arg["skipInlineSVGAssets"].(bool)- preflight, _ := arg["preflight"].(bool)- preparedHTML, _ := arg["preparedHTML"].(bool)- preserveSourceFormat, _ := arg["preserveSourceFormat"].(bool)+ return apicontract.Failure[apicontract.HTMLClipboardData](-1, err.Error())+ }+ text := request.Text+ mathML := request.MathML+ office := request.Office+ officeMathHTML := request.OfficeMathHTML+ wps := request.WPS+ skipLocalAssets := request.SkipLocalAssets+ skipBase64Assets := request.SkipBase64Assets+ skipInlineSVGAssets := request.SkipInlineSVGAssets+ preflight := request.Preflight+ preparedHTML := request.PreparedHTML+ preserveSourceFormat := request.PreserveSourceFormatluteEngine := util.NewLute()luteEngine.SetHTMLTag2TextMark(true)luteEngine.SetHTML2MarkdownAttrs([]string{"alias", "memo", "bookmark", "custom-*"})@@ -135,11 +96,10 @@ func html2BlockDOM(c *gin.Context) {preserveSourceFormat, preparedHTML, convertClipboardMath, convertOfficeHTMLClipboardMath)if !useHTML {if preflight {- ret.Data = map[string]any{"converted": true, "dom": dom, "useHTML": false}+ return apicontract.Success(apicontract.HTMLClipboardPrepared(apicontract.HTMLClipboardPreflight{Converted: true, DOM: &dom, UseHTML: false}))} else {- ret.Data = dom+ return apicontract.Success(apicontract.HTMLClipboardText(dom))}- return}if preflight {skipLocalAssets = true@@ -153,11 +113,11 @@ func html2BlockDOM(c *gin.Context) {})if nil == tree {if preflight {- ret.Data = map[string]any{"converted": false, "dom": "Failed to convert", "normalizedHTML": normalizedHTML, "useHTML": true}+ failedDOM := "Failed to convert"+ return apicontract.Success(apicontract.HTMLClipboardPrepared(apicontract.HTMLClipboardPreflight{DOM: &failedDOM, NormalizedHTML: &normalizedHTML, UseHTML: true}))} else {- ret.Data = "Failed to convert"+ return apicontract.Success(apicontract.HTMLClipboardText("Failed to convert"))}- return}var unlinks []*ast.Node@@ -274,11 +234,11 @@ func html2BlockDOM(c *gin.Context) {md, err := lute.FormatNodeSync(tree.Root, luteEngine.ParseOptions, luteEngine.RenderOptions)if nil != err {if preflight {- ret.Data = map[string]any{"converted": false, "dom": "Failed to convert", "normalizedHTML": normalizedHTML, "useHTML": true}+ failedDOM := "Failed to convert"+ return apicontract.Success(apicontract.HTMLClipboardPrepared(apicontract.HTMLClipboardPreflight{DOM: &failedDOM, NormalizedHTML: &normalizedHTML, UseHTML: true}))} else {- ret.Data = "Failed to convert"+ return apicontract.Success(apicontract.HTMLClipboardText("Failed to convert"))}- return}tree = parse.Parse("", []byte(md), luteEngine.ParseOptions)@@ -291,11 +251,14 @@ func html2BlockDOM(c *gin.Context) {renderer := render.NewProtyleRenderer(tree, luteEngine.RenderOptions, luteEngine.ParseOptions)output := renderer.Render()if preflight {- ret.Data = map[string]any{"converted": true, "normalizedHTML": normalizedHTML, "useHTML": true}+ return apicontract.Success(apicontract.HTMLClipboardPrepared(apicontract.HTMLClipboardPreflight{Converted: true, NormalizedHTML: &normalizedHTML, UseHTML: true}))} else {- ret.Data = gulu.Str.FromBytes(output)+ return apicontract.Success(apicontract.HTMLClipboardText(gulu.Str.FromBytes(output)))}-}+}, func(c *gin.Context) *apicontract.Response[apicontract.HTMLClipboardData] {+ limitHTML2BlockDOMRequestBody(c, maxHTML2BlockDOMRequestBytes)+ return nil+})func removeWhitespaceTextMarkStyles(tree *parse.Tree) {var unlinks []*ast.Node@@ -468,50 +431,27 @@ func msWordCommentID(anchor *goquery.Selection, style string) string {return ""}-func spinBlockDOM(c *gin.Context) {+var spinBlockDOM = contractHandler(apicontract.SpinBlockDOM, func(c *gin.Context, request apicontract.DOMTextRequest) apicontract.Response[apicontract.DOMData] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- var dom string- if !util.ParseJsonArgs(arg, ret, util.BindJsonArg("dom", &dom, true, false)) {- return- }+ dom := request.DOMif len(dom) > maxSpinBlockDOMBytes {// 限制输入大小,避免解析超大 DOM 导致资源消耗ret.Code = http.StatusRequestEntityTooLargeret.Msg = "dom input exceeds the maximum permitted size"- return+ return contractFailure[apicontract.DOMData](ret)}luteEngine := model.NewLute()dom = luteEngine.SpinBlockDOM(dom)- ret.Data = map[string]any{- "dom": dom,- }-}+ return apicontract.Success(apicontract.DOMData{DOM: dom})+})// md2HTML 将 Markdown 转换为 HTML。-func md2HTML(c *gin.Context) {+var md2HTML = contractHandler(apicontract.Md2HTML, func(c *gin.Context, request apicontract.MarkdownHTMLRequest) apicontract.Response[apicontract.HTMLData] {ret := gulu.Ret.NewResult()- defer c.JSON(http.StatusOK, ret)- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- var markdown, mode string- if !util.ParseJsonArgs(arg, ret,- util.BindJsonArg("markdown", &markdown, true, false),- util.BindJsonArg("mode", &mode, false, false),- ) {- return- }+ markdown, mode := request.Markdown, request.Modevar html stringswitch mode {@@ -522,10 +462,8 @@ func md2HTML(c *gin.Context) {default:ret.Code = -1ret.Msg = "unknown [mode]"- return+ return contractFailure[apicontract.HTMLData](ret)}- ret.Data = map[string]any{- "html": html,- }-}+ return apicontract.Success(apicontract.HTMLData{HTML: html})+})diff --git a/kernel/api/lute_request_limit_test.go b/kernel/api/lute_request_limit_test.goindex e1c699cf39..70b51de8d9 100644--- a/kernel/api/lute_request_limit_test.go+++ b/kernel/api/lute_request_limit_test.go@@ -57,6 +57,7 @@ func TestHTML2BlockDOMPreflightOmitsConvertedDOM(t *testing.T) {context.Request.Header.Set("Content-Type", "application/json")html2BlockDOM(context)+ requireAPIContract(t, "POST", "/api/lute/html2BlockDOM", recorder)response := struct {Code int `json:"code"`diff --git a/kernel/api/lute_wps_presentation.go b/kernel/api/lute_wps_presentation.goindex 1ce92017c5..c23003c50d 100644--- a/kernel/api/lute_wps_presentation.go+++ b/kernel/api/lute_wps_presentation.go@@ -28,8 +28,8 @@ import ("strconv""strings"- "github.com/88250/gulu""github.com/gin-gonic/gin"+ "github.com/siyuan-note/siyuan/kernel/apicontract""github.com/siyuan-note/siyuan/kernel/util")@@ -52,11 +52,6 @@ const (presentationMLStrictNamespace = "http://purl.oclc.org/ooxml/presentationml/main")-type wpsPresentationConversionResult struct {- Converted bool `json:"converted"`- DOM string `json:"dom"`-}-type wpsPresentationBulletKind uint8const (@@ -143,31 +138,16 @@ type wpsPresentationListStackEntry struct {list *wpsPresentationHTMLList}-func wpsPresentation2BlockDOM(c *gin.Context) {- ret := gulu.Ret.NewResult()- result := &wpsPresentationConversionResult{}- ret.Data = result- defer c.JSON(http.StatusOK, ret)- c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, maxWPSPresentationRequestBytes)-- arg, ok := util.JsonArg(c, ret)- if !ok {- return- }-- var encoded, text, clipboardType string- if !util.ParseJsonArgs(arg, ret,- util.BindJsonArg("data", &encoded, true, true),- util.BindJsonArg("text", &text, false, false),- util.BindJsonArg("type", &clipboardType, true, true)) {- return+var wpsPresentation2BlockDOM = contractHandler(apicontract.WPSPresentation2BlockDOM, func(c *gin.Context, request apicontract.WPSPresentationRequest) apicontract.Response[apicontract.WPSPresentationData] {+ result := apicontract.WPSPresentationData{}+ if request.Type == "texts" || request.Type == "objects" {+ result.DOM, result.Converted = convertWPSPresentation(request.Data, request.Text, request.Type)}- if clipboardType != "texts" && clipboardType != "objects" {- return- }-- result.DOM, result.Converted = convertWPSPresentation(encoded, text, clipboardType)-}+ return apicontract.Success(result)+}, func(c *gin.Context) *apicontract.Response[apicontract.WPSPresentationData] {+ c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, maxWPSPresentationRequestBytes)+ return nil+})func convertWPSPresentation(encoded, text, clipboardType string) (dom string, converted bool) {htmlContent, converted := wpsPresentationHTML(encoded, text, clipboardType)diff --git a/kernel/apicontract/clipboard_html.go b/kernel/apicontract/clipboard_html.gonew file mode 100644index 0000000000..a294cbf351--- /dev/null+++ b/kernel/apicontract/clipboard_html.go@@ -0,0 +1,74 @@+package apicontract++import (+ "bytes"+ "encoding/json"+ "io"+)++type HTMLClipboardRequest struct {+ DOM string `json:"dom"`+ Notebook string `json:"notebook" api:"optional,nullable,ignoretype"`+ Text string `json:"text" api:"optional,nullable,ignoretype"`+ MathML string `json:"mathML" api:"optional,nullable,ignoretype"`+ Office string `json:"office" api:"optional,nullable,ignoretype"`+ OfficeMathHTML string `json:"officeMathHTML" api:"optional,nullable,ignoretype"`+ WPS string `json:"wps" api:"optional,nullable,ignoretype"`+ SkipLocalAssets bool `json:"skipLocalAssets" api:"optional,nullable"`+ SkipBase64Assets bool `json:"skipBase64Assets" api:"optional,nullable"`+ SkipInlineSVGAssets bool `json:"skipInlineSVGAssets" api:"optional,nullable"`+ Preflight bool `json:"preflight" api:"optional,nullable"`+ PreparedHTML bool `json:"preparedHTML" api:"optional,nullable"`+ PreserveSourceFormat bool `json:"preserveSourceFormat" api:"optional,nullable"`+}++type HTMLClipboardPreflight struct {+ Converted bool `json:"converted"`+ DOM *string `json:"dom,omitempty"`+ NormalizedHTML *string `json:"normalizedHTML,omitempty"`+ UseHTML bool `json:"useHTML"`+}++// HTMLClipboardData 区分直接转换文本与预处理结果。+type HTMLClipboardData struct {+ text string+ preflight *HTMLClipboardPreflight+}++func HTMLClipboardText(text string) HTMLClipboardData {+ return HTMLClipboardData{text: text}+}++func HTMLClipboardPrepared(value HTMLClipboardPreflight) HTMLClipboardData {+ return HTMLClipboardData{preflight: &value}+}++func (value HTMLClipboardData) MarshalJSON() ([]byte, error) {+ if value.preflight != nil {+ return json.Marshal(value.preflight)+ }+ return json.Marshal(value.text)+}++func init() {+ plain := HTML2BlockDOM+ HTML2BlockDOM.decodeRequest = func(reader io.Reader) (request HTMLClipboardRequest, err error) {+ fields, err := blockRequestFields(reader, "/api/lute/html2BlockDOM")+ if err != nil {+ return request, err+ }+ for _, key := range []string{"skipLocalAssets", "skipBase64Assets", "skipInlineSVGAssets", "preflight", "preparedHTML", "preserveSourceFormat"} {+ if raw, exists := fields[key]; exists {+ var value bool+ if json.Unmarshal(raw, &value) != nil {+ delete(fields, key)+ }+ }+ }+ data, err := json.Marshal(fields)+ if err != nil {+ return request, err+ }+ return plain.Decode(bytes.NewReader(data))+ }+}diff --git a/kernel/apicontract/clipboard_html_test.go b/kernel/apicontract/clipboard_html_test.gonew file mode 100644index 0000000000..8d831e7572--- /dev/null+++ b/kernel/apicontract/clipboard_html_test.go@@ -0,0 +1,18 @@+package apicontract++import (+ "strings"+ "testing"+)++func TestHTMLClipboardOptionalTypeCompatibility(t *testing.T) {+ request, err := HTML2BlockDOM.Decode(strings.NewReader(`{"dom":" html ","text":42,"notebook":{},"preflight":"true","skipLocalAssets":[],"skipBase64Assets":null,"preparedHTML":true}`))+ if err != nil || request.DOM != " html " || request.Text != "" || request.Notebook != "" || request.Preflight || request.SkipLocalAssets || request.SkipBase64Assets || !request.PreparedHTML {+ t.Fatalf("optional clipboard fields changed: %#v, %v", request, err)+ }+ for _, body := range []string{`{}`, `{"dom":null}`, `{"dom":42}`} {+ if _, err := HTML2BlockDOM.Decode(strings.NewReader(body)); err == nil {+ t.Fatalf("accepted invalid DOM: %s", body)+ }+ }+}diff --git a/kernel/apicontract/clipboard_wps.go b/kernel/apicontract/clipboard_wps.gonew file mode 100644index 0000000000..20b0efce67--- /dev/null+++ b/kernel/apicontract/clipboard_wps.go@@ -0,0 +1,18 @@+package apicontract++type WPSPresentationRequest struct {+ Data string `json:"data" api:"trim"`+ Text string `json:"text" api:"optional,nullable"`+ Type string `json:"type" api:"trim"`+}++type WPSPresentationData struct {+ Converted bool `json:"converted"`+ DOM string `json:"dom"`+}++func init() {+ WPSPresentation2BlockDOM.decodeFailure = func(err error) Response[WPSPresentationData] {+ return WPSPresentation2BlockDOM.FailureWithData(-1, err.Error(), WPSPresentationData{})+ }+}diff --git a/kernel/apicontract/contracts.go b/kernel/apicontract/contracts.goindex 6ea046d2aa..befa2cf14f 100644--- a/kernel/apicontract/contracts.go+++ b/kernel/apicontract/contracts.go@@ -32,6 +32,7 @@ type Definition struct {type Endpoint[Request, Data any] struct {definition DefinitiondecodeRequest func(io.Reader) (Request, error)+ decodeFailure func(error) Response[Data]}type ResponseOptions struct {@@ -357,15 +358,19 @@ var GetRecentUpdatedBlocks = define[EmptyRequest, []*SearchBlock]("getRecentUpdavar Zip = define[ZipRequest, Null]("zip", "/api/archive/zip", JSONBody, ResponseOptions{}, "POST")var Unzip = define[UnzipRequest, Null]("unzip", "/api/archive/unzip", JSONBody, ResponseOptions{}, "POST")-var AutoSpace = define[TrimmedIDRequest, Null]("autoSpace", "/api/format/autoSpace", JSONBody, ResponseOptions{}, "POST")var NetAssets2LocalAssets = define[TrimmedIDRequest, Null]("netAssets2LocalAssets", "/api/format/netAssets2LocalAssets", JSONBody, ResponseOptions{}, "POST")var NetImg2LocalAssets = define[NetImageAssetsRequest, Null]("netImg2LocalAssets", "/api/format/netImg2LocalAssets", JSONBody, ResponseOptions{}, "POST")-var PushMsg = define[NotificationRequest, NotificationData]("pushMsg", "/api/notification/pushMsg", JSONBody, ResponseOptions{}, "POST")var PushErrMsg = define[NotificationRequest, NotificationData]("pushErrMsg", "/api/notification/pushErrMsg", JSONBody, ResponseOptions{}, "POST")-var GetBookmark = define[EmptyRequest, []*Bookmark]("getBookmark", "/api/bookmark/getBookmark", NoBody, ResponseOptions{}, "POST")+var GetSnippet = define[GetSnippetRequest, SnippetsData]("getSnippet", "/api/snippet/getSnippet", JSONBody, ResponseOptions{}, "POST")+var SetSnippet = define[SetSnippetRequest, Null]("setSnippet", "/api/snippet/setSnippet", JSONBody, ResponseOptions{}, "POST")+var RemoveSnippet = define[TrimmedIDRequest, *Snippet]("removeSnippet", "/api/snippet/removeSnippet", JSONBody, ResponseOptions{}, "POST")+var FlushTransaction = define[EmptyRequest, Null]("flushTransaction", "/api/sqlite/flushTransaction", NoBody, ResponseOptions{}, "POST")+var CopyStdMarkdown = define[CopyStdMarkdownRequest, string]("copyStdMarkdown", "/api/lute/copyStdMarkdown", JSONBody, ResponseOptions{}, "POST")+var Md2HTML = define[MarkdownHTMLRequest, HTMLData]("md2HTML", "/api/lute/md2html", JSONBody, ResponseOptions{}, "POST")+var SpinBlockDOM = define[DOMTextRequest, DOMData]("spinBlockDOM", "/api/lute/spinBlockDOM", JSONBody, ResponseOptions{AdditionalCodes: []int{413}}, "POST")var ReloadTag = define[EmptyRequest, Null]("reloadTag", "/api/ui/reloadTag", NoBody, ResponseOptions{}, "POST")var ReloadFiletree = define[EmptyRequest, Null]("reloadFiletree", "/api/ui/reloadFiletree", NoBody, ResponseOptions{}, "POST")@@ -375,17 +380,6 @@ var ReloadUI = define[EmptyRequest, Null]("reloadUI", "/api/ui/reloadUI", NoBodyvar ReloadIcon = define[EmptyRequest, Null]("reloadIcon", "/api/ui/reloadIcon", NoBody, ResponseOptions{}, "POST")var ReloadTheme = define[EmptyRequest, Null]("reloadTheme", "/api/ui/reloadTheme", NoBody, ResponseOptions{}, "POST")-var FlushTransaction = define[EmptyRequest, Null]("flushTransaction", "/api/sqlite/flushTransaction", NoBody, ResponseOptions{}, "POST")--var GetSnippet = define[GetSnippetRequest, SnippetsData]("getSnippet", "/api/snippet/getSnippet", JSONBody, ResponseOptions{}, "POST")-var SetSnippet = define[SetSnippetRequest, Null]("setSnippet", "/api/snippet/setSnippet", JSONBody, ResponseOptions{}, "POST")-var RemoveSnippet = define[TrimmedIDRequest, *Snippet]("removeSnippet", "/api/snippet/removeSnippet", JSONBody, ResponseOptions{}, "POST")--var ResetBlockAttrs = define[EmptyRequest, Null]("resetBlockAttrs", "/api/attr/resetBlockAttrs", NoBody, ResponseOptions{}, "POST")-var SearchAttributeViewNonRelationKey = define[EmptyRequest, Null]("searchAttributeViewNonRelationKey", "/api/av/searchAttributeViewNonRelationKey", NoBody, ResponseOptions{}, "POST")-var SetLocalStorage = define[EmptyRequest, Null]("setLocalStorage", "/api/storage/setLocalStorage", NoBody, ResponseOptions{}, "POST")-var DeprecatedReloadUI = define[EmptyRequest, Null]("deprecatedReloadUI", "/api/system/reloadUI", NoBody, ResponseOptions{}, "POST")-var GetLocalStorage = define[EmptyRequest, map[string]JSONValue]("getLocalStorage", "/api/storage/getLocalStorage", NoBody, ResponseOptions{}, "POST")var GetLocalStorageVal = define[StorageKeyRequest, JSONValue]("getLocalStorageVal", "/api/storage/getLocalStorageVal", JSONBody, ResponseOptions{}, "POST")var GetLocalStorageVals = define[StorageKeysRequest, map[string]JSONValue]("getLocalStorageVals", "/api/storage/getLocalStorageVals", JSONBody, ResponseOptions{}, "POST")@@ -400,16 +394,28 @@ var GetViewState = define[StorageKeyRequest, map[string]JSONValue]("getViewStatevar PatchViewState = define[ViewStatePatchRequest, map[string]JSONValue]("patchViewState", "/api/storage/patchViewState", JSONBody, ResponseOptions{}, "POST")var RemoveViewState = define[StorageKeyRequest, Null]("removeViewState", "/api/storage/removeViewState", JSONBody, ResponseOptions{}, "POST")var GetRecentDocs = define[RecentDocsRequest, []*RecentDoc]("getRecentDocs", "/api/storage/getRecentDocs", LegacyOptionalBody, ResponseOptions{}, "POST")++var ResetBlockAttrs = define[EmptyRequest, Null]("resetBlockAttrs", "/api/attr/resetBlockAttrs", NoBody, ResponseOptions{}, "POST")+var SearchAttributeViewNonRelationKey = define[EmptyRequest, Null]("searchAttributeViewNonRelationKey", "/api/av/searchAttributeViewNonRelationKey", NoBody, ResponseOptions{}, "POST")+var SetLocalStorage = define[EmptyRequest, Null]("setLocalStorage", "/api/storage/setLocalStorage", NoBody, ResponseOptions{}, "POST")+var DeprecatedReloadUI = define[EmptyRequest, Null]("deprecatedReloadUI", "/api/system/reloadUI", NoBody, ResponseOptions{}, "POST")+var GetCriteria = define[EmptyRequest, []*Criterion]("getCriteria", "/api/storage/getCriteria", NoBody, ResponseOptions{}, "POST")var SetCriterion = define[SetCriterionRequest, Null]("setCriterion", "/api/storage/setCriterion", JSONBody, ResponseOptions{}, "POST")var RemoveCriterion = define[RemoveCriterionRequest, Null]("removeCriterion", "/api/storage/removeCriterion", JSONBody, ResponseOptions{}, "POST")+var UpdateRecentDocOpenTime = define[RecentDocUpdateRequest, Null]("updateRecentDocOpenTime", "/api/storage/updateRecentDocOpenTime", JSONBody, ResponseOptions{}, "POST")var UpdateRecentDocViewTime = define[RecentDocUpdateRequest, Null]("updateRecentDocViewTime", "/api/storage/updateRecentDocViewTime", JSONBody, ResponseOptions{}, "POST")var UpdateRecentDocCloseTime = define[RecentDocUpdateRequest, Null]("updateRecentDocCloseTime", "/api/storage/updateRecentDocCloseTime", JSONBody, ResponseOptions{}, "POST")var BatchUpdateRecentDocCloseTime = define[RecentDocsUpdateRequest, Null]("batchUpdateRecentDocCloseTime", "/api/storage/batchUpdateRecentDocCloseTime", JSONBody, ResponseOptions{}, "POST")++var GetDocOutline = define[OutlineRequest, []*SearchPath]("getDocOutline", "/api/outline/getDocOutline", JSONBody, ResponseOptions{AdditionalCodes: []int{1}}, "POST")+var GetDocHeadingNumbers = define[HeadingNumbersRequest, map[string]string]("getDocHeadingNumbers", "/api/outline/getDocHeadingNumbers", JSONBody, ResponseOptions{AdditionalCodes: []int{1}}, "POST")+var GetInlineStyles = define[EmptyRequest, *InlineStyles]("getInlineStyles", "/api/storage/getInlineStyles", NoBody, ResponseOptions{}, "POST")var SetInlineStyles = define[SetInlineStylesRequest, *InlineStyles]("setInlineStyles", "/api/storage/setInlineStyles", JSONBody, ResponseOptions{}, "POST")var SetWorkspaceAVPalette = define[WorkspaceAVPaletteRequest, *InlineStyles]("setWorkspaceAVPalette", "/api/storage/setWorkspaceAVPalette", JSONBody, ResponseOptions{}, "POST")-var GetDocOutline = define[OutlineRequest, []*SearchPath]("getDocOutline", "/api/outline/getDocOutline", JSONBody, ResponseOptions{AdditionalCodes: []int{1}}, "POST")-var GetDocHeadingNumbers = define[HeadingNumbersRequest, map[string]string]("getDocHeadingNumbers", "/api/outline/getDocHeadingNumbers", JSONBody, ResponseOptions{AdditionalCodes: []int{1}}, "POST")+var HTML2BlockDOM = define[HTMLClipboardRequest, HTMLClipboardData]("html2BlockDOM", "/api/lute/html2BlockDOM", JSONBody, ResponseOptions{}, "POST")++var WPSPresentation2BlockDOM = define[WPSPresentationRequest, WPSPresentationData]("wpsPresentation2BlockDOM", "/api/lute/wpsPresentation2BlockDOM", JSONBody, ResponseOptions{DataOnError: true}, "POST")diff --git a/kernel/apicontract/legacy_routes.json b/kernel/apicontract/legacy_routes.jsonindex 7add997ae4..e0baef1d1a 100644--- a/kernel/apicontract/legacy_routes.json+++ b/kernel/apicontract/legacy_routes.json@@ -277,11 +277,6 @@{"method":"POST","path":"/api/inbox/getShorthand","handler":"getShorthand"},{"method":"POST","path":"/api/inbox/getShorthands","handler":"getShorthands"},{"method":"POST","path":"/api/inbox/removeShorthands","handler":"removeShorthands"},- {"method":"POST","path":"/api/lute/copyStdMarkdown","handler":"copyStdMarkdown"},- {"method":"POST","path":"/api/lute/html2BlockDOM","handler":"html2BlockDOM"},- {"method":"POST","path":"/api/lute/md2html","handler":"md2HTML"},- {"method":"POST","path":"/api/lute/spinBlockDOM","handler":"spinBlockDOM"},- {"method":"POST","path":"/api/lute/wpsPresentation2BlockDOM","handler":"wpsPresentation2BlockDOM"},{"method":"POST","path":"/api/network/forwardProxy","handler":"forwardProxy"},{"method":"POST","path":"/api/petal/loadPetals","handler":"loadPetals"},{"method":"POST","path":"/api/petal/setPetalEnabled","handler":"setPetalEnabled"},diff --git a/kernel/apicontract/response.go b/kernel/apicontract/response.goindex 5d22cd6d72..1a7796db29 100644--- a/kernel/apicontract/response.go+++ b/kernel/apicontract/response.go@@ -2,6 +2,14 @@ package apicontractimport "encoding/json"+// DecodeFailure 保留端点在请求解析失败时声明的响应载荷。+func (e Endpoint[Request, Data]) DecodeFailure(err error) Response[Data] {+ if e.decodeFailure != nil {+ return e.decodeFailure(err)+ }+ return Failure[Data](-1, err.Error())+}+// FailureWithData 仅为显式声明失败载荷的端点保留业务结果。func (e Endpoint[Request, Data]) FailureWithData(code int, msg string, data Data) Response[Data] {if !e.definition.DataOnError {diff --git a/kernel/apicontract/schema.go b/kernel/apicontract/schema.goindex dfd2d59467..b169abdf98 100644--- a/kernel/apicontract/schema.go+++ b/kernel/apicontract/schema.go@@ -72,6 +72,13 @@ func nonnullable(schema *Schema) *Schema {}func (b *schemaBuilder) schema(t reflect.Type, input bool) (*Schema, error) {+ if t == reflect.TypeFor[HTMLClipboardData]() {+ preflight, err := b.schema(reflect.TypeFor[HTMLClipboardPreflight](), input)+ if err != nil {+ return nil, err+ }+ return &Schema{AnyOf: []*Schema{{Type: "string"}, preflight}}, nil+ }if t == reflect.TypeFor[BlockOperationData]() {options, err := b.schema(reflect.TypeFor[BlockDeleteData](), input)if err != nil {diff --git a/kernel/apicontract/schema.json b/kernel/apicontract/schema.jsonindex 05c1be4c11..52a207da57 100644--- a/kernel/apicontract/schema.json+++ b/kernel/apicontract/schema.json@@ -1448,6 +1448,58 @@],"additionalProperties": false},+ "CopyStdMarkdownRequestInput": {+ "type": "object",+ "properties": {+ "adjustHeadingLevel": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ]+ },+ "assetsDestSpace2Underscore": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ]+ },+ "fillCSSVar": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ]+ },+ "id": {+ "type": "string"+ },+ "imgTag": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "required": [+ "id"+ ],+ "additionalProperties": false+ },"CreateEncryptedNotebookRequestInput": {"type": "object","properties": {@@ -2359,6 +2411,18 @@},"additionalProperties": false},+ "DOMData": {+ "type": "object",+ "properties": {+ "dom": {+ "type": "string"+ }+ },+ "required": [+ "dom"+ ],+ "additionalProperties": false+ },"DOMTextRequestInput": {"type": "object","properties": {@@ -2905,6 +2969,172 @@},"additionalProperties": false},+ "HTMLClipboardPreflight": {+ "type": "object",+ "properties": {+ "converted": {+ "type": "boolean"+ },+ "dom": {+ "type": "string"+ },+ "normalizedHTML": {+ "type": "string"+ },+ "useHTML": {+ "type": "boolean"+ }+ },+ "required": [+ "converted",+ "useHTML"+ ],+ "additionalProperties": false+ },+ "HTMLClipboardRequestInput": {+ "type": "object",+ "properties": {+ "dom": {+ "type": "string"+ },+ "mathML": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ },+ "notebook": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ },+ "office": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ },+ "officeMathHTML": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ },+ "preflight": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ]+ },+ "preparedHTML": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ]+ },+ "preserveSourceFormat": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ]+ },+ "skipBase64Assets": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ]+ },+ "skipInlineSVGAssets": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ]+ },+ "skipLocalAssets": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ]+ },+ "text": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ },+ "wps": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "required": [+ "dom"+ ],+ "additionalProperties": false+ },+ "HTMLData": {+ "type": "object",+ "properties": {+ "html": {+ "type": "string"+ }+ },+ "required": [+ "html"+ ],+ "additionalProperties": false+ },"HeadingChildrenRequestInput": {"type": "object","properties": {@@ -3898,6 +4128,28 @@],"additionalProperties": false},+ "MarkdownHTMLRequestInput": {+ "type": "object",+ "properties": {+ "markdown": {+ "type": "string"+ },+ "mode": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "required": [+ "markdown"+ ],+ "additionalProperties": false+ },"MoveBlockRequestInput": {"type": "object","properties": {@@ -6533,48 +6785,90 @@],"additionalProperties": false},- "WordCountData": {+ "WPSPresentationData": {"type": "object","properties": {- "reqId": {- "$ref": "#/$defs/JSONValue"+ "converted": {+ "type": "boolean"},- "stat": {- "anyOf": [- {- "$ref": "#/$defs/BlockStat"- },- {- "type": "null"- }- ]+ "dom": {+ "type": "string"}},"required": [- "reqId",- "stat"+ "converted",+ "dom"],"additionalProperties": false},- "WorkspaceAVBuiltinColorUpdateInput": {+ "WPSPresentationRequestInput": {"type": "object","properties": {- "customized": {+ "data": {+ "type": "string"+ },+ "text": {"anyOf": [{- "type": "boolean"+ "type": "string"},{"type": "null"}]},- "dark": {- "anyOf": [- {- "$ref": "#/$defs/InlineStyleThemeInput"- },- {+ "type": {+ "type": "string"+ }+ },+ "required": [+ "data",+ "type"+ ],+ "additionalProperties": false+ },+ "WordCountData": {+ "type": "object",+ "properties": {+ "reqId": {+ "$ref": "#/$defs/JSONValue"+ },+ "stat": {+ "anyOf": [+ {+ "$ref": "#/$defs/BlockStat"+ },+ {+ "type": "null"+ }+ ]+ }+ },+ "required": [+ "reqId",+ "stat"+ ],+ "additionalProperties": false+ },+ "WorkspaceAVBuiltinColorUpdateInput": {+ "type": "object",+ "properties": {+ "customized": {+ "anyOf": [+ {+ "type": "boolean"+ },+ {+ "type": "null"+ }+ ]+ },+ "dark": {+ "anyOf": [+ {+ "$ref": "#/$defs/InlineStyleThemeInput"+ },+ {"type": "null"}]@@ -13503,6 +13797,392 @@]}},+ {+ "method": "POST",+ "path": "/api/lute/copyStdMarkdown",+ "handler": "copyStdMarkdown",+ "body": "json",+ "request": {+ "$ref": "#/$defs/CopyStdMarkdownRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "type": "string"+ },+ "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/lute/html2BlockDOM",+ "handler": "html2BlockDOM",+ "body": "json",+ "request": {+ "$ref": "#/$defs/HTMLClipboardRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "anyOf": [+ {+ "type": "string"+ },+ {+ "$ref": "#/$defs/HTMLClipboardPreflight"+ }+ ]+ },+ "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/lute/md2html",+ "handler": "md2HTML",+ "body": "json",+ "request": {+ "$ref": "#/$defs/MarkdownHTMLRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "$ref": "#/$defs/HTMLData"+ },+ "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/lute/spinBlockDOM",+ "handler": "spinBlockDOM",+ "body": "json",+ "request": {+ "$ref": "#/$defs/DOMTextRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "$ref": "#/$defs/DOMData"+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": false+ },+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ -1,+ 413+ ]+ },+ "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/lute/wpsPresentation2BlockDOM",+ "handler": "wpsPresentation2BlockDOM",+ "body": "json",+ "request": {+ "$ref": "#/$defs/WPSPresentationRequestInput"+ },+ "response": {+ "anyOf": [+ {+ "type": "object",+ "properties": {+ "code": {+ "type": "integer",+ "enum": [+ 0+ ]+ },+ "data": {+ "$ref": "#/$defs/WPSPresentationData"+ },+ "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"+ },+ {+ "$ref": "#/$defs/WPSPresentationData"+ }+ ]+ },+ "msg": {+ "type": "string"+ }+ },+ "required": [+ "code",+ "msg",+ "data"+ ],+ "additionalProperties": true+ }+ ]+ }+ },{"method": "POST","path": "/api/notebook/changeMasterPassword",diff --git a/kernel/apicontract/utility.go b/kernel/apicontract/utility.gonew file mode 100644index 0000000000..5087e9ad47--- /dev/null+++ b/kernel/apicontract/utility.go@@ -0,0 +1,19 @@+package apicontract++type CopyStdMarkdownRequest struct {+ ID string `json:"id"`+ AssetsDestSpace2Underscore bool `json:"assetsDestSpace2Underscore" api:"optional,nullable"`+ FillCSSVar bool `json:"fillCSSVar" api:"optional,nullable"`+ AdjustHeadingLevel bool `json:"adjustHeadingLevel" api:"optional,nullable"`+ ImgTag bool `json:"imgTag" api:"optional,nullable"`+}+type MarkdownHTMLRequest struct {+ Markdown string `json:"markdown"`+ Mode string `json:"mode" api:"optional,nullable"`+}+type HTMLData struct {+ HTML string `json:"html"`+}+type DOMData struct {+ DOM string `json:"dom"`+}