mirror of
https://github.com/stoatchat/javascript-client-sdk.git
synced 2026-07-19 17:13:31 -04:00
chore: drop query strings from file URL generation
This commit is contained in:
+2
-14
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -45,7 +45,7 @@ export class ChannelWebhook {
|
||||
get avatarURL() {
|
||||
return this.#collection
|
||||
.getUnderlyingObject(this.id)
|
||||
.avatar?.createFileURL({ max_side: 256 });
|
||||
.avatar?.createFileURL();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+4
-29
@@ -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}`;
|
||||
|
||||
@@ -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`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user