Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow config timeout #332

Merged
merged 9 commits into from Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions README.md
@@ -1,15 +1,16 @@
[中文](README_zh_CN.md)

- SM.MS
# PicGo Plugin

![](./preview.png)

Your favorite PicGo image bed is still available in siyuan-notes, wuhu~

> Important Note:
>
> Please refrain from updating this plugin for versions of siyuan-note prior to `3.0.3`; the highest permissible version remains `1.5.1`. For siyuan-note versions `3.0.3` and beyond, the PicGO plugin may be upgraded to `1.6.0+`.
>
> Important Note:
>
> Please refrain from updating this plugin for versions of siyuan-note prior to `3.0.3`; the highest permissible version remains `1.5.1`. For siyuan-note versions `3.0.3` and beyond, the PicGO plugin may be upgraded to `1.6.0+`.
>
> For versions of siyuan-note before `2.10.8`, it is advised not to upgrade this plugin beyond version `1.4.5`. Subsequent to siyuan-note `2.10.8`, the PicGO plugin can be updated to `1.5.0+`.

## Image Hosting Support
Expand All @@ -20,7 +21,6 @@ Your favorite PicGo image bed is still available in siyuan-notes, wuhu~
- Tencent Cloud
- Upyun
- Qiniu Cloud
- SM.MS
- imgur

## Changelog
Expand Down
5 changes: 4 additions & 1 deletion libs/Universal-PicGo-Core/custom.d.ts
Expand Up @@ -3,6 +3,9 @@ declare module '*.json' {
export default value
}

declare module '*raw'

declare module "ali-oss"
declare module "arraybuffer-to-buffer"
declare module "upyun"
declare module "upyun"
declare module "js-yaml"
2 changes: 1 addition & 1 deletion libs/zhi-siyuan-picgo/package.json
Expand Up @@ -36,7 +36,7 @@
"zhi-common": "^1.33.0",
"zhi-device": "^2.11.0",
"zhi-lib-base": "^0.8.0",
"zhi-siyuan-api": "^2.19.1"
"zhi-siyuan-api": "^2.20.0"
},
"publishConfig": {
"access": "public"
Expand Down
3 changes: 2 additions & 1 deletion libs/zhi-siyuan-picgo/src/index.ts
Expand Up @@ -29,9 +29,10 @@ import { copyToClipboardInBrowser, generateUniqueName } from "./lib/utils/utils"
import { ImageItem } from "./lib/models/ImageItem"
import { ImageParser } from "./lib/parser/ImageParser"
import { ParsedImage } from "./lib/models/ParsedImage"
import { SIYUAN_PICGO_FILE_MAP_KEY } from "./lib/constants"

export { SiyuanPicGo, SiyuanPicgoConfig, SiyuanPicgoPostApi, PicgoHelper }
export { ImageItem, ImageParser, ParsedImage }
export { ImageItem, ImageParser, ParsedImage, SIYUAN_PICGO_FILE_MAP_KEY }
export { retrieveImageFromClipboardAsBlob, copyToClipboardInBrowser, calculateMD5, generateUniqueName }
export { ConfigDb, PluginLoaderDb, ExternalPicgoConfigDb }
export { PicgoTypeEnum }
Expand Down
3 changes: 1 addition & 2 deletions libs/zhi-siyuan-picgo/src/lib/siyuanPicgoPostApi.ts
Expand Up @@ -9,7 +9,7 @@

import { ILogger, simpleLogger } from "zhi-lib-base"
import { SiyuanPicGoUploadApi } from "./siyuanPicGoUploadApi"
import { hasNodeEnv, IPicGo, isFileOrBlob, win } from "universal-picgo"
import { hasNodeEnv, IImgInfo, IPicGo, isFileOrBlob, win } from "universal-picgo"
import { ParsedImage } from "./models/ParsedImage"
import { ImageItem } from "./models/ImageItem"
import { SIYUAN_PICGO_FILE_MAP_KEY } from "./constants"
Expand All @@ -18,7 +18,6 @@ import { SiyuanConfig, SiyuanKernelApi } from "zhi-siyuan-api"
import { ImageParser } from "./parser/ImageParser"
import { PicgoPostResult } from "./models/PicgoPostResult"
import { DeviceDetection, DeviceTypeEnum, SiyuanDevice } from "zhi-device"
import { IImgInfo } from "universal-picgo/src"

/**
* Picgo与文章交互的通用方法
Expand Down
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -3,6 +3,7 @@
"version": "1.6.0",
"description": "picgo plugin for siyuan-note",
"scripts": {
"clean": "./scripts/clean.sh",
"serve": "turbo run serve",
"dev": "turbo run dev",
"build": "turbo run build",
Expand Down
2 changes: 1 addition & 1 deletion packages/picgo-plugin-app/package.json
Expand Up @@ -36,7 +36,7 @@
"zhi-common": "^1.33.0",
"zhi-device": "^2.11.0",
"zhi-lib-base": "^0.8.0",
"zhi-siyuan-api": "^2.19.1",
"zhi-siyuan-api": "^2.20.0",
"zhi-siyuan-picgo": "workspace:*"
}
}
24 changes: 19 additions & 5 deletions packages/picgo-plugin-app/src/components/setting/PicgoSetting.vue
Expand Up @@ -9,7 +9,7 @@

<script setup lang="ts">
import { useVueI18n } from "$composables/useVueI18n.ts"
import { reactive } from "vue"
import { onBeforeMount, reactive } from "vue"
import { PicgoTypeEnum } from "zhi-siyuan-picgo"
import { useExternalPicGoSetting } from "@/stores/useExternalPicGoSetting.ts"
import { useBundledPicGoSetting } from "@/stores/useBundledPicGoSetting.ts"
Expand All @@ -28,23 +28,29 @@ const formData = reactive({
picgoTypeList: [
{
value: PicgoTypeEnum.Bundled,
label: t("upload.adaptor.bundled")
label: t("upload.adaptor.bundled"),
},
{
value: PicgoTypeEnum.App,
label: t("upload.adaptor.app")
}
label: t("upload.adaptor.app"),
},
// {
// value: PicgoTypeEnum.Core,
// label: t("upload.adaptor.core"),
// },
]
],
})

const handlePicgoTypeChange = (val: any) => {
const isBundled = val === PicgoTypeEnum.Bundled
externalPicGoSettingForm.value.useBundledPicgo = isBundled
}

onBeforeMount(() => {
// init siyuan related picgo config
bundledPicGoSettingForm.value.siyuan = bundledPicGoSettingForm.value.siyuan || {}
bundledPicGoSettingForm.value.siyuan.waitTimeout = bundledPicGoSettingForm.value.siyuan.waitTimeout || 10
})
</script>

<template>
Expand All @@ -65,6 +71,14 @@ const handlePicgoTypeChange = (val: any) => {
<div v-else>
<external-picgo-setting :cfg="externalPicGoSettingForm" />
</div>
<div>
<el-form-item :label="t('picgo.siyuan.wait.timeout')">
<el-input
v-model="bundledPicGoSettingForm.siyuan.waitTimeout"
:placeholder="t('picgo.siyuan.wait.timeout.tip')"
/>
</el-form-item>
</div>
</el-form>
</back-page>
</template>
Expand Down
Expand Up @@ -22,12 +22,12 @@ const { t } = useVueI18n()
const props = defineProps({
ctx: {
type: Object,
default: null
default: null,
},
cfg: {
type: Object,
default: null
}
default: null,
},
})

const formData = reactive({
Expand All @@ -50,13 +50,13 @@ const formData = reactive({
// 当前配置项表单
curFormPropertiesConfig: {} as IStringKeyMap,
// 表单配置项ID
curFormConfigId: "" as string | undefined
curFormConfigId: "" as string | undefined,
},

// 表单展示
isNewForm: false,
showConfigForm: false,
configFormTitle: ""
configFormTitle: "",
})
// PicGo 持久化操作帮助类
const picgoHelper = new PicgoHelper(props.ctx, formData.cfg)
Expand Down Expand Up @@ -152,7 +152,7 @@ function deleteConfig(config: IUploaderConfigListItem) {
ElMessageBox.confirm(`确认删除配置 ${config._configName} 吗?`, t("main.opt.warning"), {
confirmButtonText: t("main.opt.ok"),
cancelButtonText: t("main.opt.cancel"),
type: "warning"
type: "warning",
})
.then(async () => {
try {
Expand All @@ -162,12 +162,11 @@ function deleteConfig(config: IUploaderConfigListItem) {
} catch (e) {
ElMessage({
type: "error",
message: t("main.opt.failure") + "=>" + e
message: t("main.opt.failure") + "=>" + e,
})
}
})
.catch(() => {
})
.catch(() => {})
}

/**
Expand Down Expand Up @@ -238,7 +237,7 @@ onBeforeMount(() => {
:key="item.type"
:type="selectedPicbedStyle(item.type)"
@click="handlePicBedTypeChange(item)"
>{{ item.name }}
>{{ item.name }}
</el-button>
</el-button-group>
</div>
Expand Down Expand Up @@ -343,6 +342,10 @@ onBeforeMount(() => {
margin-top: 10px;
}

.picbed-group
button
margin-bottom 10px

.profile-card-item {
display: inline-block;
margin-right: 10px;
Expand Down
4 changes: 2 additions & 2 deletions packages/picgo-plugin-app/src/components/test/BrowserTest.vue

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions packages/picgo-plugin-app/src/components/test/ElectronTest.vue

Large diffs are not rendered by default.

Expand Up @@ -10,7 +10,7 @@
import { useSiyuanDevice } from "$composables/useSiyuanDevice.ts"
import { reactive } from "vue"
import { isDev } from "@/utils/Constants.ts"
import { ImageItem } from "zhi-siyuan-picgo/src/lib/models/ImageItem.ts"
import { ImageItem } from "zhi-siyuan-picgo"

/**
* Picgo公共组件
Expand Down
16 changes: 8 additions & 8 deletions packages/picgo-plugin-app/src/composables/usePicgoManage.ts
Expand Up @@ -12,7 +12,7 @@ import { useSiyuanApi } from "$composables/useSiyuanApi.ts"
import { createAppLogger } from "@/utils/appLogger.ts"
import { reactive } from "vue"
import { ElMessage, ElMessageBox } from "element-plus"
import { ImageItem } from "zhi-siyuan-picgo/src/lib/models/ImageItem.ts"
import { ImageItem } from "zhi-siyuan-picgo"
import { SiyuanPicGoClient } from "@/utils/SiyuanPicGoClient.ts"

/**
Expand All @@ -30,7 +30,7 @@ export const usePicgoManage = (props: any, deps: any) => {
// public data
const picgoManageData = reactive({
dialogImageUrl: "",
dialogPreviewVisible: false,
dialogPreviewVisible: false
})

// deps
Expand Down Expand Up @@ -86,7 +86,7 @@ export const usePicgoManage = (props: any, deps: any) => {
ElMessageBox.confirm("已经是远程图片,是否仍然覆盖上传?", t("main.opt.warning"), {
confirmButtonText: t("main.opt.ok"),
cancelButtonText: t("main.opt.cancel"),
type: "warning",
type: "warning"
})
.then(async () => {
try {
Expand All @@ -100,7 +100,7 @@ export const usePicgoManage = (props: any, deps: any) => {

ElMessage({
type: "error",
message: t("main.opt.failure") + "=>" + e,
message: t("main.opt.failure") + "=>" + e
})
logger.error(t("main.opt.failure") + "=>" + e)
}
Expand All @@ -111,7 +111,7 @@ export const usePicgoManage = (props: any, deps: any) => {
if (e.toString().indexOf("cancel") <= -1) {
ElMessage({
type: "error",
message: t("main.opt.failure") + ",图片上传异常=>" + e,
message: t("main.opt.failure") + ",图片上传异常=>" + e
})
logger.error(t("main.opt.failure") + "=>" + e)
}
Expand All @@ -127,7 +127,7 @@ export const usePicgoManage = (props: any, deps: any) => {

ElMessage({
type: "error",
message: t("main.opt.failure") + "=>" + e,
message: t("main.opt.failure") + "=>" + e
})
logger.error(t("main.opt.failure") + "=>" + e)
}
Expand Down Expand Up @@ -156,11 +156,11 @@ export const usePicgoManage = (props: any, deps: any) => {
handlePictureCardPreview: (url: string) => {
picgoManageData.dialogImageUrl = url ?? ""
picgoManageData.dialogPreviewVisible = true
},
}
}

return {
picgoManageData,
picgoManageMethods,
picgoManageMethods
}
}
3 changes: 1 addition & 2 deletions packages/picgo-plugin-app/src/composables/usePicgoUpload.ts
Expand Up @@ -11,12 +11,11 @@ import { useRouter } from "vue-router"
import { createAppLogger } from "@/utils/appLogger.ts"
import { useVueI18n } from "$composables/useVueI18n.ts"
import { reactive } from "vue"
import { ImageItem } from "zhi-siyuan-picgo"
import { generateUniqueName, ImageItem } from "zhi-siyuan-picgo"
import { ElMessage } from "element-plus"
import { useSiyuanApi } from "$composables/useSiyuanApi.ts"
import { StrUtil } from "zhi-common"
import { SiyuanPicGoClient } from "@/utils/SiyuanPicGoClient.ts"
import { generateUniqueName } from "zhi-siyuan-picgo/src"

/**
* Picgo上传组件
Expand Down
2 changes: 2 additions & 0 deletions packages/picgo-plugin-app/src/i18n/en_US.ts
Expand Up @@ -144,4 +144,6 @@ export default {
"The CORS proxy is essential for browsers and Docker environments. For further consultation, feel free to contact youweics@163.com.",
"upload.no.beds":
'No image hosting service is currently available. Kindly proceed to "Image Hosting Settings" to add a new image hosting service.',
"picgo.siyuan.wait.timeout": "Sync timeout(seconds)",
"picgo.siyuan.wait.timeout.tip": "Timeout when handle picbed sync",
}
2 changes: 2 additions & 0 deletions packages/picgo-plugin-app/src/i18n/zh_CN.ts
Expand Up @@ -138,4 +138,6 @@ export default {
"setting.cors.title": "CORS 代理",
"setting.cors.title.tip": "CORS 代理,浏览器、dcoker以及某些插件可能需要,可付费咨询 youweics@163.com",
"upload.no.beds": "暂无可用图床,请前往「图床设置」新增图床",
"picgo.siyuan.wait.timeout": "同步延迟(秒)",
"picgo.siyuan.wait.timeout.tip": "图床同步延迟时间,大于这个时间才会去同步图床元数据",
}