Skip to content

Commit

Permalink
Merge pull request #2 from fakerepic/main
Browse files Browse the repository at this point in the history
fix: infinite loop when refreshing access token
  • Loading branch information
chris-lsn authored Jan 28, 2024
2 parents a2059e3 + ed1c653 commit 7c34292
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/pkgs/pikpak.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ export default class PikPak {
return this.refreshToken;
}

private async getHeaders() {
private async getHeaders(authRequired = true) {
const headers: Record<string, string> = {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36",
"Content-Type": "application/json; charset=utf-8",
};

if (this.accessToken) {
if (authRequired && this.accessToken) {
// check if access token is expired
const deocdedJwt = jwtDecode(this.accessToken);
const exp = deocdedJwt.exp;
Expand Down Expand Up @@ -107,7 +107,7 @@ export default class PikPak {
const refreshResponse = await fetch(refreshUrl, {
method: "POST",
body: JSON.stringify(refreshData),
headers: await this.getHeaders(),
headers: await this.getHeaders(false),
});

if (!refreshResponse.ok) {
Expand Down

0 comments on commit 7c34292

Please sign in to comment.