Skip to content

Commit

Permalink
Merge pull request #411 from terwer/dev
Browse files Browse the repository at this point in the history
fix: image url join error for qiniu yun
  • Loading branch information
terwer committed Apr 22, 2024
2 parents 941a86f + 0bfc306 commit 41a0442
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 32 deletions.
23 changes: 16 additions & 7 deletions libs/Universal-PicGo-Core/src/core/ExternalPicgo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import ExternalPicgoConfigDb from "../db/externalPicGo"
import { IImgInfo, IPicGo } from "../types"
import { PicgoTypeEnum } from "../utils/enums"
import { browserPathJoin } from "../utils/browserUtils"
import { isFileOrBlob } from "../utils/common"
import { fileToBuffer, isFileOrBlob } from "../utils/common"
import { CodingUtil } from "../utils/CodingUtil"

/**
*外部的PicGO 上传 Api
Expand Down Expand Up @@ -48,17 +49,25 @@ class ExternalPicgo {
}

// check blob
let hasBlob = false
const newInput = []
if (input) {
for (const inputItem of input) {
if (isFileOrBlob(inputItem) || typeof inputItem !== "string") {
hasBlob = true
break
if (isFileOrBlob(inputItem)) {
this.logger.warn("try to get path from blob", inputItem.path)
if (inputItem.path.trim() === "") {
this.logger.warn("blob path is empty")
continue
}
newInput.push(inputItem.path)
} else {
newInput.push(inputItem)
}
}
input = newInput
}
if (hasBlob) {
throw new Error("blob is not supported via external picgo api")

if (input?.length === 0) {
throw new Error(`cannot not find valid image`)
}

this.requestUrl = this.db.get("extPicgoApiUrl") ?? this.requestUrl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import mime from "mime-types"
import { AxiosRequestConfig } from "axios"
import { Mac } from "./digest"
import { PutPolicy } from "./rs"
import { browserPathJoin } from "../../../utils/browserUtils"

function postOptions(options: IQiniuConfig, fileName: string, token: string, imgBase64: string): AxiosRequestConfig {
const area = selectArea(options.area || "z0")
Expand Down Expand Up @@ -79,7 +80,7 @@ const handle = async (ctx: IPicGo): Promise<IPicGo> => {
delete img.buffer
const baseUrl = qiniuOptions.url
const options = qiniuOptions.options
img.imgUrl = `${baseUrl}/${body.key as string}${options}`
img.imgUrl = browserPathJoin(baseUrl, body.key, options)
} else {
ctx.emit(IBuildInEvent.NOTIFICATION, {
title: ctx.i18n.translate<ILocalesKey>("UPLOAD_FAILED"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,26 @@ const handleExceed = (_e: any) => {
ElMessage.error("selected files exceed to upload limit " + limit.value)
}
const handlePasteAction = (e: any) => {
e.preventDefault()
retrieveImageFromClipboardAsBlob(e, function (imageBlob: any) {
if (imageBlob && imageBlob instanceof Blob) {
const file = new File([imageBlob], "image.png", { type: "image/png" })
handleDragAction(file)
} else {
ElMessage.error("image not found in browser clipboard")
}
})
}
onBeforeMount(() => {
window.addEventListener("paste", handlePasteAction)
})
onBeforeUnmount(() => {
window.removeEventListener("paste", handlePasteAction)
})
// const handlePasteAction = (e: any) => {
// e.preventDefault()
//
// retrieveImageFromClipboardAsBlob(e, function (imageBlob: any) {
// if (imageBlob && imageBlob instanceof Blob) {
// const file = new File([imageBlob], "image.png", { type: "image/png" })
// handleDragAction(file)
// } else {
// ElMessage.error("image not found in browser clipboard")
// }
// })
// }
// onBeforeMount(() => {
// window.addEventListener("paste", handlePasteAction)
// })
//
// onBeforeUnmount(() => {
// window.removeEventListener("paste", handlePasteAction)
// })
</script>

<template>
Expand Down
4 changes: 2 additions & 2 deletions packages/picgo-plugin-app/src/i18n/en_US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ export default {
"setting.blog.siyuan.password": "Siyuan Token",
"setting.blog.siyuan.password.tip": "Siyuan Token, which is empty by default",
"form.validate.name.required": "Please enter a name",
"upload.select.tip1": "Drop file here, Ctrl+V paste image here or",
"upload.select.tip1": "Drop file here or",
"upload.select.tip2": "click to upload",
"upload.select.limit": "jp(e)g/png/gif/svg/webp files with a size less than 500kb, max upload size is",
"upload.select.limit": "jp(e)g/png/gif/svg/webp files, max upload size is",
"upload.tab.upload": "Picture upload",
"upload.tab.setting": "Plugin setting",
"component.test": "Component test",
Expand Down
4 changes: 2 additions & 2 deletions packages/picgo-plugin-app/src/i18n/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ export default {
"setting.blog.siyuan.password": "思源Token",
"setting.blog.siyuan.password.tip": "思源Token,默认是空",
"form.validate.name.required": "请输入名称",
"upload.select.tip1": "拖拽图片到这里、Ctrl+V从剪切板粘贴或者",
"upload.select.tip1": "拖拽图片到这里或者",
"upload.select.tip2": "选择图片",
"upload.select.limit": "支持jp(e)g/png/gif/svg/webp 格式,大小不超过 500kb, 单次最大上传图片数量限制为",
"upload.select.limit": "支持jp(e)g/png/gif/svg/webp 格式,单次最大上传图片数量限制为",
"upload.tab.upload": "图片上传",
"upload.tab.setting": "插件设置",
"component.test": "组件测试",
Expand Down
11 changes: 11 additions & 0 deletions scripts/make_dev_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@
devOutDir = 'artifacts/siyuan-plugin-picgo/dist'
# ******************************************************************************************


# 如果不存在cookie.txt创建一个空的 cookie.txt
# 检查并创建空的 cookie.txt 和 token.txt
if not os.path.exists('cookie.txt'):
with open('cookie.txt', 'w', encoding='utf-8'):
pass
# 如果不存在token.txt创建一个空的 如果不存在token.txt
if not os.path.exists('token.txt'):
with open('token.txt', 'w', encoding='utf-8'):
pass

with open('cookie.txt', 'r', encoding='utf-8') as cookie_file, open('token.txt', 'r', encoding='utf-8') as token_file:
cookie = cookie_file.read().strip()
token = token_file.read().strip()
Expand Down

0 comments on commit 41a0442

Please sign in to comment.