feat: 单独抽出 api.d.ts
This commit is contained in:
parent
811519bfd8
commit
b7f633598f
2 changed files with 61 additions and 50 deletions
66
src/api.ts
66
src/api.ts
|
@ -18,11 +18,8 @@ async function request(url: string, data: any) {
|
||||||
|
|
||||||
// **************************************** Noteboook ****************************************
|
// **************************************** Noteboook ****************************************
|
||||||
|
|
||||||
export type ReslsNotebooks = {
|
|
||||||
notebooks: Notebook[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function lsNotebooks(): Promise<ReslsNotebooks> {
|
export async function lsNotebooks(): Promise<IReslsNotebooks> {
|
||||||
let url = '/api/notebook/lsNotebooks';
|
let url = '/api/notebook/lsNotebooks';
|
||||||
return request(url, '');
|
return request(url, '');
|
||||||
}
|
}
|
||||||
|
@ -141,12 +138,8 @@ export async function getHPathByID(id: BlockId): Promise<string> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// **************************************** Asset Files ****************************************
|
// **************************************** Asset Files ****************************************
|
||||||
export type ResUpload = {
|
|
||||||
errFiles: string[];
|
|
||||||
succMap: { [key: string]: string };
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function upload(assetsDirPath: string, files: any[]): Promise<ResUpload> {
|
export async function upload(assetsDirPath: string, files: any[]): Promise<IResUpload> {
|
||||||
let form = new FormData();
|
let form = new FormData();
|
||||||
form.append('assetsDirPath', assetsDirPath);
|
form.append('assetsDirPath', assetsDirPath);
|
||||||
for (let file of files) {
|
for (let file of files) {
|
||||||
|
@ -157,12 +150,8 @@ export async function upload(assetsDirPath: string, files: any[]): Promise<ResUp
|
||||||
}
|
}
|
||||||
|
|
||||||
// **************************************** Block ****************************************
|
// **************************************** Block ****************************************
|
||||||
export type ResdoOperations = {
|
|
||||||
doOperations: doOperation[];
|
|
||||||
undoOperations: doOperation[] | null;
|
|
||||||
}
|
|
||||||
type DataType = "markdown" | "dom";
|
type DataType = "markdown" | "dom";
|
||||||
export async function insertBlock(dataType: DataType, data: string, previousID: BlockId): Promise<ResdoOperations> {
|
export async function insertBlock(dataType: DataType, data: string, previousID: BlockId): Promise<IResdoOperations> {
|
||||||
let data1 = {
|
let data1 = {
|
||||||
dataType: dataType,
|
dataType: dataType,
|
||||||
data: data,
|
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<ResdoOperations> {
|
export async function appendBlock(dataType: DataType, data: string, parentID: BlockId | DocumentId): Promise<IResdoOperations> {
|
||||||
let data1 = {
|
let data1 = {
|
||||||
dataType: dataType,
|
dataType: dataType,
|
||||||
data: data,
|
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<ResdoOperations> {
|
export async function updateBlock(dataType: DataType, data: string, id: BlockId): Promise<IResdoOperations> {
|
||||||
let data1 = {
|
let data1 = {
|
||||||
dataType: dataType,
|
dataType: dataType,
|
||||||
data: data,
|
data: data,
|
||||||
|
@ -195,7 +184,7 @@ export async function updateBlock(dataType: DataType, data: string, id: BlockId)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function deleteBlock(id: BlockId): Promise<ResdoOperations> {
|
export async function deleteBlock(id: BlockId): Promise<IResdoOperations> {
|
||||||
let data = {
|
let data = {
|
||||||
id: id
|
id: id
|
||||||
}
|
}
|
||||||
|
@ -204,7 +193,7 @@ export async function deleteBlock(id: BlockId): Promise<ResdoOperations> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function moveBlock(id: BlockId, previousID: PreviousID | null = null, parentID: ParentID | null = null): Promise<ResdoOperations> {
|
export async function moveBlock(id: BlockId, previousID: PreviousID | null = null, parentID: ParentID | null = null): Promise<IResdoOperations> {
|
||||||
let data = {
|
let data = {
|
||||||
id: id,
|
id: id,
|
||||||
previousID: previousID,
|
previousID: previousID,
|
||||||
|
@ -215,12 +204,7 @@ export async function moveBlock(id: BlockId, previousID: PreviousID | null = nul
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export type ResGetBlockKramdown = {
|
export async function getBlockKramdown(id: BlockId): Promise<IResGetBlockKramdown> {
|
||||||
id: BlockId;
|
|
||||||
kramdown: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getBlockKramdown(id: BlockId): Promise<ResGetBlockKramdown> {
|
|
||||||
let data = {
|
let data = {
|
||||||
id: id
|
id: id
|
||||||
}
|
}
|
||||||
|
@ -228,12 +212,8 @@ export async function getBlockKramdown(id: BlockId): Promise<ResGetBlockKramdown
|
||||||
return request(url, data);
|
return request(url, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ChildBlock = {
|
|
||||||
id: BlockId;
|
export async function getChildBlocks(id: BlockId): Promise<IResGetChildBlock[]> {
|
||||||
type: BlockType;
|
|
||||||
subtype?: BlockSubType;
|
|
||||||
}
|
|
||||||
export async function getChildBlocks(id: BlockId): Promise<ChildBlock[]> {
|
|
||||||
let data = {
|
let data = {
|
||||||
id: id
|
id: id
|
||||||
}
|
}
|
||||||
|
@ -288,11 +268,7 @@ export async function getBlockByID(blockId: string): Promise<Block> {
|
||||||
|
|
||||||
// **************************************** Template ****************************************
|
// **************************************** Template ****************************************
|
||||||
|
|
||||||
export type ResGetTemplates = {
|
export async function render(id: DocumentId, path: string): Promise<IResGetTemplates> {
|
||||||
content: string;
|
|
||||||
path: string;
|
|
||||||
}
|
|
||||||
export async function render(id: DocumentId, path: string): Promise<ResGetTemplates> {
|
|
||||||
let data = {
|
let data = {
|
||||||
id: id,
|
id: id,
|
||||||
path: path
|
path: path
|
||||||
|
@ -343,11 +319,8 @@ export async function removeFile(path: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export type ResReadDir = {
|
|
||||||
isDir: boolean;
|
export async function readDir(path: string): Promise<IResReadDir> {
|
||||||
name: string;
|
|
||||||
}
|
|
||||||
export async function readDir(path: string): Promise<ResReadDir> {
|
|
||||||
let data = {
|
let data = {
|
||||||
path: path
|
path: path
|
||||||
}
|
}
|
||||||
|
@ -356,11 +329,7 @@ export async function readDir(path: string): Promise<ResReadDir> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export type ResExportMdContent = {
|
export async function exportMdContent(id: DocumentId): Promise<IResExportMdContent> {
|
||||||
hPath: string;
|
|
||||||
content: string;
|
|
||||||
}
|
|
||||||
export async function exportMdContent(id: DocumentId): Promise<ResExportMdContent> {
|
|
||||||
let data = {
|
let data = {
|
||||||
id: id
|
id: id
|
||||||
}
|
}
|
||||||
|
@ -379,11 +348,8 @@ export async function pandoc(args: PandocArgs[]) {
|
||||||
|
|
||||||
|
|
||||||
// **************************************** System ****************************************
|
// **************************************** System ****************************************
|
||||||
export type ResBootProgress = {
|
|
||||||
progress: number;
|
export async function bootProgress(): Promise<IResBootProgress> {
|
||||||
details: string;
|
|
||||||
}
|
|
||||||
export async function bootProgress(): Promise<ResBootProgress> {
|
|
||||||
return request('/api/system/bootProgress', {});
|
return request('/api/system/bootProgress', {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
45
src/types/api.d.ts
vendored
Normal file
45
src/types/api.d.ts
vendored
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue