Skip to content

Commit

Permalink
fix(mt): fix mt refresh rate limited (#1938)
Browse files Browse the repository at this point in the history
* fix: mt refresh fails due to rate limiting

#1936

* change the delay from 8000 to 2100

* revert linter changes
  • Loading branch information
jiang925 authored Jul 5, 2024
1 parent b23ae94 commit 22cb222
Showing 1 changed file with 38 additions and 19 deletions.
57 changes: 38 additions & 19 deletions resource/sites/xp.m-team.cc/getUserSeedingTorrents.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
(function(options, User) {
class Parser {
static MAX_RETRIES = 2;
static RETRY_DELAY_MS = 2100;

constructor(options, dataURL) {
this.options = options;
this.dataURL = dataURL;
Expand Down Expand Up @@ -74,25 +77,41 @@
let postData = this.options.rule.requestData;
postData.pageNumber = this.pageInfo.current + 1;

$.ajax({
url,
method: "POST",
dataType: "JSON",
data: JSON.stringify(postData),
contentType: "application/json",
headers: this.options.rule.headers
})
.done(result => {
this.rawData = result;
if (this.rawData.data.data.length > 0) {
this.parse();
} else {
this.done();
}
})
.fail(() => {
this.done();
});
function makeRequest(retryCount = 0) {
setTimeout(() => {
$.ajax({
url,
method: "POST",
dataType: "JSON",
data: JSON.stringify(postData),
contentType: "application/json",
headers: this.options.rule.headers,
})
.done((result) => {
try {
this.rawData = result;
if (this.rawData.data.data.length > 0) {
this.parse();
} else {
this.done();
}
} catch (error) {
console.error("[mt] Error processing result:", error);
if (retryCount < Parser.MAX_RETRIES) {
makeRequest.call(this, retryCount + 1);
} else {
this.done();
}
}
})
.fail(() => {
this.done();
});
}, Parser.RETRY_DELAY_MS);
}

// Call the function for the first time
makeRequest.call(this);
}

/**
Expand Down

0 comments on commit 22cb222

Please sign in to comment.