udpate api.ts

This commit is contained in:
frostime 2023-08-15 23:29:23 +08:00
parent 548f80a46f
commit 1f199a6dcf
2 changed files with 74 additions and 40 deletions

View file

@ -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<ResGetNotebookConf> {
export async function getNotebookConf(notebook: NotebookId): Promise<IResGetNotebookConf> {
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<DocumentId> {
let data = {
notebook: notebook,
@ -151,40 +146,56 @@ export async function upload(assetsDirPath: string, files: any[]): Promise<IResU
// **************************************** Block ****************************************
type DataType = "markdown" | "dom";
export async function insertBlock(dataType: DataType, data: string, previousID: BlockId): Promise<IResdoOperations> {
let data1 = {
export async function insertBlock(
dataType: DataType, data: string,
nextID?: BlockId, previousID?: BlockId, parentID?: BlockId
): Promise<IResdoOperations[]> {
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<IResdoOperations> {
let data1 = {
export async function prependBlock(dataType: DataType, data: string, parentID: BlockId | DocumentId): Promise<IResdoOperations[]> {
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<IResdoOperations[]> {
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<IResdoOperations> {
let data1 = {
export async function updateBlock(dataType: DataType, data: string, id: BlockId): Promise<IResdoOperations[]> {
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<IResdoOperations> {
export async function deleteBlock(id: BlockId): Promise<IResdoOperations[]> {
let data = {
id: id
}
@ -193,7 +204,7 @@ export async function deleteBlock(id: BlockId): Promise<IResdoOperations> {
}
export async function moveBlock(id: BlockId, previousID: PreviousID | null = null, parentID: ParentID | null = null): Promise<IResdoOperations> {
export async function moveBlock(id: BlockId, previousID?: PreviousID, parentID?: ParentID): Promise<IResdoOperations[]> {
let data = {
id: id,
previousID: previousID,
@ -328,27 +339,8 @@ export async function readDir(path: string): Promise<IResReadDir> {
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<IResExportResources> {
let data = {
paths: paths,
name: name
}
let url = '/api/export/exportResources';
return request(url, data);
}
// **************************************** Export ****************************************
export async function exportMdContent(id: DocumentId): Promise<IResExportMdContent> {
let data = {
@ -358,6 +350,17 @@ export async function exportMdContent(id: DocumentId): Promise<IResExportMdConte
return request(url, data);
}
export async function exportResources(paths: string[], name: string): Promise<IResExportResources> {
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,

6
src/types/api.d.ts vendored
View file

@ -1,3 +1,9 @@
interface IResGetNotebookConf {
box: string;
conf: NotebookConf;
name: string;
}
interface IReslsNotebooks {
notebooks: Notebook[];
}