Skip to content

Commit

Permalink
fix(route): Pixiv频繁refresh token (DIYgod#8527)
Browse files Browse the repository at this point in the history
  • Loading branch information
yindaheng98 authored Nov 27, 2021
1 parent 23d709f commit 57a86c6
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions lib/routes/pixiv/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,27 @@ async function tickToken() {
}
}

module.exports = async () => {
if (!token) {
await tickToken();
let tickTokenStarted = false;

async function startTickToken() {
if (!tickTokenStarted) {
// 如果tickToken没启动
tickTokenStarted = true;
await tickToken(); // 启动tickToken
}
}

async function waitForToken() {
while (!token) {
// eslint-disable-next-line no-await-in-loop
await new Promise((resolve) => setTimeout(resolve, 0));
}
return token;
}

module.exports = async () => {
await startTickToken();
return waitForToken();
};

module.exports.tickToken = tickToken;

0 comments on commit 57a86c6

Please sign in to comment.