-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from terwer/dev
feat:#6 接口适配器
- Loading branch information
Showing
4 changed files
with
66 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,27 @@ | ||
/** | ||
* 获取挂件所在的块ID | ||
* @returns {Promise<string>} | ||
*/ | ||
import {getBlockByID, getBlockAttrs, setBlockAttrs, exportMdContent} from "./siyuan/siYuanApi"; | ||
import {SiYuanApiAdaptor} from "./siyuan/siYuanApiAdaptor"; | ||
import {API_TYPE_CONSTANTS} from "./constants"; | ||
|
||
/** | ||
* 获取页面 | ||
* @param pageId 页面ID | ||
*/ | ||
export async function getPage(pageId: string) { | ||
return await getBlockByID(pageId) | ||
export interface IApi { | ||
getRecentPosts(numOfPosts: number): Promise<Array<any>> | ||
} | ||
|
||
/** | ||
* 获取页面属性 | ||
* @param pageId 页面ID | ||
*/ | ||
export async function getPageAttrs(pageId: string) { | ||
return await getBlockAttrs(pageId) | ||
} | ||
export class API implements IApi { | ||
type: string | ||
private apiAdaptor: IApi | ||
|
||
constructor(type: string) { | ||
this.type = type; | ||
switch (this.type) { | ||
case API_TYPE_CONSTANTS.API_TYPE_SIYUAN: | ||
this.apiAdaptor = new SiYuanApiAdaptor() | ||
break; | ||
default: | ||
throw new Error("未找到接口适配器,请检查参数") | ||
} | ||
} | ||
|
||
/** | ||
* 保存页面属性 | ||
* @param pageId 页面ID | ||
* @param attrs 属性对象 | ||
*/ | ||
export async function setPageAttrs(pageId: string, attrs: any) { | ||
return await setBlockAttrs(pageId, attrs) | ||
async getRecentPosts(numOfPosts: number): Promise<Array<any>> { | ||
return this.apiAdaptor.getRecentPosts(numOfPosts); | ||
} | ||
} | ||
|
||
/** | ||
* 获取页面的Markdown | ||
* @param pageId | ||
*/ | ||
export async function getPageMd(pageId: string) { | ||
return await exportMdContent(pageId); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const API_TYPE_SIYUAN = "siyuan" | ||
|
||
/** | ||
* API类型常量定义 | ||
*/ | ||
export const API_TYPE_CONSTANTS = { | ||
API_TYPE_SIYUAN | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import {IApi} from "../api"; | ||
import {getBlockByID} from "./siYuanApi"; | ||
|
||
export class SiYuanApiAdaptor implements IApi { | ||
async getRecentPosts(numOfPosts: number): Promise<Array<any>> { | ||
let result = [] | ||
|
||
// 本地测试 | ||
let pageId = "20220724172444-16a2oc1" | ||
|
||
let page = await getBlockByID(pageId) | ||
if (page) { | ||
result.push(page) | ||
} | ||
return Promise.resolve(result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cde364f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
node-siyuan – ./
node-siyuan-terwergreen.vercel.app
node-siyuan.vercel.app
node-siyuan-git-main-terwergreen.vercel.app
www.terwer.space
terwer.space