-
Notifications
You must be signed in to change notification settings - Fork 9
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
37 changed files
with
354 additions
and
95 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
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
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
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,41 @@ | ||
/* | ||
* 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 { HaloConfig } from "~/src/adaptors/api/halo/HaloConfig.ts" | ||
import { BaseBlogApi } from "~/src/adaptors/api/base/baseBlogApi.ts" | ||
import { createAppLogger } from "~/src/utils/appLogger.ts" | ||
|
||
/** | ||
* Halo API 适配器 | ||
* @see [Halo API](https://github.com/halo-sigs/vscode-extension-halo/blob/main/src/service/index.ts) | ||
*/ | ||
class HaloApiAdaptor extends BaseBlogApi { | ||
constructor(appInstance: any, cfg: HaloConfig) { | ||
super(appInstance, cfg) | ||
this.logger = createAppLogger("halo-api-adaptor") | ||
} | ||
} | ||
|
||
export { HaloApiAdaptor } |
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,58 @@ | ||
/* | ||
* 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 { CommonBlogConfig } from "~/src/adaptors/api/base/commonBlogConfig.ts" | ||
import { CategoryTypeEnum, PageTypeEnum } from "zhi-blog-api" | ||
|
||
/** | ||
* Halo 配置 | ||
*/ | ||
class HaloConfig extends CommonBlogConfig { | ||
/** | ||
* Halo 配置项 | ||
* | ||
* @param username 用户名 | ||
* @param password 密码 | ||
* @param middlewareUrl 代理地址 | ||
*/ | ||
constructor(username: string, password: string, middlewareUrl?: string) { | ||
super("", "", username, password, middlewareUrl) | ||
|
||
this.home = "[your-halo-home]" | ||
this.apiUrl = "[your-halo-api-url]" | ||
this.previewUrl = "/?p=[postid]" | ||
this.pageType = PageTypeEnum.Html | ||
this.usernameEnabled = true | ||
this.showTokenTip = false | ||
this.allowPreviewUrlChange = true | ||
this.tagEnabled = true | ||
this.cateEnabled = true | ||
this.categoryType = CategoryTypeEnum.CategoryType_Multi | ||
this.allowCateChange = true | ||
this.knowledgeSpaceEnabled = false | ||
} | ||
} | ||
|
||
export { HaloConfig } |
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 { CommonBlogPlaceholder } from "~/src/adaptors/api/base/commonBlogPlaceholder.ts" | ||
|
||
/** | ||
* Halo 配置提示 | ||
*/ | ||
class HaloPlaceholder extends CommonBlogPlaceholder {} | ||
|
||
export { HaloPlaceholder } |
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,97 @@ | ||
/* | ||
* 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 { HaloConfig } from "~/src/adaptors/api/halo/HaloConfig.ts" | ||
import { createAppLogger } from "~/src/utils/appLogger.ts" | ||
import { PublisherAppInstance } from "~/src/publisherAppInstance.ts" | ||
import { useSettingStore } from "~/src/stores/useSettingStore.ts" | ||
import { JsonUtil, ObjectUtil, StrUtil } from "zhi-common" | ||
import { Utils } from "~/src/utils/utils.ts" | ||
import { getDynPostidKey } from "~/src/platforms/dynamicConfig.ts" | ||
import { CategoryTypeEnum } from "zhi-blog-api" | ||
import { HaloApiAdaptor } from "~/src/adaptors/api/halo/HaloApiAdaptor.ts" | ||
|
||
const useHaloApi = async (key: string, newCfg?: HaloConfig) => { | ||
// 创建应用日志记录器 | ||
const logger = createAppLogger("use-halo-api") | ||
|
||
// 记录开始使用 Halo API | ||
logger.info("Start using Halo API...") | ||
|
||
// 创建应用实例 | ||
const appInstance = new PublisherAppInstance() | ||
|
||
let cfg: HaloConfig | ||
if (newCfg) { | ||
logger.info("Initialize with the latest newCfg passed in...") | ||
cfg = newCfg | ||
} else { | ||
// 从配置中获取数据 | ||
const { getSetting } = useSettingStore() | ||
const setting = await getSetting() | ||
cfg = JsonUtil.safeParse<HaloConfig>(setting[key], {} as HaloConfig) | ||
|
||
// 如果配置为空,则使用默认的环境变量值,并记录日志 | ||
if (ObjectUtil.isEmptyObject(cfg)) { | ||
// 从环境变量获取 Halo API 的 URL、认证令牌和其他配置信息 | ||
const haloUsername = Utils.emptyOrDefault(process.env.VITE_YUQUE_USERNAME, "") | ||
const haloAuthToken = Utils.emptyOrDefault(process.env.VITE_YUQUE_AUTH_TOKEN, "") | ||
const middlewareUrl = Utils.emptyOrDefault( | ||
process.env.VITE_MIDDLEWARE_URL, | ||
"https://api.terwer.space/api/middleware" | ||
) | ||
cfg = new HaloConfig(haloUsername, haloAuthToken, middlewareUrl) | ||
logger.info("Configuration is empty, using default environment variables.") | ||
} else { | ||
logger.info("Using configuration from settings...") | ||
} | ||
// 初始化posidKey | ||
if (StrUtil.isEmptyString(cfg.posidKey)) { | ||
// 默认值 | ||
cfg.posidKey = getDynPostidKey(key) | ||
} | ||
} | ||
|
||
// 标签 | ||
cfg.tagEnabled = false | ||
// Halo 使用单选分类作为知识空间 | ||
cfg.cateEnabled = false | ||
cfg.knowledgeSpaceEnabled = true | ||
cfg.knowledgeSpaceType = CategoryTypeEnum.CategoryType_Single | ||
cfg.allowKnowledgeSpaceChange = false | ||
cfg.placeholder.knowledgeSpaceReadonlyModeTip = | ||
"由于语雀平台的限制,暂时不支持编辑所属知识库。如果您想移动文档,请先点击取消删除该文档,然后重新选择新的知识库发布" | ||
|
||
// 创建 Halo API 适配器 | ||
const blogApi = new HaloApiAdaptor(appInstance, cfg) | ||
logger.info("Halo API created successfully.", cfg) | ||
|
||
return { | ||
cfg, | ||
blogApi, | ||
} | ||
} | ||
|
||
export { useHaloApi } |
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
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.