Skip to content

Commit

Permalink
fix(getScriptContent): 目前的搜索容易超时报错 #2049
Browse files Browse the repository at this point in the history
  • Loading branch information
fzlins committed Nov 11, 2024
1 parent d0daff4 commit b3fd592
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
4 changes: 3 additions & 1 deletion src/background/pageParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,11 @@ export class PageParser {
if (script) {
eval(script);
} else {
APP.getScriptContent(path).done(script => {
APP.getScriptContent(path).then(script => {
this.infoParserCache[path] = script;
eval(script);
}).catch(error => {
console.error("Error loading script:", error);
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/background/searcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ export class Searcher {
if (!entry.parseScript) {
this.service.debug("searchTorrent: getScriptContent", scriptPath);
APP.getScriptContent(scriptPath)
.done((script: string) => {
.then((script: string) => {
this.service.debug(
"searchTorrent: getScriptContent done",
scriptPath
Expand Down Expand Up @@ -526,7 +526,7 @@ export class Searcher {
}
});
})
.fail(error => {
.catch(error => {
this.service.debug(
"searchTorrent: getScriptContent fail",
error
Expand Down
4 changes: 3 additions & 1 deletion src/background/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,11 @@ export class User {
if (script) {
eval(script);
} else {
APP.getScriptContent(path).done(script => {
APP.getScriptContent(path).then(script => {
this.infoParserCache[path] = script;
eval(script);
}).catch(error => {
console.error("Error loading script:", error);
});
}
}
Expand Down
36 changes: 23 additions & 13 deletions src/service/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,19 +261,29 @@ export const APP = {
* 异步获取脚本内容
* @param path 路径
*/
getScriptContent(path: string): JQueryXHR {
let url = `${API.host}/${path}`;
// 外部链接
if (path.substr(0, 4) === "http") {
url = path;
} else {
url = url.replace("resource//", "resource/");
}
APP.debugMode && console.log("getScriptContent", url);
return $.ajax({
url,
dataType: "text",
timeout: 60000 // Set timeout to 60 seconds (60000 milliseconds)
getScriptContent(path: string): Promise<string> {
return limit(() => {
return new Promise((resolve, reject) => {
let url = `${API.host}/${path}`;
// 外部链接
if (path.substr(0, 4) === "http") {
url = path;
} else {
url = url.replace("resource//", "resource/");
}
APP.debugMode && console.log("getScriptContent", url);
$.ajax({
url,
dataType: "text",
timeout: 30000 // Set timeout to 30 seconds (30000 milliseconds)
})
.done((result) => {
resolve(result);
})
.fail((jqXHR, status, text) => {
reject(status + ", " + text);
});
});
});
},
/**
Expand Down

0 comments on commit b3fd592

Please sign in to comment.