Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

snowtransfer

Package Overview
Dependencies
Maintainers
2
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

snowtransfer - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

2

dist/ratelimitBuckets/LocalBucket.d.ts

@@ -25,3 +25,3 @@ /**

/**
* Timeout that calls the reset function once the timeframe passed
* The Date time in which the bucket will reset
*/

@@ -28,0 +28,0 @@ resetAt: number | null;

@@ -81,13 +81,5 @@ /// <reference types="node" />

/**
* Calculate the time difference between the local server and discord
* @param dateHeader Date header value returned by discord
* @returns Offset in milliseconds
*/
private _getOffsetDateFromHeader;
/**
* Apply the received ratelimit headers to the ratelimit bucket
* @param bkt Ratelimit bucket to apply the headers to
* @param headers Http headers received from discord
* @param offsetDate Unix timestamp of the current date + offset to discord time
* @param reactions Whether to use reaction ratelimits (1/250ms)
*/

@@ -94,0 +86,0 @@ private _applyRatelimitHeaders;

@@ -87,3 +87,2 @@ "use strict";

const reqID = crypto_1.default.randomBytes(20).toString("hex");
const latency = Date.now();
try {

@@ -109,11 +108,7 @@ this.emit("request", reqID, { endpoint, method, dataType, data });

}
if (request.headers["date"]) {
this.latency = Date.now() - latency;
const offsetDate = this._getOffsetDateFromHeader(request.headers["date"]);
const match = endpoint.match(/\/reactions\//);
this._applyRatelimitHeaders(bkt, request.headers, offsetDate, !!match);
}
if (request.statusCode && [429, 502].includes(request.statusCode)) {
if (request.statusCode === 429)
if (request.statusCode === 429) {
this._applyRatelimitHeaders(bkt, request.headers);
this.emit("rateLimit", { timeout: bkt.reset, limit: bkt.limit, method: method, path: endpoint, route: this.ratelimiter.routify(endpoint, method) });
}
return this.request(endpoint, method, dataType, data, amount++);

@@ -146,32 +141,11 @@ }

/**
* Calculate the time difference between the local server and discord
* @param dateHeader Date header value returned by discord
* @returns Offset in milliseconds
*/
_getOffsetDateFromHeader(dateHeader) {
const discordDate = Date.parse(dateHeader);
const offset = Date.now() - discordDate;
return Date.now() + offset;
}
/**
* Apply the received ratelimit headers to the ratelimit bucket
* @param bkt Ratelimit bucket to apply the headers to
* @param headers Http headers received from discord
* @param offsetDate Unix timestamp of the current date + offset to discord time
* @param reactions Whether to use reaction ratelimits (1/250ms)
*/
_applyRatelimitHeaders(bkt, headers, offsetDate, reactions = false) {
_applyRatelimitHeaders(bkt, headers) {
if (headers["x-ratelimit-global"]) {
bkt.ratelimiter.global = true;
bkt.ratelimiter.globalResetAt = Date.now() + (parseFloat(headers["retry_after"]) * 1000);
bkt.ratelimiter.globalResetAt = Date.now() + (parseFloat(headers["retry-after"]) * 1000);
}
if (headers["x-ratelimit-reset"]) {
const reset = (headers["x-ratelimit-reset"] * 1000) - offsetDate;
if (reactions) {
bkt.reset = Math.max(reset, 250);
}
else {
bkt.reset = reset;
}
}
if (headers["x-ratelimit-remaining"]) {

@@ -188,2 +162,5 @@ bkt.remaining = parseInt(headers["x-ratelimit-remaining"]);

}
if (headers["retry-after"] && !headers["x-ratelimit-global"]) { // The ms precision is not strictly necessary. It always rounds up, which is safe.
bkt.resetAt = Date.now() + (parseInt(headers["retry-after"]) * 1000); // retry-after is in seconds.
}
}

@@ -190,0 +167,0 @@ /**

{
"name": "snowtransfer",
"version": "0.3.0",
"version": "0.3.1",
"description": "Minimalistic Rest client for the Discord Api",

@@ -5,0 +5,0 @@ "main": "./dist/index.js",

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc