From 8a7f70a29db9b8d809b6d2a45dfa14000b03ca0a Mon Sep 17 00:00:00 2001 From: Yimien <42413155+Yimien@users.noreply.github.com> Date: Fri, 19 Apr 2024 19:37:34 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=BC=E5=AE=B9=E6=96=B0=E7=9A=84=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E4=B8=8B=E8=BD=BD=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 6 ++++++ plugin.json | 2 +- src/apis/memosApi.ts | 9 +++++++++ src/constant.ts | 3 ++- src/index.ts | 18 ++++++++++++++---- 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cb4bd2..af69c2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## v0.2.2 + +### 修复 + +1. 修复兼容新的资源下载模式 + ## v0.2.1 ### 新功能 diff --git a/plugin.json b/plugin.json index 53a7945..76f9820 100644 --- a/plugin.json +++ b/plugin.json @@ -2,7 +2,7 @@ "name": "plugin-memos-sync", "author": "Yimien", "url": "https://github.com/Yimien/plugin-memos-sync", - "version": "0.2.1", + "version": "0.2.2", "minAppVersion": "2.11.3", "backends": [ "all" diff --git a/src/apis/memosApi.ts b/src/apis/memosApi.ts index c059519..683e26f 100644 --- a/src/apis/memosApi.ts +++ b/src/apis/memosApi.ts @@ -101,4 +101,13 @@ export class MemosApi { async downloadResourceByName(name){ return await this.fetchGet(`/o/r/${name}`); } + + /** + * 根据UID下载资源 + * @param id - 资源ID + * @returns + */ + async downloadResourceByUid(uId){ + return await this.fetchGet(`/o/r/${uId}`); + } } \ No newline at end of file diff --git a/src/constant.ts b/src/constant.ts index 4d6ab12..d1f9c52 100644 --- a/src/constant.ts +++ b/src/constant.ts @@ -27,7 +27,8 @@ export const sMaps = { // RESOURCE_DOWNLOAD_MODE: { first: '1', - second: '2' + second: '2', + third: '3' }, // 标签匹配范围 diff --git a/src/index.ts b/src/index.ts index f53b25c..cb77c5a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -605,6 +605,7 @@ export default class MemosSync extends Plugin { let resourceFilename = resource.filename; // 资源文件名称 let resourceName = resource.name; // 资源名称 let resourceId = resource.id; // 资源ID + let resourceUid = resource.uid; // 资源UID // 变量定义 let link: string; @@ -647,6 +648,7 @@ export default class MemosSync extends Plugin { mdLink: mdLink, downloadLink: downloadLink, resourceId: resourceId, + resourceUid: resourceUid, resourceTypeText: resourceTypeText, resourceName: resourceName }; @@ -774,7 +776,11 @@ export default class MemosSync extends Plugin { } else if (resourceDownloadMode === sMaps.RESOURCE_DOWNLOAD_MODE.second) { let resourceName = res.resourceName; response = await this.memosService.downloadResourceByName(resourceName); - } else { + } else if (resourceDownloadMode === sMaps.RESOURCE_DOWNLOAD_MODE.third) { + let resourceUid = res.resourceUid; + response = await this.memosService.downloadResourceByName(resourceUid); + } + else { return; } @@ -1980,18 +1986,22 @@ export default class MemosSync extends Plugin { // 资源下载方式 this.setting.addItem({ title: "资源下载模式", - description: "当资源(图片)无法正确显示或下载时请选择使用第二种模式", + description: "当资源(图片)无法正确显示或下载时请选择切换其它模式", createActionElement: () => { resourceDownloadModeElement = document.createElement('select') resourceDownloadModeElement.className = "b3-select fn__flex-center fn__size200"; let options = [ { val: sMaps.RESOURCE_DOWNLOAD_MODE.first, - text: "第一种" + text: "根据资源id" }, { val: sMaps.RESOURCE_DOWNLOAD_MODE.second, - text: "第二种" + text: "根据资源名称" + }, + { + val: sMaps.RESOURCE_DOWNLOAD_MODE.third, + text: "根据资源uid" } ] for (let option of options) {