Skip to content

Commit

Permalink
Merge branch 'dev' of github.com:terwer/siyuan-plugin-picgo into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Nov 22, 2024
2 parents a1e1ba2 + 06a3bd1 commit bcaf4d0
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "1.11.0"
".": "1.11.4"
}
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
# Changelog

## [1.11.4](https://github.com/terwer/siyuan-plugin-picgo/compare/siyuan-plugin-picgo-v1.11.3...siyuan-plugin-picgo-v1.11.4) (2024-11-17)
### Bug Fixes
* copy file error in some cases ([bf56986](https://github.com/terwer/siyuan-plugin-picgo/commit/bf56986eca3f27e550aa7f3d2c854ec2071e51a6))
## [1.11.3](https://github.com/terwer/siyuan-plugin-picgo/compare/siyuan-plugin-picgo-v1.11.2...siyuan-plugin-picgo-v1.11.3) (2024-11-16)
* make siyuanpicgo singleton ([e493573](https://github.com/terwer/siyuan-plugin-picgo/commit/e493573f1cae7aaa683d31d59d13f6c25d54f070))
* move file error ([d949e50](https://github.com/terwer/siyuan-plugin-picgo/commit/d949e50b8a4d8b4330164079e97a89f3bb5474c4))
## [1.11.2](https://github.com/terwer/siyuan-plugin-picgo/compare/siyuan-plugin-picgo-v1.11.1...siyuan-plugin-picgo-v1.11.2) (2024-11-16)
## [1.11.1](https://github.com/terwer/siyuan-plugin-picgo/compare/siyuan-plugin-picgo-v1.11.0...siyuan-plugin-picgo-v1.11.1) (2024-11-16)
### Miscellaneous
* release 1.11.1 ([d797c34](https://github.com/terwer/siyuan-plugin-picgo/commit/d797c34071115196ae5009efab20e340c6e2eaa5))
## [1.11.0](https://github.com/terwer/siyuan-plugin-picgo/compare/siyuan-plugin-picgo-v1.10.2...siyuan-plugin-picgo-v1.11.0) (2024-06-04)
### Features
* [#21](https://github.com/terwer/siyuan-plugin-picgo/issues/21) support lsky pro 2.1+ ([c26415f](https://github.com/terwer/siyuan-plugin-picgo/commit/c26415f193c0c6db106aafebdceca03f4e5e43c8))
### Bug Fixes
* ci error ([959b697](https://github.com/terwer/siyuan-plugin-picgo/commit/959b697f2f1308e48f5268091e7d5087e3eed327))
* **deps:** bump @iconify/json from 2.2.203 to 2.2.216 ([2de98ae](https://github.com/terwer/siyuan-plugin-picgo/commit/2de98aebe3503d967b5b3e55ba9f6fee8635bed5))
* **deps:** bump @smithy/fetch-http-handler in /libs/universal-picgo-core ([4e3a3d5](https://github.com/terwer/siyuan-plugin-picgo/commit/4e3a3d5576927c1c4853e78a65f396f469359819))
Expand All @@ -14,7 +23,6 @@
* **deps:** bump mime from 2.6.0 to 4.0.3 in /libs/universal-picgo-core ([3f1808a](https://github.com/terwer/siyuan-plugin-picgo/commit/3f1808a425fe0e367a42b573eaf57e307a81aba0))
* **deps:** bump pnpm/action-setup from 2.2.4 to 4.0.0 ([505a17a](https://github.com/terwer/siyuan-plugin-picgo/commit/505a17a9449a9e42a4c7012996e1971d12afdf36))
* **deps:** bump unplugin-icons in /packages/picgo-plugin-app ([b59ec77](https://github.com/terwer/siyuan-plugin-picgo/commit/b59ec77a0a2d1f0884e11fdcabde0b244833029e))
### Miscellaneous
* **deps-dev:** bump unplugin-vue-components ([f8fad45](https://github.com/terwer/siyuan-plugin-picgo/commit/f8fad4505967ebcbf0ddd469559208cde673c82b))
* **deps-dev:** bump vite-plugin-node-polyfills ([4f66b19](https://github.com/terwer/siyuan-plugin-picgo/commit/4f66b19b168a297c033e013f0c01c20bb733d933))
## [1.10.2](https://github.com/terwer/siyuan-plugin-picgo/compare/siyuan-plugin-picgo-v1.10.1...siyuan-plugin-picgo-v1.10.2) (2024-04-23)
Expand Down
6 changes: 6 additions & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,18 @@ pnpm install
serve

```bash
pnpm build -F universal-picgo-store
pnpm build -F universal-picgo
pnpm build -F zhi-siyuan-picgo
pnpm serve -F picgo-plugin-app
```

dev

```bash
pnpm build -F universal-picgo-store
pnpm build -F universal-picgo
pnpm build -F zhi-siyuan-picgo
pnpm dev -F picgo-plugin-app
pnpm dev -F picgo-plugin-bootstrap
```
Expand Down
2 changes: 1 addition & 1 deletion libs/Universal-PicGo-Core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "universal-picgo",
"version": "1.11.0",
"version": "1.11.4",
"type": "module",
"description": "picgo lib for node, browser and electron",
"main": "./dist/index.js",
Expand Down
12 changes: 6 additions & 6 deletions libs/Universal-PicGo-Core/src/core/ExternalPicgo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ class ExternalPicgo {
if (input) {
for (const inputItem of input) {
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
this.logger.warn(`try to get path from blob => ${inputItem.path}`)
if (inputItem.path && inputItem.path.trim() !== "") {
newInput.push(inputItem.path)
} else {
this.logger.warn("blob path is empty, treat as clipboard image")
}
newInput.push(inputItem.path)
} else {
newInput.push(inputItem)
}
Expand All @@ -75,7 +75,7 @@ class ExternalPicgo {

let data
// 传递了路径,上传具体图片,否则上传剪贴板
if (input) {
if (input && input.length > 0) {
data = { list: input }
}

Expand Down
2 changes: 1 addition & 1 deletion libs/Universal-PicGo-Store/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "universal-picgo-store",
"version": "1.11.0",
"version": "1.11.4",
"type": "module",
"description": "For PicGo projects to write & read data from browser, node or electron",
"main": "./dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion libs/zhi-siyuan-picgo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zhi-siyuan-picgo",
"version": "1.11.0",
"version": "1.11.4",
"type": "module",
"description": "picgo lib for siyuan-note",
"main": "./dist/index.js",
Expand Down
44 changes: 37 additions & 7 deletions libs/zhi-siyuan-picgo/src/lib/siyuanPicgo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,47 @@

import { SiyuanPicgoPostApi } from "./siyuanPicgoPostApi"
import { SiyuanConfig, SiyuanKernelApi } from "zhi-siyuan-api"
import { ILogger, simpleLogger } from "zhi-lib-base"

/**
* 思源笔记 PicGo 实例
*/
class SiyuanPicGo {
private static logger: ILogger | null = null
private static siyuanApiInstance: SiyuanKernelApi | null = null
private static picgoInstance: SiyuanPicgoPostApi | null = null

public static async getInstance(siyuanConfig: SiyuanConfig, isDev?: boolean): Promise<SiyuanPicgoPostApi> {
return new Promise((resolve, _reject) => {
const siyuanApi = new SiyuanKernelApi(siyuanConfig)
const picgo = new SiyuanPicgoPostApi(siyuanConfig, isDev)
if (!this.logger) {
this.logger = simpleLogger("get-instance", "zhi-siyuan-picgo", isDev)
}

// 如果 siyuanApi 尚未创建,初始化它
if (!this.siyuanApiInstance) {
console.log("初始化 SiyuanKernelApi 实例")
this.siyuanApiInstance = new SiyuanKernelApi(siyuanConfig)
}

// 如果 picgo 尚未创建,初始化它
if (!this.picgoInstance) {
console.log("初始化 SiyuanPicgoPostApi 实例")
this.picgoInstance = new SiyuanPicgoPostApi(siyuanConfig, isDev)

// 异步检查配置迁移状态
await this.checkConfigMigration(this.siyuanApiInstance, this.picgoInstance)
}

// 返回已初始化的 picgo 实例
return this.picgoInstance
}

/**
* 检查 PicGo 配置迁移的状态
*/
private static async checkConfigMigration(siyuanApi: SiyuanKernelApi, picgo: SiyuanPicgoPostApi): Promise<void> {
return new Promise<void>((resolve) => {
let needUpdate = false

const checkConfig = () => {
if (picgo.cfgUpdating) {
needUpdate = true
Expand All @@ -28,20 +58,20 @@ class SiyuanPicGo {
timeout: 1000,
})
console.warn("检测到旧配置,正在迁移配置,请勿进行任何操作...")
setTimeout(checkConfig, 1000)
setTimeout(checkConfig, 1000) // 递归检查
} else {
if (needUpdate) {
siyuanApi.pushMsg({
msg: "PicGO 图床历史配置迁移完成",
timeout: 7000,
})
console.log("PicGO 图床历史配置迁移完成")
needUpdate = false
}
console.log("picgo instance is ready")
resolve(picgo)
console.log("PicGO 实例已就绪")
resolve()
}
}

checkConfig()
})
}
Expand Down
18 changes: 14 additions & 4 deletions libs/zhi-siyuan-picgo/src/lib/siyuanPicgoPostApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,13 +424,15 @@ class SiyuanPicgoPostApi {
// 存在旧文件采取迁移
this.cfgUpdating = true
this.logger.info(`will move ${from} to ${to}`)
// 目的地存在复制
try {
if (existTo) {
await this.copyFolder(from, to)
// 目的地存在复制
await this.copyFolder(from, to, true)
} else {
// 不存在移动过去
await fs.promises.rename(from, to)
// https://stackoverflow.com/a/76459661/4037224
// await fs.promises.rename(from, to)
await this.copyFolder(from, to)
}
} catch (e) {
this.logger.error(`move ${from} to ${to} failed: ${e}`)
Expand All @@ -439,10 +441,14 @@ class SiyuanPicgoPostApi {
}
}

private async copyFolder(from: string, to: string) {
private async copyFolder(from: string, to: string, overwrite: boolean = false): Promise<any> {
const fs = win.fs
const path = win.require("path")

if (overwrite) {
await fs.promises.rmdir(to, { recursive: true })
}

const files = await fs.promises.readdir(from)
for (const file of files) {
if (file.startsWith(".")) {
Expand All @@ -457,6 +463,10 @@ class SiyuanPicgoPostApi {
// 递归复制子文件夹
await this.copyFolder(sourcePath, destPath)
} else {
const destDir = path.dirname(destPath)
if (!fs.existsSync(destDir)) {
await fs.promises.mkdir(destDir, { recursive: true })
}
await fs.promises.copyFile(sourcePath, destPath)
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "siyuan-plugin-picgo",
"version": "1.11.0",
"version": "1.11.4",
"description": "picgo plugin for siyuan-note",
"scripts": {
"clean": "./scripts/clean.sh",
Expand Down
2 changes: 1 addition & 1 deletion packages/picgo-plugin-app/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "picgo-plugin-app",
"private": true,
"version": "1.11.0",
"version": "1.11.4",
"type": "module",
"scripts": {
"serve": "python -u scripts/serve.py && vite",
Expand Down
2 changes: 1 addition & 1 deletion packages/picgo-plugin-bootstrap/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "picgo-plugin-bootstrap",
"version": "1.11.0",
"version": "1.11.4",
"description": "plugin bootstrap for siyuan-note",
"type": "module",
"repository": "terwer/siyuan-plugin-bootstrap",
Expand Down
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "siyuan-plugin-picgo",
"author": "terwer",
"url": "https://github.com/terwer/siyuan-plugin-picgo",
"version": "1.11.0",
"version": "1.11.4",
"minAppVersion": "2.9.0",
"backends": [
"windows",
Expand Down

0 comments on commit bcaf4d0

Please sign in to comment.