refactor(rest): separate functions into diff files (#685)

* shtufffff

* fixe rate limit path infinite loop

* refactor

* ID > id

* Update process_request_headers.ts

* file names

Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>
Co-authored-by: ayntee <ayyantee@gmail.com>
This commit is contained in:
Skillz4Killz
2021-03-29 15:50:08 -04:00
committed by GitHub
parent 79d57f0377
commit ebb15afa0e
16 changed files with 444 additions and 708 deletions
+47
View File
@@ -0,0 +1,47 @@
import { checkRateLimits } from "./check_rate_limits.ts";
import { cleanupQueues } from "./cleanup_queues.ts";
import { createRequestBody } from "./create_request_body.ts";
import { handlePayload } from "./handle_payload.ts";
import { processQueue } from "./process_queue.ts";
import { processRateLimitedPaths } from "./process_rate_limited_paths.ts";
import { processRequest } from "./process_request.ts";
import { processRequestHeaders } from "./process_request_headers.ts";
import { RequestManager } from "./request_manager.ts";
import { runMethod } from "./run_method.ts";
export const rest: RestCache = {
/** The secret authorization key to confirm that this was a request made by you and not a DDOS attack. */
authorization: "discordeno_best_lib_ever",
pathQueues: new Map(),
processingQueue: false,
processingRateLimitedPaths: false,
globallyRateLimited: false,
ratelimitedPaths: new Map(),
eventHandlers: {
// BY DEFAULT WE WILL LOG ALL ERRORS TO CONSOLE. USER CAN CHOOSE TO OVERRIDE
error: function (_type, error) {
console.error(error);
},
// PLACEHOLDERS TO ALLOW USERS TO CUSTOMIZE
fetching() {},
fetched() {},
fetchSuccess() {},
fetchFailed() {},
globallyRateLimited() {},
retriesMaxed() {},
},
// TODO: add propeer docs dcomments
manager: RequestManager,
/** Handler function for every request. Converts to json, verified authorization & requirements and begins processing the request */
handlePayload,
checkRateLimits,
cleanupQueues,
processQueue,
processRateLimitedPaths,
processRequestHeaders,
processRequest,
createRequestBody,
runMethod,
};