Skip to content

Commit

Permalink
feat: 新版挂件-集成 API 测试
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Jun 24, 2023
1 parent 647154c commit cac089e
Show file tree
Hide file tree
Showing 27 changed files with 2,455 additions and 38 deletions.
6 changes: 6 additions & 0 deletions components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export {}
declare module '@vue/runtime-core' {
export interface GlobalComponents {
ChangeLocal: typeof import('./src/components/set/preference/ChangeLocal.vue')['default']
CnblogsTest: typeof import('./src/components/test/CnblogsTest.vue')['default']
ElButton: typeof import('element-plus/es')['ElButton']
ElDialog: typeof import('element-plus/es')['ElDialog']
ElForm: typeof import('element-plus/es')['ElForm']
Expand All @@ -20,11 +21,16 @@ declare module '@vue/runtime-core' {
ElTabPane: typeof import('element-plus/es')['ElTabPane']
ElTabs: typeof import('element-plus/es')['ElTabs']
GeneralSetting: typeof import('./src/components/set/GeneralSetting.vue')['default']
HexoTest: typeof import('./src/components/test/HexoTest.vue')['default']
HugoTest: typeof import('./src/components/test/HugoTest.vue')['default']
PublishIndex: typeof import('./src/components/publish/PublishIndex.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
SetIndex: typeof import('./src/components/set/SetIndex.vue')['default']
SiyuanTest: typeof import('./src/components/test/SiyuanTest.vue')['default']
TypechoTest: typeof import('./src/components/test/TypechoTest.vue')['default']
VitepressTest: typeof import('./src/components/test/VitepressTest.vue')['default']
WordpressTest: typeof import('./src/components/test/WordpressTest.vue')['default']
YuqueTest: typeof import('./src/components/test/YuqueTest.vue')['default']
}
}
1 change: 1 addition & 0 deletions docs/设计思路.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
常规发布:可详细配置各种发布参数
发布预览
上传图片到图床
文章管理
设置
偏好设置
图床设置
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,19 @@
"@vueuse/core": "^10.2.0",
"cross-fetch": "^3.1.6",
"element-plus": "^2.3.7",
"js-base64": "^3.7.5",
"pinia": "^2.1.4",
"simple-xmlrpc": "^1.4.2",
"vue": "^3.3.4",
"vue-i18n": "^9.2.2",
"vue-router": "^4.2.2",
"xmlbuilder2": "^3.1.1",
"zhi-blog-api": "^1.12.0",
"zhi-blog-api": "^1.13.0",
"zhi-common": "^1.11.2",
"zhi-device": "^2.3.0",
"zhi-fetch-middleware": "^0.1.16",
"zhi-lib-base": "0.4.1",
"zhi-siyuan-api": "^1.24.0"
"zhi-siyuan-api": "^1.25.0",
"zhi-xmlrpc-middleware": "^0.2.16"
}
}
51 changes: 40 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions src/adaptors/github/GithubApiAdaptor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2023, Terwer . All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Terwer designates this
* particular file as subject to the "Classpath" exception as provided
* by Terwer in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com
* or visit www.terwer.space if you need additional information or have any
* questions.
*/

import { BlogApi } from "zhi-blog-api"

/**
* Github API 适配器
*
* @author terwer
* @version 1.0.0
* @since 1.0.0
*/
class GithubApiAdaptor extends BlogApi {

}

export { GithubApiAdaptor }
15 changes: 15 additions & 0 deletions src/adaptors/siyuan/docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# SiYuanApiAdaptor

## Usage

```ts
import { SiYuanApiAdaptor, SiyuanConfig } from "zhi-siyuan-api"

const siyuanCfg = new SiyuanConfig("http://127.0.0.1:6806", "")
// 显示指定修复标题
siyuanCfg.fixTitle = true
const siyuanApiAdaptor = new SiYuanApiAdaptor(siyuanCfg)
const siyuanApi = Utils.blogApi(appInstance, siyuanApiAdaptor)
const siyuanUsersBlogs = await siyuanApi.getUsersBlogs()
console.log("siyuanUsersBlogs=>", siyuanUsersBlogs)
```
72 changes: 72 additions & 0 deletions src/adaptors/wordpress/adaptor/wordpressApiAdaptor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2023, Terwer . All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Terwer designates this
* particular file as subject to the "Classpath" exception as provided
* by Terwer in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com
* or visit www.terwer.space if you need additional information or have any
* questions.
*/

import { BlogApi, UserBlog } from "zhi-blog-api"
import { WordpressConfig } from "~/src/adaptors/wordpress/config/wordpressConfig.ts"
import { CommonXmlrpcClient } from "zhi-xmlrpc-middleware"
import { AppInstance } from "~/src/appInstance.ts"
import { createAppLogger } from "~/src/utils/appLogger.ts"
import { WordpressConstants } from "~/src/adaptors/wordpress/wordpressConstants.ts"

/**
* WordPress API 适配器
*
* @author terwer
* @version 1.0.0
* @since 1.0.0
*/
class WordpressApiAdaptor extends BlogApi {
private readonly logger
private readonly cfg: WordpressConfig
private readonly commonXmlrpcClient

/**
* 初始化 WordPress API 适配器
*
* @param appInstance 应用实例
* @param cfg 配置项
*/
constructor(appInstance: AppInstance, cfg: WordpressConfig) {
super()

this.cfg = cfg
this.logger = createAppLogger("wordpress-api-adaptor")
this.commonXmlrpcClient = new CommonXmlrpcClient(appInstance, cfg.apiUrl)
}

public override async getUsersBlogs(): Promise<Array<UserBlog>> {
let result: UserBlog[] = []
result = await this.wordpressCall(WordpressConstants.METHOD_GET_USERS_BLOGS, [])
this.logger.debug("getUsersBlogs=>", result)
return result
}

private async wordpressCall(method: string, params: string[]) {
const parameters = ["wordpress", this.cfg.username, this.cfg.password]
params.forEach((param) => parameters.push(param))
return await this.commonXmlrpcClient.methodCall(method, parameters, this.cfg.middlewareUrl)
}
}
export { WordpressApiAdaptor }
72 changes: 72 additions & 0 deletions src/adaptors/wordpress/config/wordpressConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2023, Terwer . All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Terwer designates this
* particular file as subject to the "Classpath" exception as provided
* by Terwer in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Terwer, Shenzhen, Guangdong, China, youweics@163.com
* or visit www.terwer.space if you need additional information or have any
* questions.
*/

import { BlogConfig } from "zhi-blog-api"

/**
* WordPress 配置
*
* @author terwer
* @since 1.0.0
*/
class WordpressConfig extends BlogConfig {
/**
* API 地址
*/
public override apiUrl = ""

/**
* 用户名
*/
public override username = ""

/**
* 密码
*/
public override password = ""

/**
* 代理地址
*/
public override middlewareUrl = ""

/**
* WordPress 配置项
*
* @param apiUrl API 地址
* @param username 用户名
* @param password 密码
* @param middlewareUrl 代理地址
*/
constructor(apiUrl: string, username: string, password: string, middlewareUrl?: string) {
super()
this.apiUrl = apiUrl
this.username = username
this.password = password
this.middlewareUrl = middlewareUrl
}
}

export { WordpressConfig }
Loading

0 comments on commit cac089e

Please sign in to comment.