Skip to content

Commit

Permalink
Fix bugs in HttpService and bump version number
Browse files Browse the repository at this point in the history
Closes #10
Closes #11
  • Loading branch information
Ecks1337 committed Sep 10, 2022
1 parent 8cc5448 commit 666204f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 24 deletions.
3 changes: 0 additions & 3 deletions .github/ISSUE_TEMPLATE/bug_report.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ Steps to reproduce the behavior:
**Expected behavior**
A clear and concise description of what you expected to happen.

**Did you use a fitgirl repack to install Ryujinx?**
[Yes/no]

**Screenshots**
Add screenshots to help explain your problem. Even if it seems irrelevant, it may help.

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "RyuSAK",
"productName": "RyuSAK",
"version": "1.4.1",
"version": "1.4.3",
"description": "RyuSAK",
"repository": "https://github.com/Ecks1337/RyuSAK",
"main": ".webpack/main",
Expand Down
51 changes: 31 additions & 20 deletions src/main/services/HttpService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ class HttpService {
}

protected fetch(url: string, req: RequestInit = { }) {
req.agent ??= this.httpsAgent;
req.headers = {
...req.headers,
"User-Agent": USER_AGENT
"User-Agent": USER_AGENT,
...req.headers
};

return fetch(url, req);
Expand All @@ -85,11 +86,7 @@ class HttpService {
const url = new URL(path, CDN_URL);
return pRetry(
async () => {
const response = await this.fetch(url.href, {
agent: url.protocol == "https:"
? this.httpsAgent
: this.httpAgent
});
const response = await this.fetch(url.href);

if (response.status >= 400) {
throw new pRetry.AbortError(response.statusText);
Expand All @@ -112,7 +109,6 @@ class HttpService {
public async post(path: string, body: BodyInit, headers: HeadersInit = null) {
const url = new URL(path, CDN_URL);
return this.fetch(url.href, {
agent: this.httpsAgent,
method: "POST",
body,
headers
Expand All @@ -133,8 +129,7 @@ class HttpService {
const controller = new AbortController();

const response = await this.fetch(url.href, {
signal: controller.signal,
agent: this.httpsAgent
signal: controller.signal
});

let chunkLength = 0;
Expand Down Expand Up @@ -182,11 +177,14 @@ class HttpService {
}

public async getThreshold() {
return this.get(HTTP_PATHS.THRESHOLD, "TXT").catch(() => -1) as Promise<number>;
return this.get(HTTP_PATHS.THRESHOLD, "TXT")
.then(threshold => Number(threshold))
.catch(() => -1) as Promise<number>;
}

public async getShadersMinVersion() {
return this.get(HTTP_PATHS.SHADERS_MIN_VER, "TXT") as Promise<number>;
return this.get(HTTP_PATHS.SHADERS_MIN_VER, "TXT")
.then(ver => Number(ver)) as Promise<number>;
}

public async getFirmwareVersion() {
Expand All @@ -198,9 +196,7 @@ class HttpService {

public async getLatestApplicationVersion() {
// Do not use this.get because we do not want exponential backoff strategy since GitHub api is limited to 10 requests per minute for unauthenticated requests
const response = await this.fetch(OTHER_URLS.RELEASE_INFO, {
agent: this.httpsAgent
});
const response = await this.fetch(OTHER_URLS.RELEASE_INFO);

if (response.status != 200) {
return app.getVersion();
Expand All @@ -212,8 +208,24 @@ class HttpService {
return tagName.replace("v", "");
}

public async downloadKeys() {
return this.get(OTHER_URLS.KEYS, "TXT") as Promise<string>;
public async downloadKeys(retries = 3) {
return pRetry(
async () => {
const response = await this.fetch(OTHER_URLS.KEYS, {
agent: this.httpAgent,
headers: {
"User-Agent": "node-fetch"
}
});

if (response.status >= 400) {
throw new pRetry.AbortError(response.statusText);
}

return response.text();
},
{ retries }
)
}

public async downloadEshopData() {
Expand All @@ -222,9 +234,8 @@ class HttpService {

public async getRyujinxCompatibility(query: string) {
// Do not use this.get because we do not want exponential backoff strategy since GitHub api is limited to 10 requests per minute for unauthenticated requests
return this.fetch(OTHER_URLS.COMPAT_LIST.replace("{query}", query), {
agent: this.httpsAgent
}).then(r => r.json()) as Promise<GithubIssue>;
return this.fetch(OTHER_URLS.COMPAT_LIST.replace("{query}", query))
.then(r => r.json()) as Promise<GithubIssue>;
}

public async getModVersions(titleId: string) {
Expand Down

0 comments on commit 666204f

Please sign in to comment.