mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
refactor!: remove deprecated CDN method overloads (#10649)
BREAKING CHANGE: Removed user avatar decoration overload from `CDN#avatarDecoration()` BREAKING CHANGE: Removed non-object options overload from `CDN#emoji()` Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
This commit is contained in:
@@ -30,10 +30,6 @@ test('avatar dynamic-not-animated', () => {
|
||||
expect(cdn.avatar(id, hash)).toEqual(`${baseCDN}/avatars/${id}/${hash}.webp`);
|
||||
});
|
||||
|
||||
test('avatar decoration default', () => {
|
||||
expect(cdn.avatarDecoration(id, hash)).toEqual(`${baseCDN}/avatar-decorations/${id}/${hash}.webp`);
|
||||
});
|
||||
|
||||
test('avatar decoration preset', () => {
|
||||
expect(cdn.avatarDecoration(hash)).toEqual(`${baseCDN}/avatar-decoration-presets/${hash}.png`);
|
||||
});
|
||||
|
||||
@@ -8,9 +8,6 @@ import {
|
||||
type ImageSize,
|
||||
type StickerExtension,
|
||||
} from './utils/constants.js';
|
||||
import { deprecationWarning } from './utils/utils.js';
|
||||
|
||||
let deprecationEmittedForEmoji = false;
|
||||
|
||||
/**
|
||||
* The options used for image URLs
|
||||
@@ -111,33 +108,8 @@ export class CDN {
|
||||
*
|
||||
* @param asset - The avatar decoration hash
|
||||
*/
|
||||
public avatarDecoration(asset: string): string;
|
||||
|
||||
/**
|
||||
* Generates a user avatar decoration URL.
|
||||
*
|
||||
* @deprecated This overload is deprecated. Pass a hash instead.
|
||||
* @param userId - The id of the user
|
||||
* @param userAvatarDecoration - The hash provided by Discord for this avatar decoration
|
||||
* @param options - Optional options for the avatar decoration
|
||||
*/
|
||||
public avatarDecoration(
|
||||
userId: string,
|
||||
userAvatarDecoration: string,
|
||||
// eslint-disable-next-line @typescript-eslint/unified-signatures
|
||||
options?: Readonly<BaseImageURLOptions>,
|
||||
): string;
|
||||
|
||||
public avatarDecoration(
|
||||
userIdOrAsset: string,
|
||||
userAvatarDecoration?: string,
|
||||
options?: Readonly<BaseImageURLOptions>,
|
||||
): string {
|
||||
if (userAvatarDecoration) {
|
||||
return this.makeURL(`/avatar-decorations/${userIdOrAsset}/${userAvatarDecoration}`, options);
|
||||
}
|
||||
|
||||
return this.makeURL(`/avatar-decoration-presets/${userIdOrAsset}`, { extension: 'png' });
|
||||
public avatarDecoration(asset: string): string {
|
||||
return this.makeURL(`/avatar-decoration-presets/${asset}`, { extension: 'png' });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -186,41 +158,13 @@ export class CDN {
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an emoji's URL for an emoji.
|
||||
* Generates an emoji's URL.
|
||||
*
|
||||
* @param emojiId - The emoji id
|
||||
* @param options - Optional options for the emoji
|
||||
*/
|
||||
public emoji(emojiId: string, options?: Readonly<BaseImageURLOptions>): string;
|
||||
|
||||
/**
|
||||
* Generates an emoji's URL for an emoji.
|
||||
*
|
||||
* @param emojiId - The emoji id
|
||||
* @param extension - The extension of the emoji
|
||||
* @deprecated This overload is deprecated. Pass an object containing the extension instead.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/unified-signatures
|
||||
public emoji(emojiId: string, extension?: ImageExtension): string;
|
||||
|
||||
public emoji(emojiId: string, options?: ImageExtension | Readonly<BaseImageURLOptions>): string {
|
||||
let resolvedOptions;
|
||||
|
||||
if (typeof options === 'string') {
|
||||
if (!deprecationEmittedForEmoji) {
|
||||
deprecationWarning(
|
||||
'Passing a string for the second parameter of CDN#emoji() is deprecated. Use an object instead.',
|
||||
);
|
||||
|
||||
deprecationEmittedForEmoji = true;
|
||||
}
|
||||
|
||||
resolvedOptions = { extension: options };
|
||||
} else {
|
||||
resolvedOptions = options;
|
||||
}
|
||||
|
||||
return this.makeURL(`/emojis/${emojiId}`, resolvedOptions);
|
||||
public emoji(emojiId: string, options?: Readonly<BaseImageURLOptions>): string {
|
||||
return this.makeURL(`/emojis/${emojiId}`, options);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -60,10 +60,3 @@ export const OverwrittenMimeTypes = {
|
||||
} as const satisfies Readonly<Record<string, string>>;
|
||||
|
||||
export const BurstHandlerMajorIdKey = 'burst';
|
||||
|
||||
/**
|
||||
* Prefix for deprecation warnings.
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
export const DEPRECATION_WARNING_PREFIX = 'DeprecationWarning' as const;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import type { RESTPatchAPIChannelJSONBody, Snowflake } from 'discord-api-types/v10';
|
||||
import type { REST } from '../REST.js';
|
||||
import { RateLimitError } from '../errors/RateLimitError.js';
|
||||
import { DEPRECATION_WARNING_PREFIX } from './constants.js';
|
||||
import { RequestMethod } from './types.js';
|
||||
import type { GetRateLimitOffsetFunction, RateLimitData, ResponseLike } from './types.js';
|
||||
|
||||
@@ -143,21 +142,6 @@ export function isBufferLike(value: unknown): value is ArrayBuffer | Buffer | Ui
|
||||
return value instanceof ArrayBuffer || value instanceof Uint8Array || value instanceof Uint8ClampedArray;
|
||||
}
|
||||
|
||||
/**
|
||||
* Irrespective environment warning.
|
||||
*
|
||||
* @remarks Only the message is needed. The deprecation prefix is handled already.
|
||||
* @param message - A string the warning will emit with
|
||||
* @internal
|
||||
*/
|
||||
export function deprecationWarning(message: string) {
|
||||
if (typeof globalThis.process === 'undefined') {
|
||||
console.warn(`${DEPRECATION_WARNING_PREFIX}: ${message}`);
|
||||
} else {
|
||||
process.emitWarning(message, DEPRECATION_WARNING_PREFIX);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes the offset for rate limits. Applies a Math.max(0, N) to prevent negative offsets,
|
||||
* also deals with callbacks.
|
||||
|
||||
Reference in New Issue
Block a user