Skip to content

Commit

Permalink
feat: 支持接入平台自有能力进行图片上传
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Aug 11, 2023
1 parent 87eeaff commit efccca6
Show file tree
Hide file tree
Showing 72 changed files with 369 additions and 343 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,20 @@
"shorthash2": "^1.0.3",
"simple-xmlrpc": "^1.4.2",
"siyuan": "^0.7.9",
"siyuan-plugin-picgo": "^1.2.0",
"siyuan-plugin-picgo": "^1.3.0",
"uuid": "^9.0.0",
"vue": "^3.3.4",
"vue-i18n": "^9.2.2",
"vue-router": "^4.2.4",
"xmlbuilder2": "^3.1.1",
"zhi-blog-api": "^1.20.17",
"zhi-blog-api": "^1.20.21",
"zhi-common": "^1.14.2",
"zhi-device": "^2.3.0",
"zhi-fetch-middleware": "^0.2.20",
"zhi-github-middleware": "^0.2.2",
"zhi-lib-base": "^0.4.4",
"zhi-notion-markdown": "^0.1.2",
"zhi-siyuan-api": "^2.0.21",
"zhi-siyuan-api": "^2.0.26",
"zhi-xmlrpc-middleware": "^0.4.15"
}
}
28 changes: 14 additions & 14 deletions pnpm-lock.yaml

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

77 changes: 0 additions & 77 deletions src/adaptors/api/base/CommonblogConfig.ts

This file was deleted.

7 changes: 6 additions & 1 deletion src/adaptors/api/base/baseBlogApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* questions.
*/

import { BlogApi, BlogConfig } from "zhi-blog-api"
import { BlogApi, BlogConfig, Post } from "zhi-blog-api"
import { SiyuanKernelApi } from "zhi-siyuan-api"
import { CommonFetchClient } from "zhi-fetch-middleware"
import { AppInstance } from "~/src/appInstance.ts"
Expand Down Expand Up @@ -64,6 +64,11 @@ export class BaseBlogApi extends BlogApi {
this.useSiyuanProxy = isUseSiyuanProxy()
}

public async preEditPost(post: Post, id?: string, publishCfg?: any): Promise<Post> {
this.logger.info("未处理,原样返回。如需处理,请在子类重写")
return post
}

// ================
// private methods
// ================
Expand Down
54 changes: 54 additions & 0 deletions src/adaptors/api/base/commonBlogConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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, PageTypeEnum } from "zhi-blog-api"
import { CommonBlogPlaceholder } from "~/src/adaptors/api/base/commonBlogPlaceholder.ts"

export class CommonBlogConfig extends BlogConfig {

/**
* 操作提示
*/
public override placeholder = {} as CommonBlogPlaceholder

constructor(home: string, apiUrl: string, username: string, password: string, middlewareUrl?: string) {
super()
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.middlewareUrl = middlewareUrl
this.usernameEnabled = false
this.allowPreviewUrlChange = true
this.showTokenTip = false
this.placeholder = new CommonBlogPlaceholder()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ import { BlogPlaceholder } from "zhi-blog-api"
/**
* Metaweblog 操作提示
*/
export class CommonblogPlaceholder extends BlogPlaceholder {}
export class CommonBlogPlaceholder extends BlogPlaceholder {}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { BaseBlogApi } from "~/src/adaptors/api/base/baseBlogApi.ts"
import { createAppLogger } from "~/src/utils/appLogger.ts"
import { CategoryInfo, Post, UserBlog } from "zhi-blog-api"
import { CommonGithubClient, GithubConfig } from "zhi-github-middleware"
import { CommonGithubConfig } from "~/src/adaptors/api/base/github/CommonGithubConfig.ts"
import { CommonGithubConfig } from "~/src/adaptors/api/base/github/commonGithubConfig.ts"
import { StrUtil } from "zhi-common"
import { toRaw } from "vue"
import { Base64 } from "js-base64"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
*/

import { PasswordType } from "zhi-blog-api"
import { CommonblogConfig } from "~/src/adaptors/api/base/CommonblogConfig.ts"
import { CommonBlogConfig } from "~/src/adaptors/api/base/commonBlogConfig.ts"

/**
* CommonGithubConfig 类用于存储 GitHub 相关配置信息
*/
class CommonGithubConfig extends CommonblogConfig {
class CommonGithubConfig extends CommonBlogConfig {
/**
* Github仓库名称
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
* questions.
*/

import { CommonblogPlaceholder } from "~/src/adaptors/api/base/CommonblogPlaceholder.ts"
import { CommonBlogPlaceholder } from "~/src/adaptors/api/base/commonBlogPlaceholder.ts"

/**
* Github 操作提示
*/
class CommonGithubPlaceholder extends CommonblogPlaceholder {}
class CommonGithubPlaceholder extends CommonBlogPlaceholder {}

export { CommonGithubPlaceholder }
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,34 @@
* questions.
*/

import { BlogApi, CategoryInfo, Post, PostStatusEnum, UserBlog } from "zhi-blog-api"
import { AppInstance } from "~/src/appInstance.ts"
import { CategoryInfo, Post, PostStatusEnum, UserBlog } from "zhi-blog-api"
import { createAppLogger } from "~/src/utils/appLogger.ts"
import { CommonXmlrpcClient } from "zhi-xmlrpc-middleware"
import { MetaweblogConfig } from "~/src/adaptors/api/base/metaweblog/MetaweblogConfig.ts"
import { MetaweblogConstants } from "~/src/adaptors/api/base/metaweblog/metaweblogConstants.ts"
import { StrUtil } from "zhi-common"
import { BrowserUtil } from "zhi-device"
import { BaseBlogApi } from "~/src/adaptors/api/base/baseBlogApi.ts"
import { MetaweblogConfig } from "~/src/adaptors/api/base/metaweblog/metaweblogConfig.ts"

/**
* MetaweblogBlogApi 类继承自 BlogApi 类,并为 Metaweblog API 提供了额外的功能
* MetaweblogBlogApi 类继承自 BaseBlogApi 类,并为 Metaweblog API 提供了额外的功能
*
* @author terwer
* @version 0.9.0
* @since 0.9.0
*/
class MetaweblogBlogApi extends BlogApi {
protected readonly cfg: MetaweblogConfig
protected logger
private readonly commonXmlrpcClient
class MetaweblogBlogApiAdaptor extends BaseBlogApi {
private readonly commonXmlrpcClient: CommonXmlrpcClient

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

this.cfg = cfg
this.cfg.blogid = "metaweblog"
this.logger = createAppLogger("metaweblog-api-adaptor")
this.commonXmlrpcClient = new CommonXmlrpcClient(appInstance, cfg.apiUrl)
Expand All @@ -75,11 +72,11 @@ class MetaweblogBlogApi extends BlogApi {
*
* @param keyword
*/
public override async getRecentPostsCount(keyword?: string): Promise<number> {
public async getRecentPostsCount(keyword?: string): Promise<number> {
return 0
}

public override async getRecentPosts(numOfPosts: number): Promise<Post[]> {
public async getRecentPosts(numOfPosts: number): Promise<Post[]> {
const result: Post[] = []
const blogPosts = await this.metaweblogCall(MetaweblogConstants.METHOD_GET_RECENT_POSTS, [
this.cfg.blogid,
Expand Down Expand Up @@ -287,4 +284,4 @@ class MetaweblogBlogApi extends BlogApi {
}
}

export { MetaweblogBlogApi }
export { MetaweblogBlogApiAdaptor }
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@
*/

import { PageTypeEnum } from "zhi-blog-api"
import { MetaweblogPlaceholder } from "~/src/adaptors/api/base/metaweblog/MetaweblogPlaceholder.ts"
import { CommonblogConfig } from "~/src/adaptors/api/base/CommonblogConfig.ts"
import { MetaweblogPlaceholder } from "~/src/adaptors/api/base/metaweblog/metaweblogPlaceholder.ts"
import { CommonBlogConfig } from "~/src/adaptors/api/base/commonBlogConfig.ts"

/**
* Metaweblog配置类
*/
export class MetaweblogConfig extends CommonblogConfig {
export class MetaweblogConfig extends CommonBlogConfig {
/**
* 首页
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
* questions.
*/

import { CommonblogPlaceholder } from "~/src/adaptors/api/base/CommonblogPlaceholder.ts"
import { CommonBlogPlaceholder } from "~/src/adaptors/api/base/commonBlogPlaceholder.ts"

/**
* Metaweblog 操作提示
*/
export class MetaweblogPlaceholder extends CommonblogPlaceholder {}
export class MetaweblogPlaceholder extends CommonBlogPlaceholder {}
Loading

0 comments on commit efccca6

Please sign in to comment.