Skip to content

Commit

Permalink
Fix Discord poster no longer getting headers for some reason
Browse files Browse the repository at this point in the history
How did this ever work?!?!?!
  • Loading branch information
BOLL7708 committed Jun 19, 2024
1 parent a83aa26 commit d0c9a50
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions app/src/Shared/Utils/DiscordUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,19 @@ export default class DiscordUtils {
method: 'post',
body: item.data
}
const response: Response = await fetch(url, options)
const response: Response = await fetch(`${url}?wait=true`, options)
if(response == null) {
console.warn('Discord: Catastrophic Failure', url, item.data)
return EResponseState.Skip
}
const headers: IDiscordResponseHeaders = {}

for(const [key, header] of Object.entries(response.headers)) {
headers[key] = header
}
if(headers['x-ratelimit-global']) {
console.warn('Discord: ratelimit was global, this is unexpected as it usually means the server is in a bad standing!', url, item.data, headers)
if(response.headers.get('x-ratelimit-global')) {
console.warn('Discord: ratelimit was global, this is unexpected as it usually means the server is in a bad standing!', url, item.data, response.headers.entries())
}
const bucket = headers["x-ratelimit-bucket"]
const bucket = response.headers.get("x-ratelimit-bucket")
if(bucket) {
if(!this._rateLimitBuckets.hasOwnProperty(url)) this._rateLimitBuckets[url] = bucket
const remaining = Utils.ensureNumber(headers["x-ratelimit-remaining"], 0)
const reset = Utils.ensureNumber(headers["x-ratelimit-reset"], 0)
const remaining = Utils.ensureNumber(response.headers.get("x-ratelimit-remaining"), 0)
const reset = Utils.ensureNumber(response.headers.get("x-ratelimit-reset"), 0)
if(response.ok) {
const resetTimestamp = reset * 1000
this._rateLimits[bucket] = {remaining: remaining, resetTimestamp: resetTimestamp}
Expand Down

0 comments on commit d0c9a50

Please sign in to comment.