mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 08:47:22 +00:00
feat(rest): add isProxied (#2957)
Adds the `isProxied` property to rest.
This effectively removes the `startWith('https://discord.com/api')` check.
This commit is contained in:
@@ -62,11 +62,14 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage
|
||||
)
|
||||
}
|
||||
|
||||
const baseUrl = options.proxy?.baseUrl ?? 'https://discord.com/api'
|
||||
|
||||
const rest: RestManager = {
|
||||
token: options.token,
|
||||
applicationId,
|
||||
version: options.version ?? 10,
|
||||
baseUrl: options.proxy?.baseUrl ?? 'https://discord.com/api',
|
||||
baseUrl,
|
||||
isProxied: !baseUrl.startsWith('https://discord.com/api'),
|
||||
maxRetryCount: Infinity,
|
||||
globallyRateLimited: false,
|
||||
processingRateLimitedPaths: false,
|
||||
@@ -396,8 +399,8 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage
|
||||
},
|
||||
|
||||
async makeRequest(method, route, options) {
|
||||
if (!rest.baseUrl.startsWith('https://discord.com') && route[0] === '/') {
|
||||
const result = await fetch(`${rest.baseUrl}${route}`, rest.createRequestBody(method, options))
|
||||
if (rest.isProxied) {
|
||||
const result = await fetch(`${rest.baseUrl}/v${rest.version}${route}`, rest.createRequestBody(method, options))
|
||||
|
||||
if (!result.ok) {
|
||||
const err = (await result.json().catch(() => {})) as Record<string, any>
|
||||
|
||||
@@ -136,6 +136,12 @@ export interface RestManager {
|
||||
* @default https://discord.com/api
|
||||
*/
|
||||
baseUrl: string
|
||||
/**
|
||||
* `true` if the `baseUrl` does not start with `https://discord.com/api`.
|
||||
*
|
||||
* Mostly used only for intern functions.
|
||||
*/
|
||||
isProxied: boolean
|
||||
/** The authorization header to attach when sending requests to the proxy. */
|
||||
authorization?: string
|
||||
/** The maximum amount of times a request should be retried. Defaults to Infinity */
|
||||
|
||||
Reference in New Issue
Block a user