Skip to content

Commit

Permalink
chore: #309 深度适配Typecho-移除头部错误信息
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Jan 6, 2023
1 parent 7fb24b7 commit 975ccfd
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 10 deletions.
13 changes: 12 additions & 1 deletion components/publish/tab/main/MetaweblogMain.vue
Expand Up @@ -307,7 +307,11 @@ import {
} from "~/utils/util"
import { SiYuanApi } from "~/utils/platform/siyuan/siYuanApi"
import { formatNumToZhDate } from "~/utils/dateUtil"
import { getPublishCfg, getPublishStatus } from "~/utils/publishUtil"
import {
getApiParams,
getPublishCfg,
getPublishStatus,
} from "~/utils/publishUtil"
import { CONSTANTS } from "~/utils/constants/constants"
const logger = LogFactory.getLogger(
Expand Down Expand Up @@ -488,6 +492,13 @@ const initPage = async () => {
isInitLoading.value = false
logger.error("文章新获取失败", e)
}
} else {
logger.warn("检测到之前发布异常,清空文章ID")
const postidKey = getApiParams<IMetaweblogCfg>(props.apiType).posidKey
const customAttr = {
[postidKey]: "",
}
await siyuanApi.setBlockAttrs(siyuanData.pageId, customAttr)
}
// 全部文章分类请求
Expand Down
43 changes: 43 additions & 0 deletions libs/simple-xmlrpc/custom/xmlrpcUtil.ts
@@ -0,0 +1,43 @@
/*
* 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.
*/

/**
* Xmlrpc工具栏
*/
export class XmlrpcUtil {
/**
* 移除xml头部有非法字符
* @param resText xml字符串
*/
static removeXmlHeader(resText: string): string {
const startIndex = resText.indexOf("<?xml")
if (startIndex > 0) {
console.warn("xml头部有非法字符,将去除=>", resText)
resText = resText.substring(startIndex, resText.length)
}
console.log("methodCall resText=>", resText)
return resText
}
}
3 changes: 3 additions & 0 deletions libs/simple-xmlrpc/xmlrpc/Deserializer.ts
Expand Up @@ -216,6 +216,9 @@ export class Deserializer {
case "MEMBER":
// Ignored by design
break
case "BR":
// Ignored by typecho
break
default:
this._onError(new Error(`Unknown XML-RPC tag "${el}"`))
break
Expand Down
4 changes: 3 additions & 1 deletion libs/simple-xmlrpc/xmlrpc/XmlRpcClient.ts
Expand Up @@ -34,6 +34,7 @@ import {
XmlRpcValue,
XmlRpcValueOrFault,
} from "./XmlRpcTypes"
import { XmlrpcUtil } from "../custom/xmlrpcUtil"

// A client for making XML-RPC method calls over HTTP(S)
export class XmlRpcClient {
Expand Down Expand Up @@ -80,7 +81,8 @@ export class XmlRpcClient {
)
}

const resText = await res.text()
let resText = await res.text()
resText = XmlrpcUtil.removeXmlHeader(resText)
const deserializer = new Deserializer(this.encoding)
return await deserializer.deserializeMethodResponse(resText)
}
Expand Down
14 changes: 6 additions & 8 deletions utils/publishUtil.ts
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, Terwer . All rights reserved.
* Copyright (c) 2022-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
Expand Down Expand Up @@ -35,12 +35,11 @@ import { ICommonblogCfg } from "~/utils/platform/commonblog/commonblogCfg"
import { LogFactory } from "~/utils/logUtil"
import { PublishPreference } from "~/utils/models/publishPreference"
import { CONSTANTS } from "~/utils/constants/constants"
import { isEmptyObject, parseBoolean } from "~/utils/util"
import { isEmptyObject, isEmptyString, parseBoolean } from "~/utils/util"
import { PageEditMode } from "~/utils/common/pageEditMode"
import { SourceContentShowType } from "~/utils/common/sourceContentShowType"

const logger = LogFactory.getLogger("utils/publishUtil.ts")
const isProd = process.env.NODE_ENV === "production"

/**
* 新版获取apiParams参数的方法,使用ts泛型
Expand Down Expand Up @@ -112,33 +111,32 @@ export const getPublishStatus = (apiType: string, meta: any): boolean => {
}
})

// 处理
let postId
if (githubTypeArray.includes(apiType)) {
const postidKey = getApiParams<IGithubCfg>(apiType).posidKey
const postId = meta[postidKey] || ""
postId = meta[postidKey] || ""
logger.debug("平台=>", apiType)
logger.debug("meta=>", meta)
logger.debug("postidKey=>", postidKey)
logger.debug("postidKey的值=>", postId)
return postId !== ""
} else if (metaweblogTypeArray.includes(apiType)) {
const postidKey = getApiParams<IMetaweblogCfg>(apiType).posidKey
const postId = meta[postidKey] || ""
logger.debug("平台=>", apiType)
logger.debug("meta=>", meta)
logger.debug("postidKey=>", postidKey)
logger.debug("postidKey的值=>", postId)
return postId !== ""
} else if (commonblogTypeArray.includes(apiType)) {
const postidKey = getApiParams<ICommonblogCfg>(apiType).posidKey
const postId = meta[postidKey ?? ""] || ""
logger.debug("平台=>", apiType)
logger.debug("meta=>", meta)
logger.debug("postidKey=>", postidKey)
logger.debug("postidKey的值=>", postId)
return postId !== ""
}

return false
return isEmptyString(postId)
}

/**
Expand Down

0 comments on commit 975ccfd

Please sign in to comment.