From b7f633598f903ee080c3dc9f80fe77ce811ca45f Mon Sep 17 00:00:00 2001 From: frostime Date: Tue, 15 Aug 2023 10:52:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8D=95=E7=8B=AC=E6=8A=BD=E5=87=BA=20?= =?UTF-8?q?api.d.ts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api.ts | 66 +++++++++++----------------------------------- src/types/api.d.ts | 45 +++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 50 deletions(-) create mode 100644 src/types/api.d.ts diff --git a/src/api.ts b/src/api.ts index 0df6c12..1aacac4 100644 --- a/src/api.ts +++ b/src/api.ts @@ -18,11 +18,8 @@ async function request(url: string, data: any) { // **************************************** Noteboook **************************************** -export type ReslsNotebooks = { - notebooks: Notebook[]; -} -export async function lsNotebooks(): Promise { +export async function lsNotebooks(): Promise { let url = '/api/notebook/lsNotebooks'; return request(url, ''); } @@ -141,12 +138,8 @@ export async function getHPathByID(id: BlockId): Promise { } // **************************************** Asset Files **************************************** -export type ResUpload = { - errFiles: string[]; - succMap: { [key: string]: string }; -} -export async function upload(assetsDirPath: string, files: any[]): Promise { +export async function upload(assetsDirPath: string, files: any[]): Promise { let form = new FormData(); form.append('assetsDirPath', assetsDirPath); for (let file of files) { @@ -157,12 +150,8 @@ export async function upload(assetsDirPath: string, files: any[]): Promise { +export async function insertBlock(dataType: DataType, data: string, previousID: BlockId): Promise { let data1 = { dataType: dataType, data: data, @@ -173,7 +162,7 @@ export async function insertBlock(dataType: DataType, data: string, previousID: } -export async function appendBlock(dataType: DataType, data: string, parentID: BlockId | DocumentId): Promise { +export async function appendBlock(dataType: DataType, data: string, parentID: BlockId | DocumentId): Promise { let data1 = { dataType: dataType, data: data, @@ -184,7 +173,7 @@ export async function appendBlock(dataType: DataType, data: string, parentID: Bl } -export async function updateBlock(dataType: DataType, data: string, id: BlockId): Promise { +export async function updateBlock(dataType: DataType, data: string, id: BlockId): Promise { let data1 = { dataType: dataType, data: data, @@ -195,7 +184,7 @@ export async function updateBlock(dataType: DataType, data: string, id: BlockId) } -export async function deleteBlock(id: BlockId): Promise { +export async function deleteBlock(id: BlockId): Promise { let data = { id: id } @@ -204,7 +193,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 | null = null, parentID: ParentID | null = null): Promise { let data = { id: id, previousID: previousID, @@ -215,12 +204,7 @@ export async function moveBlock(id: BlockId, previousID: PreviousID | null = nul } -export type ResGetBlockKramdown = { - id: BlockId; - kramdown: string; -} - -export async function getBlockKramdown(id: BlockId): Promise { +export async function getBlockKramdown(id: BlockId): Promise { let data = { id: id } @@ -228,12 +212,8 @@ export async function getBlockKramdown(id: BlockId): Promise { + +export async function getChildBlocks(id: BlockId): Promise { let data = { id: id } @@ -288,11 +268,7 @@ export async function getBlockByID(blockId: string): Promise { // **************************************** Template **************************************** -export type ResGetTemplates = { - content: string; - path: string; -} -export async function render(id: DocumentId, path: string): Promise { +export async function render(id: DocumentId, path: string): Promise { let data = { id: id, path: path @@ -343,11 +319,8 @@ export async function removeFile(path: string) { } -export type ResReadDir = { - isDir: boolean; - name: string; -} -export async function readDir(path: string): Promise { + +export async function readDir(path: string): Promise { let data = { path: path } @@ -356,11 +329,7 @@ export async function readDir(path: string): Promise { } -export type ResExportMdContent = { - hPath: string; - content: string; -} -export async function exportMdContent(id: DocumentId): Promise { +export async function exportMdContent(id: DocumentId): Promise { let data = { id: id } @@ -379,11 +348,8 @@ export async function pandoc(args: PandocArgs[]) { // **************************************** System **************************************** -export type ResBootProgress = { - progress: number; - details: string; -} -export async function bootProgress(): Promise { + +export async function bootProgress(): Promise { return request('/api/system/bootProgress', {}); } diff --git a/src/types/api.d.ts b/src/types/api.d.ts new file mode 100644 index 0000000..d363403 --- /dev/null +++ b/src/types/api.d.ts @@ -0,0 +1,45 @@ +interface IReslsNotebooks { + notebooks: Notebook[]; +} + +interface IResUpload { + errFiles: string[]; + succMap: { [key: string]: string }; +} + +interface IResdoOperations { + doOperations: doOperation[]; + undoOperations: doOperation[] | null; +} + +interface IResGetBlockKramdown { + id: BlockId; + kramdown: string; +} + +interface IResGetChildBlock { + id: BlockId; + type: BlockType; + subtype?: BlockSubType; +} + +interface IResGetTemplates { + content: string; + path: string; +} + +interface IResReadDir { + isDir: boolean; + name: string; +} + +interface IResExportMdContent { + hPath: string; + content: string; +} + +interface IResBootProgress { + progress: number; + details: string; +} +