Skip to content

Commit

Permalink
feat: 发布首个稳定版
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Aug 9, 2023
1 parent 4723632 commit 945df12
Show file tree
Hide file tree
Showing 32 changed files with 388 additions and 91 deletions.
1 change: 1 addition & 0 deletions src/adaptors/api/base/CommonblogConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,6 @@ export class CommonblogConfig extends BlogConfig {
this.middlewareUrl = middlewareUrl
this.usernameEnabled = false
this.allowPreviewUrlChange = true
this.showTokenTip = false
}
}
4 changes: 2 additions & 2 deletions src/adaptors/api/hexo/hexoConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class HexoConfig extends CommonGithubConfig {
this.showTokenTip = true
this.defaultPath = "source/_posts"
this.previewUrl = "/[user]/[repo]/blob/[branch]/[docpath]"
// this.previewPostUrl = "/post/[postid].html"
// this.mdFilenameRule = "[slug].md"
this.previewPostUrl = "/post/[postid].html"
this.mdFilenameRule = "[slug].md"
this.pageType = PageTypeEnum.Markdown
this.passwordType = PasswordType.PasswordType_Token
this.allowPreviewUrlChange = false
Expand Down
1 change: 1 addition & 0 deletions src/adaptors/api/notion/notionConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class NotionConfig extends CommonblogConfig {
super("https://www.notion.so/", "https://api.notion.com/v1", "", password, middlewareUrl)

this.tokenSettingUrl = "https://www.notion.so/my-integrations"
this.showTokenTip = true
this.previewUrl = "/[postid]"
this.pageType = PageTypeEnum.Markdown
this.passwordType = PasswordType.PasswordType_Token
Expand Down
1 change: 1 addition & 0 deletions src/adaptors/api/yuque/yuqueConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class YuqueConfig extends CommonblogConfig {
super("https://www.yuque.com/", "https://www.yuque.com/api/v2", username, password, middlewareUrl)

this.tokenSettingUrl = "https://www.yuque.com/settings/tokens"
this.showTokenTip = true
this.previewUrl = "/[notebook]/[postid]"
this.pageType = PageTypeEnum.Markdown
this.usernameEnabled = true
Expand Down
90 changes: 85 additions & 5 deletions src/adaptors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,14 @@
* questions.
*/

import { BlogAdaptor, WebAdaptor } from "zhi-blog-api"
import { BlogAdaptor, BlogConfig, WebAdaptor } from "zhi-blog-api"
import { getSubPlatformTypeByKey, SubPlatformType } from "~/src/platforms/dynamicConfig.ts"
import { useCnblogsApi } from "~/src/adaptors/api/cnblogs/useCnblogsApi.ts"
import { createAppLogger } from "~/src/utils/appLogger.ts"
import { useWordpressApi } from "~/src/adaptors/api/wordpress/useWordpressApi.ts"
import { useTypechoApi } from "~/src/adaptors/api/typecho/useTypechoApi.ts"
import { useYuqueApi } from "~/src/adaptors/api/yuque/useYuqueApi.ts"
import { useZhihuWeb } from "~/src/adaptors/web/zhihu/useZhihuWeb.ts"
import { useCsdnWeb } from "~/src/adaptors/web/csdn/useCsdnWeb.ts"
import { useJianshuWeb } from "~/src/adaptors/web/jianshu/useJianshuWeb.ts"
import { useJuejinWeb } from "~/src/adaptors/web/juejin/useJuejinWeb.ts"
import { useWechatWeb } from "~/src/adaptors/web/wechat/useWechatWeb.ts"
import { useSiyuanApi } from "~/src/composables/useSiyuanApi.ts"
import { useMetaweblogApi } from "~/src/adaptors/api/metaweblog/useMetaweblogApi.ts"
import { useNotionApi } from "~/src/adaptors/api/notion/useNotionApi.ts"
Expand All @@ -50,6 +46,90 @@ import { useHexoApi } from "~/src/adaptors/api/hexo/useHexoApi.ts"
class Adaptors {
private static logger = createAppLogger("adaptors")

/**
* 根据平台key查找配置
*
* @param key
*/
public static async getCfg(key: string): Promise<BlogConfig> {
let conf = null
const type: SubPlatformType = getSubPlatformTypeByKey(key)

switch (type) {
case SubPlatformType.Common_Yuque: {
const { cfg } = await useYuqueApi(key)
conf = cfg
break
}
case SubPlatformType.Common_Notion: {
const { cfg } = await useNotionApi(key)
conf = cfg
break
}
case SubPlatformType.Github_Hexo: {
const { cfg } = await useHexoApi(key)
conf = cfg
break
}
case SubPlatformType.Metaweblog_Metaweblog: {
const { cfg } = await useMetaweblogApi(key)
conf = cfg
break
}
case SubPlatformType.Metaweblog_Cnblogs: {
const { cfg } = await useCnblogsApi(key)
conf = cfg
break
}
case SubPlatformType.Metaweblog_Typecho: {
const { cfg } = await useTypechoApi(key)
conf = cfg
break
}
case SubPlatformType.Wordpress_Wordpress: {
const { cfg } = await useWordpressApi(key)
conf = cfg
break
}
case SubPlatformType.Custom_Zhihu: {
const { cfg } = await useZhihuWeb(key)
conf = cfg
break
}
// case SubPlatformType.Custom_CSDN: {
// const { cfg } = await useCsdnWeb(key)
// conf = cfg
// break
// }
// case SubPlatformType.Custom_Jianshu: {
// const { cfg } = await useJianshuWeb(key)
// conf = cfg
// break
// }
// case SubPlatformType.Custom_Juejin: {
// const { cfg } = await useJuejinWeb(key)
// conf = cfg
// break
// }
// case SubPlatformType.Custom_Wechat: {
// const { cfg } = await useWechatWeb(key)
// conf = cfg
// break
// }
case SubPlatformType.System_Siyuan: {
const { cfg } = useSiyuanApi()
conf = cfg
break
}
default: {
conf = {}
break
}
}
this.logger.debug(`get conf from key ${key}=>`, conf)
return conf
}

/**
* 根据平台key查找适配器
*
Expand Down
23 changes: 21 additions & 2 deletions src/adaptors/web/base/CommonWebConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,28 @@
* questions.
*/

import { WebConfig } from "zhi-blog-api"
import { PageTypeEnum, WebConfig } from "zhi-blog-api"
import { MetaweblogPlaceholder } from "~/src/adaptors/api/base/metaweblog/MetaweblogPlaceholder.ts"

/**
* 网页授权配置
*/
export class CommonWebConfig extends WebConfig {}
export class CommonWebConfig extends WebConfig {
constructor(home: string, apiUrl: string, username: string, password: string, middlewareUrl?: string) {
super(password, middlewareUrl)

this.home = home
this.apiUrl = apiUrl
this.username = username

this.password = password
this.apiStatus = false
this.blogid = ""
this.blogName = ""
this.posidKey = ""
this.previewUrl = ""
this.pageType = PageTypeEnum.Markdown
this.placeholder = new MetaweblogPlaceholder()
this.middlewareUrl = middlewareUrl
}
}
6 changes: 5 additions & 1 deletion src/adaptors/web/csdn/csdnConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ import { CommonWebConfig } from "~/src/adaptors/web/base/CommonWebConfig.ts"
/**
* CSDN配置
*/
export class CsdnConfig extends CommonWebConfig {}
export class CsdnConfig extends CommonWebConfig {
constructor(username: string, password: string, middlewareUrl?: string) {
super("", "", username, password, middlewareUrl)
}
}
6 changes: 5 additions & 1 deletion src/adaptors/web/csdn/useCsdnWeb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ const useCsdnWeb = async (key?: string, newCfg?: CsdnConfig) => {
// 如果配置为空,则使用默认的环境变量值,并记录日志
if (ObjectUtil.isEmptyObject(cfg)) {
// 从环境变量获取Csdn的cookie
const middlewareUrl = Utils.emptyOrDefault(
process.env.VITE_MIDDLEWARE_URL,
"https://api.terwer.space/api/middleware"
)
const csdnCookie = Utils.emptyOrDefault(process.env.VITE_CSDN_AUTH_TOKEN, "")
cfg = new CsdnConfig(csdnCookie)
cfg = new CsdnConfig("", csdnCookie, middlewareUrl)
logger.debug("Configuration is empty, using default environment variables.")
} else {
logger.info("Using configuration from settings...")
Expand Down
6 changes: 5 additions & 1 deletion src/adaptors/web/jianshu/JianshuConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ import { CommonWebConfig } from "~/src/adaptors/web/base/CommonWebConfig.ts"
/**
* 简书配置
*/
export class JianshuConfig extends CommonWebConfig {}
export class JianshuConfig extends CommonWebConfig {
constructor(username: string, password: string, middlewareUrl?: string) {
super("", "", username, password, middlewareUrl)
}
}
6 changes: 5 additions & 1 deletion src/adaptors/web/jianshu/useJianshuWeb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ const useJianshuWeb = async (key?: string, newCfg?: JianshuConfig) => {
cfg = JsonUtil.safeParse<JianshuConfig>(setting[key], {} as JianshuConfig)
// 如果配置为空,则使用默认的环境变量值,并记录日志
if (ObjectUtil.isEmptyObject(cfg)) {
const middlewareUrl = Utils.emptyOrDefault(
process.env.VITE_MIDDLEWARE_URL,
"https://api.terwer.space/api/middleware"
)
// 从环境变量获取Jianshu的cookie
const jianshuCookie = Utils.emptyOrDefault(process.env.VITE_JIANSHU_AUTH_TOKEN, "")
cfg = new JianshuConfig(jianshuCookie)
cfg = new JianshuConfig("", jianshuCookie, middlewareUrl)
logger.debug("Configuration is empty, using default environment variables.")
} else {
logger.info("Using configuration from settings...")
Expand Down
6 changes: 5 additions & 1 deletion src/adaptors/web/juejin/JuejinConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ import { CommonWebConfig } from "~/src/adaptors/web/base/CommonWebConfig.ts"
/**
* 掘金配置
*/
export class JuejinConfig extends CommonWebConfig {}
export class JuejinConfig extends CommonWebConfig {
constructor(username: string, password: string, middlewareUrl?: string) {
super("", "", username, password, middlewareUrl)
}
}
6 changes: 5 additions & 1 deletion src/adaptors/web/juejin/useJuejinWeb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ const useJuejinWeb = async (key?: string, newCfg?: JuejinConfig) => {
cfg = JsonUtil.safeParse<JuejinConfig>(setting[key], {} as JuejinConfig)
// 如果配置为空,则使用默认的环境变量值,并记录日志
if (ObjectUtil.isEmptyObject(cfg)) {
const middlewareUrl = Utils.emptyOrDefault(
process.env.VITE_MIDDLEWARE_URL,
"https://api.terwer.space/api/middleware"
)
// 从环境变量获取Juejin的cookie
const juejinCookie = Utils.emptyOrDefault(process.env.VITE_JUEJIN_AUTH_TOKEN, "")
cfg = new JuejinConfig(juejinCookie)
cfg = new JuejinConfig("", juejinCookie, middlewareUrl)
logger.debug("Configuration is empty, using default environment variables.")
} else {
logger.info("Using configuration from settings...")
Expand Down
6 changes: 5 additions & 1 deletion src/adaptors/web/wechat/WechatConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@ import { CommonWebConfig } from "~/src/adaptors/web/base/CommonWebConfig.ts"
/**
* 微信公众号配置
*/
export class WechatConfig extends CommonWebConfig {}
export class WechatConfig extends CommonWebConfig {
constructor(username: string, password: string, middlewareUrl?: string) {
super("", "", username, password, middlewareUrl)
}
}
6 changes: 5 additions & 1 deletion src/adaptors/web/wechat/useWechatWeb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ const useWechatWeb = async (key?: string, newCfg?: WechatConfig) => {
cfg = JsonUtil.safeParse<WechatConfig>(setting[key], {} as WechatConfig)
// 如果配置为空,则使用默认的环境变量值,并记录日志
if (ObjectUtil.isEmptyObject(cfg)) {
const middlewareUrl = Utils.emptyOrDefault(
process.env.VITE_MIDDLEWARE_URL,
"https://api.terwer.space/api/middleware"
)
// 从环境变量获取Wechat的cookie
const wechatCookie = Utils.emptyOrDefault(process.env.VITE_WECHAT_AUTH_TOKEN, "")
cfg = new WechatConfig(wechatCookie)
cfg = new WechatConfig("", wechatCookie, middlewareUrl)
logger.debug("Configuration is empty, using default environment variables.")
} else {
logger.info("Using configuration from settings...")
Expand Down
9 changes: 7 additions & 2 deletions src/adaptors/web/zhihu/useZhihuWeb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,13 @@ const useZhihuWeb = async (key?: string, newCfg?: ZhihuConfig) => {
cfg = JsonUtil.safeParse<ZhihuConfig>(setting[key], {} as ZhihuConfig)
// 如果配置为空,则使用默认的环境变量值,并记录日志
if (ObjectUtil.isEmptyObject(cfg)) {
const middlewareUrl = Utils.emptyOrDefault(
process.env.VITE_MIDDLEWARE_URL,
"https://api.terwer.space/api/middleware"
)
// 从环境变量获取Zhihu的cookie
const zhihuCookie = Utils.emptyOrDefault(process.env.VITE_ZHIHU_AUTH_TOKEN, "")
cfg = new ZhihuConfig(zhihuCookie)
cfg = new ZhihuConfig("", zhihuCookie, middlewareUrl)
logger.debug("Configuration is empty, using default environment variables.")
} else {
logger.info("Using configuration from settings...")
Expand All @@ -66,7 +70,7 @@ const useZhihuWeb = async (key?: string, newCfg?: ZhihuConfig) => {
process.env.VITE_MIDDLEWARE_URL,
"https://api.terwer.space/api/middleware"
)
if(StrUtil.isEmptyString(cfg.middlewareUrl)){
if (StrUtil.isEmptyString(cfg.middlewareUrl)) {
cfg.middlewareUrl = middlewareUrl
}
// 初始化posidKey
Expand All @@ -78,6 +82,7 @@ const useZhihuWeb = async (key?: string, newCfg?: ZhihuConfig) => {

const webApi = new ZhihuWebAdaptor(appInstance, cfg)
return {
cfg,
webApi,
}
}
Expand Down
12 changes: 11 additions & 1 deletion src/adaptors/web/zhihu/zhihuConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,18 @@
*/

import { CommonWebConfig } from "~/src/adaptors/web/base/CommonWebConfig.ts"
import { PageTypeEnum, PasswordType } from "zhi-blog-api"

/**
* 知乎配置
*/
export class ZhihuConfig extends CommonWebConfig {}
export class ZhihuConfig extends CommonWebConfig {
constructor(username: string, password: string, middlewareUrl?: string) {
super("https://zhuanlan.zhihu.com", "https://zhuanlan.zhihu.com/api", username, password, middlewareUrl)
this.previewUrl = "/p/[postid]"
this.pageType = PageTypeEnum.Html
this.passwordType = PasswordType.PasswordType_Cookie
this.knowledgeSpaceTitle = "专栏"
this.enableKnowledgeSpace = true
}
}
30 changes: 30 additions & 0 deletions src/adaptors/web/zhihu/zhihuPlaceholder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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 { CommonWebPlaceholder } from "~/src/adaptors/web/base/CommonWebPlaceholder.ts"

class ZhihuPlaceholder extends CommonWebPlaceholder {}

export { ZhihuPlaceholder }
2 changes: 1 addition & 1 deletion src/adaptors/web/zhihu/zhihuWebAdaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ZhihuWebAdaptor extends BaseWebApi {
uid: res.uid,
title: res.name,
avatar: res.avatar_url,
supportTypes: ["markdown"],
supportTypes: ["html"],
type: "zhihu",
displayName: "知乎",
home: "https://www.zhihu.com/settings/account",
Expand Down
Loading

0 comments on commit 945df12

Please sign in to comment.