Skip to content

Commit

Permalink
feat: support replace link in dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
terwer committed Apr 18, 2024
1 parent de999fa commit 8717ce2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
19 changes: 18 additions & 1 deletion libs/zhi-siyuan-picgo/src/lib/siyuanPicgoPostApi.ts
Expand Up @@ -227,16 +227,20 @@ class SiyuanPicgoPostApi {
/**
* 上传单张图片到图床(当前图片单个上传,提供给外部调用)
*
* 注意:所有的图片上传都会走这个
*
* @param pageId 文章ID
* @param attrs 文章属性
* @param imageItem 图片信息
* @param forceUpload 强制上传
* @param ignoreReplaceLink 忽略替换链接
*/
public async uploadSingleImageToBed(
pageId: string,
attrs: any,
imageItem: ImageItem,
forceUpload?: boolean
forceUpload?: boolean,
ignoreReplaceLink = false
): Promise<void> {
const mapInfoStr = attrs[SIYUAN_PICGO_FILE_MAP_KEY] ?? "{}"
const fileMap = JsonUtil.safeParse<any>(mapInfoStr, {})
Expand Down Expand Up @@ -306,6 +310,19 @@ class SiyuanPicgoPostApi {
[SIYUAN_PICGO_FILE_MAP_KEY]: newFileMapStr,
})

//处理链接替换
if (!ignoreReplaceLink) {
// 不强制忽略则去查询配置
const ctx = this.ctx()
// 是否替换链接
const SIYUAN_REPLACE_LINK = ctx.getConfig("siyuan.replaceLink") ?? true
if (SIYUAN_REPLACE_LINK) {
this.logger.info("链接替换已开启,准备替换链接")
}
} else {
this.logger.info("当前是思源笔记剪切板模式上传,暂时忽略链接替换,后面使用轮询处理替换链接")
}

return imageJsonObj
}

Expand Down
6 changes: 3 additions & 3 deletions packages/picgo-plugin-app/src/i18n/zh_CN.ts
Expand Up @@ -71,9 +71,9 @@ export default {
"picgo.siyuan.tip": "您当前使用的是思源笔记PC客户端,PicGO已内置,只需配置即可",
"picgo.upload.status": "上传状态",
"picgo.upload.select.pic": "选择图片",
"picgo.upload.clipboard": "剪贴板图片",
"picgo.upload.onclick": "一键上传本地图片到图床",
"picgo.download.onclick": "一键下载远程图片到本地",
"picgo.upload.clipboard": "剪贴板上传",
"picgo.upload.onclick": "一键上传",
"picgo.download.onclick": "一键下载",
"picgo.download.local.to.bed": "上传本地图片到图床",
"picgo.download.bed.to.local": "下载远程图片到本地",
"picgo.pic.preview": "图片预览",
Expand Down
4 changes: 3 additions & 1 deletion packages/picgo-plugin-bootstrap/src/index.ts
Expand Up @@ -114,7 +114,9 @@ export default class PicgoPlugin extends Plugin {
// 每次都要最新
const attrs = await siyuanApi.getBlockAttrs(pageId)
const imageItem = new ImageItem(generateUniqueName(), file as any, true, "", "")
const imageJsonObj: any = await picgoPostApi.uploadSingleImageToBed(pageId, attrs, imageItem, true)
// !!注意
// 这里不替换,后面在替换
const imageJsonObj: any = await picgoPostApi.uploadSingleImageToBed(pageId, attrs, imageItem, true, true)

// 处理后续
if (imageJsonObj && imageJsonObj.length > 0) {
Expand Down

0 comments on commit 8717ce2

Please sign in to comment.