mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
refactor(CDN)!: Use an object for the constructor (#10978)
BREAKING CHANGE: The CDN class requires an object to construct.
This commit is contained in:
@@ -8,7 +8,7 @@ const hash = 'abcdef';
|
|||||||
const animatedHash = 'a_bcdef';
|
const animatedHash = 'a_bcdef';
|
||||||
const defaultAvatar = 1_234 % 5;
|
const defaultAvatar = 1_234 % 5;
|
||||||
|
|
||||||
const cdn = new CDN(baseCDN, baseMedia);
|
const cdn = new CDN({ cdn: baseCDN, mediaProxy: baseMedia });
|
||||||
|
|
||||||
test('appAsset default', () => {
|
test('appAsset default', () => {
|
||||||
expect(cdn.appAsset(id, hash)).toEqual(`${baseCDN}/app-assets/${id}/${hash}.webp`);
|
expect(cdn.appAsset(id, hash)).toEqual(`${baseCDN}/app-assets/${id}/${hash}.webp`);
|
||||||
|
|||||||
@@ -83,14 +83,36 @@ interface MakeURLOptions {
|
|||||||
size?: ImageSize;
|
size?: ImageSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options for initializing the {@link CDN} class.
|
||||||
|
*/
|
||||||
|
export interface CDNOptions {
|
||||||
|
/**
|
||||||
|
* The base URL for the CDN.
|
||||||
|
*
|
||||||
|
* @defaultValue `DefaultRestOptions.cdn`
|
||||||
|
*/
|
||||||
|
cdn?: string | undefined;
|
||||||
|
/**
|
||||||
|
* The base URL for the media proxy.
|
||||||
|
*
|
||||||
|
* @defaultValue `DefaultRestOptions.mediaProxy`
|
||||||
|
*/
|
||||||
|
mediaProxy?: string | undefined;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The CDN link builder
|
* The CDN link builder
|
||||||
*/
|
*/
|
||||||
export class CDN {
|
export class CDN {
|
||||||
public constructor(
|
private readonly cdn: string;
|
||||||
private readonly cdn: string = DefaultRestOptions.cdn,
|
|
||||||
private readonly mediaProxy: string = DefaultRestOptions.mediaProxy,
|
private readonly mediaProxy: string;
|
||||||
) {}
|
|
||||||
|
public constructor({ cdn, mediaProxy }: CDNOptions = {}) {
|
||||||
|
this.cdn = cdn ?? DefaultRestOptions.cdn;
|
||||||
|
this.mediaProxy = mediaProxy ?? DefaultRestOptions.mediaProxy;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates an app asset URL for a client's asset.
|
* Generates an app asset URL for a client's asset.
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ export class REST extends AsyncEventEmitter<RestEvents> {
|
|||||||
|
|
||||||
public constructor(options: Partial<RESTOptions> = {}) {
|
public constructor(options: Partial<RESTOptions> = {}) {
|
||||||
super();
|
super();
|
||||||
this.cdn = new CDN(options.cdn ?? DefaultRestOptions.cdn, options.mediaProxy ?? DefaultRestOptions.mediaProxy);
|
this.cdn = new CDN(options);
|
||||||
this.options = { ...DefaultRestOptions, ...options };
|
this.options = { ...DefaultRestOptions, ...options };
|
||||||
this.globalRemaining = Math.max(1, this.options.globalRequestsPerSecond);
|
this.globalRemaining = Math.max(1, this.options.globalRequestsPerSecond);
|
||||||
this.agent = options.agent ?? null;
|
this.agent = options.agent ?? null;
|
||||||
|
|||||||
Reference in New Issue
Block a user