Skip to content

Commit

Permalink
Fix cdn error
Browse files Browse the repository at this point in the history
  • Loading branch information
denoflionsx committed Jul 7, 2022
1 parent 4fafb29 commit 175e0f6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
22 changes: 15 additions & 7 deletions src/Z64Online/common/cdn/CDNClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,22 @@ export class CDNClient {
var fetchUrl = require("fetch").fetchUrl;

fetchUrl(packet.url, (error: any, meta: any, body: any) => {
if (this.pendingDownloads.has(packet.model_id)) {
this.ModLoader.utils.setTimeoutFrames(() => {
let _zip = new zip(body);
let data = _zip.getEntry(packet.model_id)!.getData();
this.cache.set(packet.model_id, data);
this.pendingDownloads.get(packet.model_id)!.resolve(data);
if (error){
this.ModLoader.logger.error(error);
if (this.pendingDownloads.has(packet.model_id)) {
this.pendingDownloads.get(packet.model_id)!.reject("Failed to connect to backend!");
this.pendingDownloads.delete(packet.model_id);
}, 1);
}
}else{
if (this.pendingDownloads.has(packet.model_id)) {
this.ModLoader.utils.setTimeoutFrames(() => {
let _zip = new zip(body);
let data = _zip.getEntry(packet.model_id)!.getData();
this.cache.set(packet.model_id, data);
this.pendingDownloads.get(packet.model_id)!.resolve(data);
this.pendingDownloads.delete(packet.model_id);
}, 1);
}
}
});
}
Expand Down
6 changes: 5 additions & 1 deletion src/Z64Online/common/cdn/CDNThread.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,11 @@ class CDNThread {
let resp = new CDNFileDownload_Packet(packet.model_id);
resp.player = packet.player;
let port = this.config.reverseProxy ? this.config.reverseProxyPort.toString() : this.config.port.toString();
resp.url = `${this.config.url}:${port}/cdn/files/` + packet.model_id + ".zip";
if (port === "80") {
resp.url = `${this.config.url}/cdn/files/` + packet.model_id + ".zip";
} else {
resp.url = `${this.config.url}:${port}/cdn/files/` + packet.model_id + ".zip";
}
if (!this.knownFiles.has(packet.model_id)) {
resp.error = true;
}
Expand Down

0 comments on commit 175e0f6

Please sign in to comment.