-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
456 additions
and
16 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
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,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 { CommonXmlrpcClient } from "zhi-xmlrpc-middleware" | ||
import { AppInstance } from "~/src/appInstance.ts" | ||
import { createAppLogger } from "~/src/utils/appLogger.ts" | ||
import { TypechoConfig } from "~/src/adaptors/api/typecho/config/typechoConfig.ts" | ||
import { TypechoConstants } from "~/src/adaptors/api/typecho/typechoConstants.ts" | ||
|
||
/** | ||
* WordPress API 适配器 | ||
* | ||
* @author terwer | ||
* @version 0.9.0 | ||
* @since 0.9.0 | ||
*/ | ||
class TypechoApiAdaptor extends BlogApi { | ||
private readonly logger | ||
private readonly cfg: TypechoConfig | ||
private readonly commonXmlrpcClient | ||
|
||
/** | ||
* 初始化 WordPress API 适配器 | ||
* | ||
* @param appInstance 应用实例 | ||
* @param cfg 配置项 | ||
*/ | ||
constructor(appInstance: AppInstance, cfg: TypechoConfig) { | ||
super() | ||
|
||
this.cfg = cfg | ||
this.logger = createAppLogger("typecho-api-adaptor") | ||
this.commonXmlrpcClient = new CommonXmlrpcClient(appInstance, cfg.apiUrl) | ||
} | ||
|
||
public override async getUsersBlogs(): Promise<Array<UserBlog>> { | ||
let result: UserBlog[] = [] | ||
result = await this.typechoCall(TypechoConstants.METHOD_GET_USERS_BLOGS, []) | ||
this.logger.debug("getUsersBlogs=>", result) | ||
return result | ||
} | ||
|
||
private async typechoCall(method: string, params: string[]) { | ||
const parameters = ["typecho", this.cfg.username, this.cfg.password] | ||
params.forEach((param) => parameters.push(param)) | ||
return await this.commonXmlrpcClient.methodCall(method, parameters, this.cfg.middlewareUrl) | ||
} | ||
} | ||
export { TypechoApiAdaptor } |
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,76 @@ | ||
/* | ||
* 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 { MetaweblogConfig } from "~/src/adaptors/api/base/metaweblog/config/MetaweblogConfig.ts" | ||
import { PageTypeEnum } from "zhi-blog-api" | ||
import TypechoUtils from "~/src/adaptors/api/Typecho/TypechoUtils.ts" | ||
|
||
/** | ||
* Typecho 配置 | ||
* | ||
* @author terwer | ||
* @since 1.0.0 | ||
*/ | ||
class TypechoConfig extends MetaweblogConfig { | ||
/** | ||
* API 地址 | ||
*/ | ||
public override apiUrl = "" | ||
|
||
/** | ||
* 用户名 | ||
*/ | ||
public override username = "" | ||
|
||
/** | ||
* 密码 | ||
*/ | ||
public override password = "" | ||
|
||
/** | ||
* 代理地址 | ||
*/ | ||
public override middlewareUrl = "" | ||
|
||
/** | ||
* Typecho 配置项 | ||
* | ||
* @param homeAddr Typecho 主页 | ||
* @param username 用户名 | ||
* @param password 密码 | ||
* @param middlewareUrl 代理地址 | ||
*/ | ||
constructor(homeAddr: string, username: string, password: string, middlewareUrl?: string) { | ||
super(homeAddr, "", username, password, middlewareUrl) | ||
|
||
const { home, apiUrl } = TypechoUtils.parseHomeAndUrl(homeAddr) | ||
this.home = home | ||
this.apiUrl = apiUrl | ||
this.previewUrl = "/?p=[postid]" | ||
this.pageType = PageTypeEnum.Markdown | ||
} | ||
} | ||
|
||
export { TypechoConfig } |
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,33 @@ | ||
/* | ||
* 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 { MetaweblogPlaceholder } from "~/src/adaptors/api/base/metaweblog/config/MetaweblogPlaceholder.ts" | ||
|
||
/** | ||
* WordPress 操作提示 | ||
*/ | ||
class TypechoPlaceholder extends MetaweblogPlaceholder {} | ||
|
||
export { TypechoPlaceholder } |
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 @@ | ||
# TypechoApiAdaptor |
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,37 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
/** | ||
* 预定义 Typecho 变量 | ||
* | ||
* @author terwer | ||
* @version 0.9.0 | ||
* @since 0.9.0 | ||
*/ | ||
class TypechoConstants { | ||
public static METHOD_GET_USERS_BLOGS = "metaWeblog.getUsersBlogs" | ||
} | ||
|
||
export { TypechoConstants } |
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,56 @@ | ||
/* | ||
* 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 { createAppLogger } from "~/src/utils/appLogger.ts" | ||
|
||
/** | ||
* 用于处理Typecho相关操作的实用工具类 | ||
*/ | ||
class TypechoUtils { | ||
private static logger = createAppLogger("typecho-utils") | ||
|
||
/** | ||
* 解析给定的主页地址并生成相应的apiUrl地址 | ||
* | ||
* @param home - 主页地址 | ||
*/ | ||
public static parseHomeAndUrl(home: string): { home: string; apiUrl: string } { | ||
this.logger.debug(`Parsing Home address: ${home}`) | ||
// 解析主页地址 | ||
let apiUrl = "" | ||
if (home.endsWith("/index.php/action/xmlrpc")) { | ||
apiUrl = home | ||
home = home.replace("/index.php/action/xmlrpc", "") | ||
} else { | ||
home = home.replace(/\/$/, "") | ||
apiUrl = `${home}/index.php/action/xmlrpc` | ||
} | ||
|
||
this.logger.debug(`Parse result: home=${home}, apiUrl=${apiUrl}`) | ||
return { home, apiUrl } | ||
} | ||
} | ||
|
||
export default TypechoUtils |
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 @@ | ||
# WordpressApiAdaptor |
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
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
Oops, something went wrong.