fix mac os search error

This commit is contained in:
wanxp 2024-07-10 18:33:55 +08:00
parent a5747c2f45
commit d0ed8cf1f3
5 changed files with 27 additions and 7 deletions

@ -1,7 +1,7 @@
{
"id": "obsidian-douban-plugin",
"name": "Douban",
"version": "2.0.5",
"version": "2.0.6",
"minAppVersion": "0.12.0",
"description": "This is a plugin that can import movies/books/musics/notes/games info data from Douban for Obsidian .",
"author": "Wanxp",

@ -1,6 +1,6 @@
{
"name": "obsidian-douban-plugin",
"version": "2.0.5",
"version": "2.0.6",
"description": "This is a plugin for Obsidian (https://obsidian.md) that can import data from Douban (https://www.douban.com/).",
"main": "main.js",
"scripts": {

@ -5,6 +5,7 @@ import HttpUtil from "../../../../utils/HttpUtil";
import {log} from "../../../../utils/Logutil";
import {i18nHelper} from "../../../../lang/helper";
import {DoubanHttpUtil} from "../../../../utils/DoubanHttpUtil";
import {Platform} from "obsidian";
export abstract class AbstractSearchPageFetcher implements SearchPageFetcherInterface {
@ -19,7 +20,7 @@ export abstract class AbstractSearchPageFetcher implements SearchPageFetcherInte
}
fetch(keyword: string, pageNum: number, pageSize: number): Promise<string> {
const start:number = (pageNum - 1) * pageSize;
const url:string = this.getUrl(keyword, start, pageSize);
const url:string = this.getSearchUrl(keyword, start, pageSize);
if (!url) {
return Promise.resolve("");
}
@ -28,8 +29,18 @@ export abstract class AbstractSearchPageFetcher implements SearchPageFetcherInte
throw log.error(i18nHelper.getMessage('130101').replace('{0}', e.toString()), e);
}); }
getSearchUrl(keyword: string, start: number, pageSize: number):string {
keyword = keyword.trim();
if (keyword.length == 0) {
return "";
}
if (Platform.isMacOS) {
keyword = HttpUtil.encodeUrl(keyword);
}
return this.getUrl(keyword, start, pageSize)
}
abstract getUrl(keyword: string, start: number, pageSize: number):string;
}

@ -99,5 +99,14 @@ export default class HttpUtil {
return str;
}
/**
* url编码
* @param keyword
*/
static encodeUrl(keyword: string) {
if (!keyword) {
return '';
}
return encodeURIComponent(keyword);
}
}

@ -50,6 +50,6 @@
"2.0.2": "0.12.0",
"2.0.3": "0.12.0",
"2.0.4": "0.12.0",
"2.0.5": "0.12.0"
"2.0.5": "0.12.0",
"2.0.6": "0.12.0"
}