chore: drop query strings from file URL generation

This commit is contained in:
Paul Makles
2024-12-23 22:01:53 +00:00
parent 856ec34a04
commit 692e49c84a
7 changed files with 15 additions and 62 deletions
+2 -14
View File
@@ -307,26 +307,14 @@ export class Channel {
* URL to the channel icon
*/
get iconURL() {
return (
this.icon?.createFileURL({ max_side: 256 }) ?? this.recipient?.avatarURL
);
}
/**
* URL to a small variant of the channel icon
*/
get smallIconURL() {
return this.icon?.createFileURL({ max_side: 64 });
return this.icon?.createFileURL() ?? this.recipient?.avatarURL;
}
/**
* URL to the animated channel icon
*/
get animatedIconURL() {
return (
this.icon?.createFileURL({ max_side: 256 }, true) ??
this.recipient?.animatedAvatarURL
);
return this.icon?.createFileURL(true) ?? this.recipient?.animatedAvatarURL;
}
/**
+1 -1
View File
@@ -45,7 +45,7 @@ export class ChannelWebhook {
get avatarURL() {
return this.#collection
.getUnderlyingObject(this.id)
.avatar?.createFileURL({ max_side: 256 });
.avatar?.createFileURL();
}
/**
+4 -29
View File
@@ -98,41 +98,16 @@ export class File {
/**
* Creates a URL to a given file with given options.
* @param options Optional query parameters to modify object
* @param allowAnimation Returns GIF if applicable, no operations occur on image
* @param forceAnimation Returns GIF if applicable (for avatars/icons)
* @returns Generated URL or nothing
*/
createFileURL(
options?: {
max_side?: number;
size?: number;
width?: number;
height?: number;
},
allowAnimation?: boolean
) {
createFileURL(forceAnimation?: boolean) {
const autumn = this.#client.configuration?.features.autumn;
if (!autumn?.enabled) return;
// TODO: server-side
if (this.metadata?.type === "Image") {
if (
Math.min(this.metadata.width, this.metadata.height) <= 0 ||
(this.contentType === "image/gif" &&
Math.max(this.metadata.width, this.metadata.height) >= 4096)
)
return;
}
let query = "";
if (options) {
if (!allowAnimation || this.contentType !== "image/gif") {
query =
"?" +
Object.keys(options)
.map((k) => `${k}=${options[k as keyof typeof options]}`)
.join("&");
}
if (forceAnimation && this.contentType === "image/gif") {
query = "/original";
}
return `${autumn.url}/${this.tag}/${this.id}${query}`;
+1 -1
View File
@@ -380,7 +380,7 @@ export class MessageWebhook {
*/
get avatarURL() {
return (
this.avatar?.createFileURL({ max_side: 256 }) ??
this.avatar?.createFileURL() ??
`${this.#client.options.baseURL}/users/${this.id}/default_avatar`
);
}
+3 -3
View File
@@ -285,21 +285,21 @@ export class Server {
* URL to the server's icon
*/
get iconURL() {
return this.icon?.createFileURL({ max_side: 256 });
return this.icon?.createFileURL();
}
/**
* URL to the server's animated icon
*/
get animatedIconURL() {
return this.icon?.createFileURL({ max_side: 256 }, true);
return this.icon?.createFileURL(true);
}
/**
* URL to the server's banner
*/
get bannerURL() {
return this.banner?.createFileURL({ max_side: 256 }, true);
return this.banner?.createFileURL();
}
/**
+2 -7
View File
@@ -207,19 +207,14 @@ export class ServerMember {
* URL to the member's avatar
*/
get avatarURL() {
return (
this.avatar?.createFileURL({ max_side: 256 }) ?? this.user?.avatarURL
);
return this.avatar?.createFileURL() ?? this.user?.avatarURL;
}
/**
* URL to the member's animated avatar
*/
get animatedAvatarURL() {
return (
this.avatar?.createFileURL({ max_side: 256 }, true) ??
this.user?.animatedAvatarURL
);
return this.avatar?.createFileURL(true) ?? this.user?.animatedAvatarURL;
}
/**
+2 -7
View File
@@ -147,19 +147,14 @@ export class User {
* URL to the user's avatar
*/
get avatarURL() {
return (
this.avatar?.createFileURL({ max_side: 256 }) ?? this.defaultAvatarURL
);
return this.avatar?.createFileURL() ?? this.defaultAvatarURL;
}
/**
* URL to the user's animated avatar
*/
get animatedAvatarURL() {
return (
this.avatar?.createFileURL({ max_side: 256 }, true) ??
this.defaultAvatarURL
);
return this.avatar?.createFileURL(true) ?? this.defaultAvatarURL;
}
/**