diff --git a/lib/api.ts b/lib/api.ts index ad1ed3a..d75c7aa 100644 --- a/lib/api.ts +++ b/lib/api.ts @@ -5,6 +5,7 @@ import {UserBlog} from "~/lib/common/userBlog"; import {JvueApiAdaptor} from "~/lib/platform/metaweblog/jvue/jvueApiAdaptor"; import {ConfApiAdaptor} from "~/lib/platform/metaweblog/conf/confApiAdaptor"; import {CnblogsApiAdaptor} from "~/lib/platform/metaweblog/cnblogs/cnblogsApiAdaptor"; +import {WordpressApiAdaptor} from "~/lib/platform/metaweblog/wordpress/wordpressApiAdaptor"; /** * 通用API定义 @@ -50,6 +51,9 @@ export class API implements IApi { case API_TYPE_CONSTANTS.API_TYPE_CNBLOGS: this.apiAdaptor = new CnblogsApiAdaptor(env) break; + case API_TYPE_CONSTANTS.API_TYPE_WORDPRESS: + this.apiAdaptor = new WordpressApiAdaptor(env) + break; default: throw new Error("未找到接口适配器,请检查参数") } diff --git a/lib/constants.ts b/lib/constants.ts index 3b327cb..1db4c8e 100644 --- a/lib/constants.ts +++ b/lib/constants.ts @@ -14,6 +14,10 @@ const API_TYPE_CONF = "conf" * Cnblogs */ const API_TYPE_CNBLOGS = "cnblogs" +/** + * Wordpress + */ +const API_TYPE_WORDPRESS = "wordpress" /** * API类型常量定义 @@ -22,5 +26,6 @@ export const API_TYPE_CONSTANTS = { API_TYPE_SIYUAN, API_TYPE_JVUE, API_TYPE_CONF, - API_TYPE_CNBLOGS + API_TYPE_CNBLOGS, + API_TYPE_WORDPRESS } \ No newline at end of file diff --git a/lib/platform/metaweblog/wordpress/wordpressApiAdaptor.ts b/lib/platform/metaweblog/wordpress/wordpressApiAdaptor.ts new file mode 100644 index 0000000..92ab2fa --- /dev/null +++ b/lib/platform/metaweblog/wordpress/wordpressApiAdaptor.ts @@ -0,0 +1,20 @@ +import {API_TYPE_CONSTANTS} from "~/lib/constants"; +import {MetaWeblogApi} from "~/lib/platform/metaweblog/metaweblogApi"; +import {MetaWeblogApiAdaptor} from "~/lib/platform/metaweblog/metaweblogApiAdaptor"; +import {IApi} from "~/lib/api"; + +export class WordpressApiAdaptor extends MetaWeblogApiAdaptor implements IApi { + private readonly env:any + + constructor(env:any) { + super(); + + this.env = env + this.apiUrl = process.env.WORDPRESS_API_URL || "" + this.username = process.env.WORDPRESS_USERNAME || "" + this.password = process.env.WORDPRESS_PASSWORD || "" + this.appkey = API_TYPE_CONSTANTS.API_TYPE_WORDPRESS + + this.metaWeblog = new MetaWeblogApi(this.appkey, this.apiUrl, this.username, this.password); + } +} \ No newline at end of file diff --git a/nuxt.config.ts b/nuxt.config.ts index 2726150..73ab32f 100644 --- a/nuxt.config.ts +++ b/nuxt.config.ts @@ -22,6 +22,9 @@ export default defineNuxtConfig({ JVUE_PASSWORD: process.env.JVUE_PASSWORD, CONF_API_URL: process.env.CONF_API_URL, CONF_USERNAME: process.env.CONF_USERNAME, - CONF_PASSWORD: process.env.CONF_PASSWORD + CONF_PASSWORD: process.env.CONF_PASSWORD, + WORDPRESS_API_URL: process.env.WORDPRESS_API_URL, + WORDPRESS_USERNAME: process.env.WORDPRESS_USERNAME, + WORDPRESS_PASSWORD: process.env.WORDPRESS_PASSWORD, } }) diff --git a/server/api/endpoint/getPost.ts b/server/api/endpoint/getPost.ts index 10c36a6..2c73040 100644 --- a/server/api/endpoint/getPost.ts +++ b/server/api/endpoint/getPost.ts @@ -7,7 +7,7 @@ export default defineEventHandler(async (event) => { throw new Error("参数类型错误") } - const type = query.t || API_TYPE_CONSTANTS.API_TYPE_JVUE + const type = query.t || API_TYPE_CONSTANTS.API_TYPE_WORDPRESS const postid = "1" const env = useRuntimeConfig() diff --git a/server/api/endpoint/getRecentPosts.ts b/server/api/endpoint/getRecentPosts.ts index 0657f2b..bbc686f 100644 --- a/server/api/endpoint/getRecentPosts.ts +++ b/server/api/endpoint/getRecentPosts.ts @@ -9,7 +9,7 @@ export default defineEventHandler(async (event) => { } logUtil.logInfo("query.t", query.t) - const type = query.t || API_TYPE_CONSTANTS.API_TYPE_JVUE + const type = query.t || API_TYPE_CONSTANTS.API_TYPE_WORDPRESS const num = 10 const page = 1 const keyword = ""