Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Commit

Permalink
兼容新的资源下载模式
Browse files Browse the repository at this point in the history
  • Loading branch information
Yimien committed Apr 19, 2024
1 parent ed83924 commit 8a7f70a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v0.2.2

### 修复

1. 修复兼容新的资源下载模式

## v0.2.1

### 新功能
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": "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"
Expand Down
9 changes: 9 additions & 0 deletions src/apis/memosApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
}
3 changes: 2 additions & 1 deletion src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ export const sMaps = {
//
RESOURCE_DOWNLOAD_MODE: {
first: '1',
second: '2'
second: '2',
third: '3'
},

// 标签匹配范围
Expand Down
18 changes: 14 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -647,6 +648,7 @@ export default class MemosSync extends Plugin {
mdLink: mdLink,
downloadLink: downloadLink,
resourceId: resourceId,
resourceUid: resourceUid,
resourceTypeText: resourceTypeText,
resourceName: resourceName
};
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 8a7f70a

Please sign in to comment.