Skip to content

Commit

Permalink
feat:#85 Google插件扩展-修复Metaweblog发布问题
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Sep 25, 2022
1 parent 2db93ca commit e7a8c46
Show file tree
Hide file tree
Showing 15 changed files with 107 additions and 79 deletions.
2 changes: 1 addition & 1 deletion src/components/tab/DynamicPlantform.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const submitForm = async (formEl: FormInstance | undefined) => {
const pkey = formData.plantformKey
// 最终存储的key
const ptypeKey = pType.value.toLowerCase() + "-" + formData.plantformKey
logUtil.logWarn("将要保存的平台key", ptypeKey)
logUtil.logInfo("将要保存的平台key", ptypeKey)
if (isDynamicKeyExists(ptypeKey)) {
ElMessage.error(t('dynamic.platform.opt.key.exist'))
return
Expand Down
2 changes: 1 addition & 1 deletion src/components/tab/PostBind.vue
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ const submitForm = async (formEl: FormInstance | undefined) => {
assignPostid(item.modelValue, customAttr, posidKey, item.posid)
});
logUtil.logWarn("PostBind保存属性到思源笔记,meta=>", customAttr);
logUtil.logInfo("PostBind保存属性到思源笔记,meta=>", customAttr);
await setPageAttrs(siyuanData.pageId, customAttr)
ElMessage.success(t('main.opt.success'))
Expand Down
12 changes: 6 additions & 6 deletions src/components/tab/main/CommonBlogMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ function checkForce() {
// 别名不为空,默认不刷新
if (!forceRefresh.value) {
// ElMessage.warning(t('main.force.refresh.tip'))
logUtil.logWarn(t('main.force.refresh.tip'))
logUtil.logInfo(t('main.force.refresh.tip'))
return false
}
Expand Down Expand Up @@ -462,7 +462,7 @@ const oneclickAttr = async (hideTip?: boolean) => {
// 发布属性
await saveAttrToSiyuan(true)
logUtil.logWarn("发布属性完成")
logUtil.logInfo("发布属性完成")
isGenLoading.value = false
if (hideTip != true) {
Expand Down Expand Up @@ -523,19 +523,19 @@ const doPublish = async () => {
throw new Error("文章更新失败=>" + postid)
}
logUtil.logWarn("文章已更新,postid=>", postid)
logUtil.logInfo("文章已更新,postid=>", postid)
} else {
postid = await api.newPost(post, publish)
// 这里是发布成功之后
// 属性获取postidKey
logUtil.logWarn("当前保存的posidKey=>", commonblogCfg.posidKey)
logUtil.logInfo("当前保存的posidKey=>", commonblogCfg.posidKey)
const customAttr = {
[commonblogCfg.posidKey || ""]: postid,
};
await setPageAttrs(siyuanData.pageId, customAttr)
logUtil.logInfo("CommonblogMain发布成功,保存postid,meta=>", customAttr);
logUtil.logWarn("文章发布成功,postid=>", postid)
logUtil.logInfo("文章发布成功,postid=>", postid)
}
// 刷新属性数据
Expand Down Expand Up @@ -598,7 +598,7 @@ const doCancel = async (isInit: boolean) => {
[commonblogCfg.posidKey || ""]: ""
};
await setPageAttrs(siyuanData.pageId, customAttr)
logUtil.logWarn("MetaweblogMain取消发布,meta=>", customAttr);
logUtil.logInfo("MetaweblogMain取消发布,meta=>", customAttr);
// 刷新属性数据
if (isInit) {
Expand Down
12 changes: 6 additions & 6 deletions src/components/tab/main/MetaweblogMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ function checkForce() {
// 别名不为空,默认不刷新
if (!forceRefresh.value) {
// ElMessage.warning(t('main.force.refresh.tip'))
logUtil.logWarn(t('main.force.refresh.tip'))
logUtil.logInfo(t('main.force.refresh.tip'))
return false
}
Expand Down Expand Up @@ -548,7 +548,7 @@ const oneclickAttr = async (hideTip?: boolean) => {
// 发布属性
await saveAttrToSiyuan(true)
logUtil.logWarn("发布属性完成")
logUtil.logInfo("发布属性完成")
isGenLoading.value = false
if (hideTip != true) {
Expand Down Expand Up @@ -613,19 +613,19 @@ const doPublish = async () => {
throw new Error("文章更新失败=>" + postid)
}
logUtil.logWarn("文章已更新,postid=>", postid)
logUtil.logInfo("文章已更新,postid=>", postid)
} else {
postid = await api.newPost(post, publish)
// 这里是发布成功之后
// 属性获取postidKey
logUtil.logWarn("当前保存的posidKey=>", metaweblogCfg.posidKey)
logUtil.logInfo("当前保存的posidKey=>", metaweblogCfg.posidKey)
const customAttr = {
[metaweblogCfg.posidKey]: postid,
};
await setPageAttrs(siyuanData.pageId, customAttr)
logUtil.logInfo("MetaweblogMain发布成功,保存postid,meta=>", customAttr);
logUtil.logWarn("文章发布成功,postid=>", postid)
logUtil.logInfo("文章发布成功,postid=>", postid)
}
// 刷新属性数据
Expand Down Expand Up @@ -686,7 +686,7 @@ const doCancel = async (isInit: boolean) => {
[metaweblogCfg.posidKey]: ""
};
await setPageAttrs(siyuanData.pageId, customAttr)
logUtil.logWarn("MetaweblogMain取消发布,meta=>", customAttr);
logUtil.logInfo("MetaweblogMain取消发布,meta=>", customAttr);
// 刷新属性数据
if (isInit) {
Expand Down
22 changes: 11 additions & 11 deletions src/components/tab/main/VuepressMain.vue
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ watch(() => props.isReload, async (oldValue, newValue) => {
// 初始化
await initPage()
logUtil.logWarn("VuepressMain检测到更新操作,刷新页面")
logUtil.logInfo("VuepressMain检测到更新操作,刷新页面")
})
onBeforeMount(async () => {
Expand Down Expand Up @@ -325,7 +325,7 @@ async function initPage() {
ElMessage.error("网络异常,数据获取失败")
throw new Error("网络异常,数据获取失败")
}
logUtil.logWarn("VuepressMain获取主文档", page)
logUtil.logInfo("VuepressMain获取主文档", page)
// 思源笔记数据
siyuanData.value.pageId = pageId;
Expand Down Expand Up @@ -405,7 +405,7 @@ function checkForce() {
// 别名不为空,默认不刷新
if (!forceRefresh.value) {
// ElMessage.warning(t('main.force.refresh.tip'))
logUtil.logWarn(t('main.force.refresh.tip'))
logUtil.logInfo(t('main.force.refresh.tip'))
return false
}
Expand Down Expand Up @@ -535,7 +535,7 @@ async function saveAttrToSiyuan(hideTip?: boolean) {
tags: formData.value.tag.dynamicTags.join(",")
};
await setPageAttrs(siyuanData.value.pageId, customAttr)
logUtil.logWarn("VuepressMain保存属性到思源笔记,meta=>", customAttr);
logUtil.logInfo("VuepressMain保存属性到思源笔记,meta=>", customAttr);
// 单独调用才去刷新数据,否则自行刷新数据
if (hideTip != true) {
Expand Down Expand Up @@ -706,7 +706,7 @@ async function doPublish() {
return
} else if (isOk && vuepressGithubEnabled.value) {
// api可用并且开启了发布
logUtil.logWarn("开始真正调用api发布到Github")
logUtil.logInfo("开始真正调用api发布到Github")
const vuepressCfg = getJSONConf<IVuepressCfg>(API_TYPE_CONSTANTS.API_TYPE_VUEPRESS)
Expand All @@ -716,13 +716,13 @@ async function doPublish() {
// 如果选择了自定义的目录
if (formData.value.customPath.indexOf(".md") > -1) {
docPath = formData.value.customPath
logUtil.logWarn("已经有完整路径,不拼接")
logUtil.logInfo("已经有完整路径,不拼接")
} else {
docPath = formData.value.customPath + "/" + mdFile
}
logUtil.logInfo(formData.value.customPath)
logUtil.logWarn("文章讲发布于以下路径=>", docPath)
logUtil.logInfo("文章讲发布于以下路径=>", docPath)
}
// 发布内容
Expand All @@ -734,7 +734,7 @@ async function doPublish() {
vuepressData.value.vuepressContent = md;
vuepressData.value.vuepressFullContent = mdContent;
logUtil.logWarn("即将发布的内容,mdContent=>", {"mdContent": mdContent})
logUtil.logInfo("即将发布的内容,mdContent=>", {"mdContent": mdContent})
// 发布
const res = await publishPage(vuepressCfg, docPath, mdContent)
Expand Down Expand Up @@ -764,7 +764,7 @@ async function doPublish() {
// 刷新属性数据
await initPage();
}
logUtil.logWarn("发布内容完成")
logUtil.logInfo("发布内容完成")
isPublishLoading.value = false
ElMessage.success(t('main.opt.status.publish'))
Expand All @@ -782,7 +782,7 @@ async function oneclickAttr(hideTip?: boolean) {
// 发布属性
await saveAttrToSiyuan(true)
logUtil.logWarn("发布属性完成")
logUtil.logInfo("发布属性完成")
isGenLoading.value = false
if (hideTip != true) {
Expand Down Expand Up @@ -830,7 +830,7 @@ async function doCancel(isInit: boolean) {
[POSTID_KEY_CONSTANTS.VUEPRESS_POSTID_KEY]: ""
};
await setPageAttrs(siyuanData.value.pageId, customAttr)
logUtil.logWarn("VuepressMain取消发布,meta=>", customAttr);
logUtil.logInfo("VuepressMain取消发布,meta=>", customAttr);
// 刷新属性数据
if (isInit) {
Expand Down
4 changes: 2 additions & 2 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function getConf(key: string): string {

const value = localStorage.getItem(key)
if (!value) {
logUtil.logWarn("未找到对应数据,key=>", key)
logUtil.logInfo("未找到对应数据,key=>", key)
return "";
}
logUtil.logInfo("从localStorage获取数据=>", value)
Expand Down Expand Up @@ -112,7 +112,7 @@ export function setJSONConf<T>(key: string, value: T): void {
*/
export function setConf(key: string, value: string): void {
if (!value || value == "") {
logUtil.logWarn("空值,不保存")
logUtil.logInfo("空值,不保存")
return
}

Expand Down
1 change: 0 additions & 1 deletion src/lib/envUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export function getEnv(key: string) {
}
} catch (e:any) {
throw new Error(e)
// logUtil.logWarn(e)
}

return env
Expand Down
6 changes: 3 additions & 3 deletions src/lib/platform/commonblog/commonblogApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ export class CommonblogApi {

const widgetResult = await getWidgetId()
if (widgetResult.isInSiyuan) {
logUtil.logWarn("当前处于挂件模式,使用electron的fetch获取数据")
logUtil.logInfo("当前处于挂件模式,使用electron的fetch获取数据")
// 不解析了,直接使用Node兼容调用
result = await fetch(apiUrl, fetchOptions)
} else if (isInChromeExtension()) {
logUtil.logWarn("当前处于Chrome插件中,需要模拟fetch解决CORS跨域问题")
logUtil.logInfo("当前处于Chrome插件中,需要模拟fetch解决CORS跨域问题")
result = await this.fetchChromeCORS(apiUrl, fetchOptions, formJson)
} else {
logUtil.logWarn("当前处于非挂件模式,已开启请求代理解决CORS跨域问题")
logUtil.logInfo("当前处于非挂件模式,已开启请求代理解决CORS跨域问题")
logUtil.logInfo("formJson=>", formJson)
result = await this.fetchCORS(apiUrl, fetchOptions, formJson)
}
Expand Down
56 changes: 37 additions & 19 deletions src/lib/platform/metaweblog/CustomMetaweblogApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export class CustomMetaWeblogApi {
val = obj.value
break
} else {
val = obj.value.string || obj.value.int || obj.value.i4
val = obj.value.string || obj.value.int || obj.value.i4 || obj.value
break
}
}
Expand Down Expand Up @@ -138,7 +138,21 @@ export class CustomMetaWeblogApi {
post.mt_excerpt = this.parseFieldValue(postObj, "mt_excerpt")
post.wp_slug = this.parseFieldValue(postObj, "wp_slug")
post.dateCreated = this.parseFieldValue(postObj, "dateCreated")
post.categories = this.parseFieldValue(postObj, "categories")

let pcats = <any[]>[]
const cats = this.parseFieldValue(postObj, "categories")?.array?.data?.value || []
if (typeof cats?.string == 'string') {
pcats.push(cats.string)
} else {
// logUtil.logInfo("cats=>", cats)
cats.forEach((cat: any) => {
const item = cat.string
pcats.push(item)
})
}
// logUtil.logInfo("pcats=>", pcats)
post.categories = pcats

post.mt_text_more = this.parseFieldValue(postObj, "mt_text_more")

return post
Expand All @@ -149,8 +163,7 @@ export class CustomMetaWeblogApi {

const ret = await this.xmlrpcClient.methodCallEntry(METAWEBLOG_METHOD_CONSTANTS.GET_POST,
[postid, username, password])
logUtil.logInfo("getPost ret=>")
logUtil.logInfo(ret)
logUtil.logInfo("getPost ret=>", ret)

// 错误处理
this.doFault(ret)
Expand All @@ -161,6 +174,7 @@ export class CustomMetaWeblogApi {
// 这里原样返回,到适配器再去自己处理
// post.description = render(post.description)

logUtil.logInfo("getPost post=>", post)
return Promise.resolve(post)
}

Expand All @@ -179,15 +193,16 @@ export class CustomMetaWeblogApi {
}

const postStruct = this.createPostStruct(post)
logUtil.logWarn("postStruct=>")
logUtil.logWarn(postStruct)
logUtil.logInfo("postStruct=>")
logUtil.logInfo(postStruct)

let ret = await this.xmlrpcClient.methodCallEntry(METAWEBLOG_METHOD_CONSTANTS.NEW_POST,
[this.apiType, username, password, postStruct, publish])
ret = ret.replace(/"/g, "")
logUtil.logInfo("newPost ret=>")
logUtil.logInfo(ret)

return ret;
let retStr = ret.params.param.value.string || ""
logUtil.logInfo("newPost retStr=>", retStr.toString())

return retStr.toString();
}

public async editPost(postid: string, username: string, password: string, post: Post, publish: boolean): Promise<boolean> {
Expand All @@ -197,23 +212,25 @@ export class CustomMetaWeblogApi {
}

const postStruct = this.createPostStruct(post)
logUtil.logWarn("postStruct=>")
logUtil.logWarn(postStruct)
logUtil.logInfo("postStruct=>")
logUtil.logInfo(postStruct)
const ret = await this.xmlrpcClient.methodCallEntry(METAWEBLOG_METHOD_CONSTANTS.EDIT_POST,
[postid, username, password, postStruct, publish])
logUtil.logInfo("editPost ret=>")
logUtil.logInfo(ret)

return ret;
let retBool = ret.params.param.value.boolean || ""
logUtil.logInfo("editPost retBool=>", retBool)

return retBool;
}

public async deletePost(appKey: string, postid: string, username: string, password: string, publish: boolean) {
const ret = await this.xmlrpcClient.methodCallEntry(METAWEBLOG_METHOD_CONSTANTS.DELETE_POST,
[appKey, postid, username, password, publish])
logUtil.logInfo("deletePost ret=>")
logUtil.logInfo(ret)

return ret;
let retBool = ret.params.param.value.boolean || ""
logUtil.logInfo("deletePost retBool=>", retBool)

return retBool;
};

/**
Expand Down Expand Up @@ -290,7 +307,7 @@ export class CustomMetaWeblogApi {

let ret = await this.xmlrpcClient.methodCallEntry(METAWEBLOG_METHOD_CONSTANTS.GET_CATEGORIES,
[this.apiType, username, password])
logUtil.logInfo("getCategories ret=>", ret)
// logUtil.logInfo("getCategories ret=>", ret)

// 错误处理
this.doFault(ret)
Expand All @@ -301,6 +318,7 @@ export class CustomMetaWeblogApi {
result.push(cat)
})

// logUtil.logInfo("getCategories result=>", result)
return result
}

Expand Down
Loading

0 comments on commit e7a8c46

Please sign in to comment.