Skip to content

Commit

Permalink
fix: #434 文章没有图片时候图床错误文章发布失败
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Mar 25, 2023
1 parent 53b5016 commit 3f286fa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 30 deletions.
23 changes: 11 additions & 12 deletions utils/otherlib/ChromeUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,14 @@ export const isSlot = getQueryString("isSlot") === "true"
* 检测文件是否存在
* @returns {boolean}
*/
export const isFileExist = (filepath) => {
const syWin = siyuanBrowserUtil.getSiyuanWindow()
const fs = syWin.require("fs")

if (fs.existsSync(filepath)) {
console.log("File exists")
return true
} else {
console.log("File does not exist")
return false
}
}
// export const isFileExist = (filepath) => {
// const fs = require("fs")
//
// if (fs.existsSync(filepath)) {
// console.log("File exists")
// return true
// } else {
// console.log("File does not exist")
// return false
// }
// }
10 changes: 3 additions & 7 deletions utils/otherlib/confUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* questions.
*/

import { isBrowser, isElectron } from "~/utils/browserUtil"
import { isElectron } from "~/utils/browserUtil"
import { isInSiyuanWidget } from "~/utils/platform/siyuan/siyuanUtil"

/**
Expand All @@ -33,7 +33,7 @@ import { isInSiyuanWidget } from "~/utils/platform/siyuan/siyuanUtil"
* @since 0.6.8
*/
export const getLocalStorageAdaptor = (cfgfile) => {
let ret
let ret = window.localStorage

if (isElectron) {
if (isInSiyuanWidget()) {
Expand All @@ -47,11 +47,7 @@ export const getLocalStorageAdaptor = (cfgfile) => {
}
ret.switchCfg(cfg)
} else {
if (isBrowser()) {
ret = window.localStorage
} else {
ret = global.localStorage
}
ret = window.localStorage
}

return ret
Expand Down
17 changes: 6 additions & 11 deletions utils/platform/picgo/picgoPostApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ import { getSiyuanCfg } from "~/utils/platform/siyuan/siYuanConfig"
import { SiYuanApi } from "~/utils/platform/siyuan/siYuanApi"
import { isElectron } from "~/utils/browserUtil"
import { getSiyuanNewWinDataDir } from "~/utils/otherlib/siyuanBrowserUtil"
import { isFileExist } from "~/utils/otherlib/ChromeUtil"
import picgoUtil from "~/utils/otherlib/picgoUtil"
import { ElMessage } from "element-plus"

/**
* Picgo与文章交互的通用方法
Expand Down Expand Up @@ -80,10 +78,6 @@ export class PicgoPostApi {
}

const imageItem = new ImageItem(originUrl, imgUrl, isLocal)
// logger.debug("imageItem.hash imageItem.name=>", imageItem.name)
// logger.debug("imageItem.hash fileMap=>", fileMap)
// logger.debug("imageItem.hash=>", imageItem.hash)
// logger.debug("fileMap[imageItem.hash]=>", fileMap[imageItem.hash])
if (fileMap[imageItem.hash]) {
const newImageItem = fileMap[imageItem.hash]
this.logger.debug("newImageItem=>", newImageItem)
Expand Down Expand Up @@ -130,8 +124,9 @@ export class PicgoPostApi {

ret.localImages = imageItemArray
ret.unuploadImages = unuploadedImages
this.logger.debug("localImages=>", ret.localImages)
this.logger.debug("unuploadImages=>", ret.unuploadImages)
this.logger.debug("attrs=>", attrs)
this.logger.debug("uniqueLocalImages=>", uniqueLocalImages)
this.logger.debug("ret=>", ret)

return ret
}
Expand Down Expand Up @@ -225,9 +220,9 @@ export class PicgoPostApi {
imageFullPath = `${dataDir}/${imagePath}`

// 不存在就用网页url
if (!isFileExist(imageFullPath)) {
imageFullPath = imageItem.url
}
// if (!isFileExist(imageFullPath)) {
// imageFullPath = imageItem.url
// }
} else {
imageFullPath = imageItem.url
}
Expand Down

0 comments on commit 3f286fa

Please sign in to comment.