mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
refactor(rest): move user agent to constants
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { authorization, eventHandlers } from "../bot.ts";
|
import { authorization, eventHandlers } from "../bot.ts";
|
||||||
import { Errors, HttpResponseCode, RequestMethods } from "../types/types.ts";
|
import { Errors, HttpResponseCode, RequestMethods } from "../types/types.ts";
|
||||||
import { baseEndpoints, discordAPIURLS } from "../util/constants.ts";
|
import { API_VERSION, baseEndpoints, BASE_URL, IMAGE_BASE_URL, USER_AGENT } from "../util/constants.ts";
|
||||||
import { delay } from "../util/utils.ts";
|
import { delay } from "../util/utils.ts";
|
||||||
|
|
||||||
const pathQueues: { [key: string]: QueuedRequest[] } = {};
|
const pathQueues: { [key: string]: QueuedRequest[] } = {};
|
||||||
@@ -137,8 +137,7 @@ export const RequestManager = {
|
|||||||
function createRequestBody(body: any, method: RequestMethods) {
|
function createRequestBody(body: any, method: RequestMethods) {
|
||||||
const headers: { [key: string]: string } = {
|
const headers: { [key: string]: string } = {
|
||||||
Authorization: authorization,
|
Authorization: authorization,
|
||||||
"User-Agent":
|
"User-Agent": USER_AGENT,
|
||||||
`DiscordBot (https://github.com/skillz4killz/discordeno, v10)`,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (method === "get") body = undefined;
|
if (method === "get") body = undefined;
|
||||||
@@ -199,8 +198,8 @@ async function runMethod(
|
|||||||
|
|
||||||
// For proxies we don't need to do any of the legwork so we just forward the request
|
// For proxies we don't need to do any of the legwork so we just forward the request
|
||||||
if (
|
if (
|
||||||
!url.startsWith(discordAPIURLS.BASE_URL) &&
|
!url.startsWith(`${BASE_URL}/v${API_VERSION}`) &&
|
||||||
!url.startsWith(discordAPIURLS.CDN_URL)
|
!url.startsWith(IMAGE_BASE_URL)
|
||||||
) {
|
) {
|
||||||
return fetch(url, { method, body: body ? JSON.stringify(body) : undefined })
|
return fetch(url, { method, body: body ? JSON.stringify(body) : undefined })
|
||||||
.then((res) => res.json())
|
.then((res) => res.json())
|
||||||
|
|||||||
+13
-7
@@ -1,13 +1,19 @@
|
|||||||
// These will never be modified and remain constants
|
/** https://discord.com/developers/docs/reference#api-reference-base-url */
|
||||||
export const discordAPIURLS = {
|
export const BASE_URL = "https://discord.com/api";
|
||||||
BASE_URL: `https://discord.com/api/v8`,
|
|
||||||
CDN_URL: "https://cdn.discordapp.com",
|
/** https://discord.com/developers/docs/reference#api-versioning-api-versions */
|
||||||
};
|
export const API_VERSION = 8;
|
||||||
|
|
||||||
|
/** https://discord.com/developers/docs/reference#user-agent */
|
||||||
|
export const USER_AGENT = "DiscordBot (https://github.com/discordeno/discordeno, v10)";
|
||||||
|
|
||||||
|
/** https://discord.com/developers/docs/reference#image-formatting-image-base-url */
|
||||||
|
export const IMAGE_BASE_URL = "https://cdn.discordapp.com/";
|
||||||
|
|
||||||
// This can be modified by big brain bots and use a proxy
|
// This can be modified by big brain bots and use a proxy
|
||||||
export const baseEndpoints = {
|
export const baseEndpoints = {
|
||||||
BASE_URL: discordAPIURLS.BASE_URL,
|
BASE_URL: `${BASE_URL}/v${API_VERSION}`,
|
||||||
CDN_URL: discordAPIURLS.CDN_URL,
|
CDN_URL: IMAGE_BASE_URL,
|
||||||
};
|
};
|
||||||
|
|
||||||
const GUILDS_BASE = (id: string) => `${baseEndpoints.BASE_URL}/guilds/${id}`;
|
const GUILDS_BASE = (id: string) => `${baseEndpoints.BASE_URL}/guilds/${id}`;
|
||||||
|
|||||||
Reference in New Issue
Block a user