From 1f199a6dcf70501bf92501dbb749f9faf9c844b4 Mon Sep 17 00:00:00 2001 From: frostime Date: Tue, 15 Aug 2023 23:29:23 +0800 Subject: [PATCH] udpate api.ts --- src/api.ts | 108 ++++++++++++++++++++++++++++----------------- src/types/api.d.ts | 6 +++ 2 files changed, 74 insertions(+), 40 deletions(-) diff --git a/src/api.ts b/src/api.ts index 9d3a2fd..3939d14 100644 --- a/src/api.ts +++ b/src/api.ts @@ -6,6 +6,7 @@ * API 文档见 [API_zh_CN.md](https://github.com/siyuan-note/siyuan/blob/master/API_zh_CN.md) */ +import { time } from "console"; import { fetchSyncPost, IWebSocketData } from "siyuan"; @@ -54,14 +55,8 @@ export async function removeNotebook(notebook: NotebookId) { return request(url, { notebook: notebook }); } -export type ResGetNotebookConf = { - box: string; - conf: NotebookConf; - name: string; -} - -export async function getNotebookConf(notebook: NotebookId): Promise { +export async function getNotebookConf(notebook: NotebookId): Promise { let data = { notebook: notebook }; let url = '/api/notebook/getNotebookConf'; return request(url, data); @@ -75,7 +70,7 @@ export async function setNotebookConf(notebook: NotebookId, conf: NotebookConf): } -// **************************************** Document **************************************** +// **************************************** File Tree **************************************** export async function createDocWithMd(notebook: NotebookId, path: string, markdown: string): Promise { let data = { notebook: notebook, @@ -151,40 +146,56 @@ export async function upload(assetsDirPath: string, files: any[]): Promise { - let data1 = { +export async function insertBlock( + dataType: DataType, data: string, + nextID?: BlockId, previousID?: BlockId, parentID?: BlockId +): Promise { + let payload = { dataType: dataType, data: data, - previousID: previousID + nextID: nextID, + previousID: previousID, + parentID: parentID } let url = '/api/block/insertBlock'; - return request(url, data1); + return request(url, payload); } -export async function appendBlock(dataType: DataType, data: string, parentID: BlockId | DocumentId): Promise { - let data1 = { +export async function prependBlock(dataType: DataType, data: string, parentID: BlockId | DocumentId): Promise { + let payload = { + dataType: dataType, + data: data, + parentID: parentID + } + let url = '/api/block/prependBlock'; + return request(url, payload); +} + + +export async function appendBlock(dataType: DataType, data: string, parentID: BlockId | DocumentId): Promise { + let payload = { dataType: dataType, data: data, parentID: parentID } let url = '/api/block/appendBlock'; - return request(url, data1); + return request(url, payload); } -export async function updateBlock(dataType: DataType, data: string, id: BlockId): Promise { - let data1 = { +export async function updateBlock(dataType: DataType, data: string, id: BlockId): Promise { + let payload = { dataType: dataType, data: data, id: id } let url = '/api/block/updateBlock'; - return request(url, data1); + return request(url, payload); } -export async function deleteBlock(id: BlockId): Promise { +export async function deleteBlock(id: BlockId): Promise { let data = { id: id } @@ -193,7 +204,7 @@ export async function deleteBlock(id: BlockId): Promise { } -export async function moveBlock(id: BlockId, previousID: PreviousID | null = null, parentID: ParentID | null = null): Promise { +export async function moveBlock(id: BlockId, previousID?: PreviousID, parentID?: ParentID): Promise { let data = { id: id, previousID: previousID, @@ -328,27 +339,8 @@ export async function readDir(path: string): Promise { return request(url, data); } -// /api/export/exportResources -/* -{ - "paths": [ - "/conf/appearance/boot", - "/conf/appearance/langs", - "/conf/appearance/emojis/conf.json", - "/conf/appearance/icons/index.html", - ], - "name": "zip-file-name" -} -*/ -export async function exportResources(paths: string[], name: string): Promise { - let data = { - paths: paths, - name: name - } - let url = '/api/export/exportResources'; - return request(url, data); -} +// **************************************** Export **************************************** export async function exportMdContent(id: DocumentId): Promise { let data = { @@ -358,6 +350,17 @@ export async function exportMdContent(id: DocumentId): Promise { + let data = { + paths: paths, + name: name + } + let url = '/api/export/exportResources'; + return request(url, data); +} + +// **************************************** Convert **************************************** + export type PandocArgs = string; export async function pandoc(args: PandocArgs[]) { let data = { @@ -367,6 +370,31 @@ export async function pandoc(args: PandocArgs[]) { return request(url, data); } +// **************************************** Notification **************************************** + +// /api/notification/pushMsg +// { +// "msg": "test", +// "timeout": 7000 +// } +export async function pushMsg(msg: string, timeout: number = 7000) { + let payload = { + msg: msg, + timeout: timeout + }; + let url = "/api/notification/pushMsg"; + return request(url, payload); +} + +export async function pushErrMsg(msg: string, timeout: number = 7000) { + let payload = { + msg: msg, + timeout: timeout + }; + let url = "/api/notification/pushErrMsg"; + return request(url, payload); +} + // **************************************** Network **************************************** export async function forwardProxy( url: string, method: string, payload: any, diff --git a/src/types/api.d.ts b/src/types/api.d.ts index 1163bb0..3c08859 100644 --- a/src/types/api.d.ts +++ b/src/types/api.d.ts @@ -1,3 +1,9 @@ +interface IResGetNotebookConf { + box: string; + conf: NotebookConf; + name: string; +} + interface IReslsNotebooks { notebooks: Notebook[]; }