Skip to content

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

♻️ Migrate SQLite flush API contract https://github.com/siyuan-note/siyuan/issues/19378

Daniel2b723219b4f5
diff --git a/app/src/types/api/index.d.ts b/app/src/types/api/index.d.ts
index e0f585f126..118940dd9a 100644
--- a/app/src/types/api/index.d.ts
+++ b/app/src/types/api/index.d.ts
@@ -685,7 +685,6 @@ export type APILegacyPOSTPath =
"/api/snippet/getSnippet" |
"/api/snippet/removeSnippet" |
"/api/snippet/setSnippet" |
- "/api/sqlite/flushTransaction" |
"/api/storage/batchUpdateRecentDocCloseTime" |
"/api/storage/getCriteria" |
"/api/storage/getInlineStyles" |
@@ -1364,6 +1363,11 @@ export interface APIPOSTRoutes {
response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
body: "json";
};
+ "/api/sqlite/flushTransaction": {
+ request: EmptyRequestInput;
+ response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
+ body: "none";
+ };
"/api/system/addMicrosoftDefenderExclusion": {
request: EmptyRequestInput;
response: { "code": 0; "data": null; "msg": string; } | { "code": -1; "data": { "closeTimeout": number; } | null; "msg": string; };
diff --git a/kernel/api/sql.go b/kernel/api/sql.go
index 98f657baae..dc12837c7d 100644
--- a/kernel/api/sql.go
+++ b/kernel/api/sql.go
@@ -17,6 +17,7 @@
package api
import (
+ "github.com/siyuan-note/siyuan/kernel/apicontract"
"net/http"
"github.com/88250/gulu"
@@ -26,14 +27,14 @@ import (
"github.com/siyuan-note/siyuan/kernel/util"
)
-func flushTransaction(c *gin.Context) {
+var flushTransaction = contractHandler(apicontract.FlushTransaction, func(c *gin.Context, request apicontract.EmptyRequest) apicontract.Response[apicontract.Null] {
// Add internal kernel API `/api/sqlite/flushTransaction` https://github.com/siyuan-note/siyuan/issues/10005
- ret := gulu.Ret.NewResult()
- defer c.JSON(http.StatusOK, ret)
model.FlushTxQueue()
sql.FlushQueue()
-}
+
+ return apicontract.Success(apicontract.Null{})
+})
func SQL(c *gin.Context) {
ret := gulu.Ret.NewResult()
diff --git a/kernel/apicontract/contracts.go b/kernel/apicontract/contracts.go
index 4e9428061e..afa96b26be 100644
--- a/kernel/apicontract/contracts.go
+++ b/kernel/apicontract/contracts.go
@@ -374,3 +374,5 @@ var ReloadAttributeView = define[BlockIDRequest, Null]("reloadAttributeView", "/
var ReloadUI = define[EmptyRequest, Null]("reloadUI", "/api/ui/reloadUI", NoBody, ResponseOptions{}, "POST")
var 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")
diff --git a/kernel/apicontract/legacy_routes.json b/kernel/apicontract/legacy_routes.json
index 841829e47c..aa264ef2ea 100644
--- a/kernel/apicontract/legacy_routes.json
+++ b/kernel/apicontract/legacy_routes.json
@@ -383,7 +383,6 @@
{"method":"POST","path":"/api/snippet/getSnippet","handler":"getSnippet"},
{"method":"POST","path":"/api/snippet/removeSnippet","handler":"removeSnippet"},
{"method":"POST","path":"/api/snippet/setSnippet","handler":"setSnippet"},
- {"method":"POST","path":"/api/sqlite/flushTransaction","handler":"flushTransaction"},
{"method":"POST","path":"/api/storage/batchUpdateRecentDocCloseTime","handler":"batchUpdateRecentDocCloseTime"},
{"method":"POST","path":"/api/storage/getCriteria","handler":"getCriteria"},
{"method":"POST","path":"/api/storage/getInlineStyles","handler":"getInlineStyles"},
diff --git a/kernel/apicontract/schema.json b/kernel/apicontract/schema.json
index 5a11437aa5..0369046bd1 100644
--- a/kernel/apicontract/schema.json
+++ b/kernel/apicontract/schema.json
@@ -13444,6 +13444,81 @@
]
}
},
+ {
+ "method": "POST",
+ "path": "/api/sqlite/flushTransaction",
+ "handler": "flushTransaction",
+ "body": "none",
+ "request": {
+ "$ref": "#/$defs/EmptyRequestInput"
+ },
+ "response": {
+ "anyOf": [
+ {
+ "type": "object",
+ "properties": {
+ "code": {
+ "type": "integer",
+ "enum": [
+ 0
+ ]
+ },
+ "data": {
+ "type": "null"
+ },
+ "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/system/addMicrosoftDefenderExclusion",