mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-03 05:26:07 +00:00
Push add-n128 (#6)
* Update User.ts method: avatarUrl -> avatarURL * Url -> URL * Fix endpoint for BaseGuild->iconURL * formatting
This commit is contained in:
parent
58b98719b4
commit
2b0a930d37
@ -4,7 +4,7 @@ import type { Session } from "../session/Session.ts";
|
||||
import type { DiscordUser } from "../vendor/external.ts";
|
||||
import type { ImageFormat, ImageSize } from "../util/shared/images.ts";
|
||||
import { iconBigintToHash, iconHashToBigInt } from "../util/hash.ts";
|
||||
import { formatImageUrl } from "../util/shared/images.ts";
|
||||
import { formatImageURL } from "../util/shared/images.ts";
|
||||
import * as Routes from "../util/Routes.ts";
|
||||
|
||||
/**
|
||||
@ -42,7 +42,7 @@ export class User implements Model {
|
||||
}
|
||||
|
||||
/** gets the user's avatar */
|
||||
avatarUrl(options: { format?: ImageFormat; size?: ImageSize } = { size: 128 }) {
|
||||
avatarURL(options: { format?: ImageFormat; size?: ImageSize } = { size: 128 }) {
|
||||
let url: string;
|
||||
|
||||
if (!this.avatarHash) {
|
||||
@ -51,7 +51,7 @@ export class User implements Model {
|
||||
url = Routes.USER_AVATAR(this.id, iconBigintToHash(this.avatarHash));
|
||||
}
|
||||
|
||||
return formatImageUrl(url, options.size, options.format);
|
||||
return formatImageURL(url, options.size, options.format);
|
||||
}
|
||||
|
||||
toString() {
|
||||
|
@ -3,7 +3,7 @@ import type { Session } from "../../session/Session.ts";
|
||||
import type { DiscordGuild, GuildNsfwLevel, VerificationLevels } from "../../vendor/external.ts";
|
||||
import type { ImageFormat, ImageSize } from "../../util/shared/images.ts";
|
||||
import { iconBigintToHash, iconHashToBigInt } from "../../util/hash.ts";
|
||||
import { formatImageUrl } from "../../util/shared/images.ts";
|
||||
import { formatImageURL } from "../../util/shared/images.ts";
|
||||
import BaseGuild from "./BaseGuild.ts";
|
||||
import * as Routes from "../../util/Routes.ts";
|
||||
|
||||
@ -31,9 +31,9 @@ export class AnonymousGuild extends BaseGuild implements Model {
|
||||
description?: string;
|
||||
premiumSubscriptionCount?: number;
|
||||
|
||||
splashUrl(options: { size?: ImageSize; format?: ImageFormat } = { size: 128 }) {
|
||||
splashURL(options: { size?: ImageSize; format?: ImageFormat } = { size: 128 }) {
|
||||
if (this.splashHash) {
|
||||
return formatImageUrl(
|
||||
return formatImageURL(
|
||||
Routes.GUILD_SPLASH(this.id, iconBigintToHash(this.splashHash)),
|
||||
options.size,
|
||||
options.format,
|
||||
@ -41,9 +41,9 @@ export class AnonymousGuild extends BaseGuild implements Model {
|
||||
}
|
||||
}
|
||||
|
||||
bannerUrl(options: { size?: ImageSize; format?: ImageFormat } = { size: 128 }) {
|
||||
bannerURL(options: { size?: ImageSize; format?: ImageFormat } = { size: 128 }) {
|
||||
if (this.bannerHash) {
|
||||
return formatImageUrl(
|
||||
return formatImageURL(
|
||||
Routes.GUILD_BANNER(this.id, iconBigintToHash(this.bannerHash)),
|
||||
options.size,
|
||||
options.format,
|
||||
|
@ -2,7 +2,7 @@ import type { Model } from "../Base.ts";
|
||||
import type { Session } from "../../session/Session.ts";
|
||||
import type { DiscordGuild } from "../../vendor/external.ts";
|
||||
import type { ImageFormat, ImageSize } from "../../util/shared/images.ts";
|
||||
import { formatImageUrl } from "../../util/shared/images.ts";
|
||||
import { formatImageURL } from "../../util/shared/images.ts";
|
||||
import { iconBigintToHash, iconHashToBigInt } from "../../util/hash.ts";
|
||||
import { GuildFeatures } from "../../vendor/external.ts";
|
||||
import { Snowflake } from "../../util/Snowflake.ts";
|
||||
@ -45,10 +45,10 @@ export abstract class BaseGuild implements Model {
|
||||
return this.features.includes(GuildFeatures.Verified);
|
||||
}
|
||||
|
||||
iconUrl(options: { size?: ImageSize; format?: ImageFormat } = { size: 128 }) {
|
||||
iconURL(options: { size?: ImageSize; format?: ImageFormat } = { size: 128 }) {
|
||||
if (this.iconHash) {
|
||||
return formatImageUrl(
|
||||
Routes.GUILD_BANNER(this.id, iconBigintToHash(this.iconHash)),
|
||||
return formatImageURL(
|
||||
Routes.GUILD_ICON(this.id, iconBigintToHash(this.iconHash)),
|
||||
options.size,
|
||||
options.format,
|
||||
);
|
||||
|
@ -9,6 +9,6 @@ export type ImageFormat = "jpg" | "jpeg" | "png" | "webp" | "gif" | "json";
|
||||
export type ImageSize = 16 | 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096;
|
||||
|
||||
/** Help format an image url */
|
||||
export function formatImageUrl(url: string, size: ImageSize = 128, format?: ImageFormat) {
|
||||
export function formatImageURL(url: string, size: ImageSize = 128, format?: ImageFormat) {
|
||||
return `${url}.${format || (url.includes("/a_") ? "gif" : "jpg")}?size=${size}`;
|
||||
}
|
||||
|
8
vendor/types/shared.ts
vendored
8
vendor/types/shared.ts
vendored
@ -1238,7 +1238,7 @@ export type CamelCase<S extends string> = S extends `${infer P1}_${infer P2}${in
|
||||
: Lowercase<S>;
|
||||
export type Camelize<T> = {
|
||||
[K in keyof T as CamelCase<string & K>]: T[K] extends Array<infer U> ? U extends {} ? Array<Camelize<U>>
|
||||
: T[K]
|
||||
: T[K]
|
||||
: T[K] extends {} ? Camelize<T[K]>
|
||||
: never;
|
||||
};
|
||||
@ -1293,8 +1293,8 @@ export type AnythingBut<T> = Exclude<
|
||||
* object identity type
|
||||
*/
|
||||
export type Id<T> = T extends infer U ? {
|
||||
[K in keyof U]: U[K];
|
||||
}
|
||||
[K in keyof U]: U[K];
|
||||
}
|
||||
: never;
|
||||
|
||||
export type KeysWithUndefined<T> = {
|
||||
@ -1319,7 +1319,7 @@ type OptionalizeAux<T extends object> = Id<
|
||||
export type Optionalize<T> = T extends object
|
||||
? T extends Array<unknown>
|
||||
? number extends T["length"] ? T[number] extends object ? Array<OptionalizeAux<T[number]>>
|
||||
: T
|
||||
: T
|
||||
: Partial<T>
|
||||
: OptionalizeAux<T>
|
||||
: T;
|
||||
|
Loading…
x
Reference in New Issue
Block a user