Skip to content

Commit 0609886

Browse files
author
Vitor
authored
feat(REST): add CDNRoutes (#502)
1 parent a2d76fc commit 0609886

File tree

4 files changed

+1024
-0
lines changed

4 files changed

+1024
-0
lines changed

deno/rest/v10/mod.ts

Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,262 @@ export const Routes = {
844844
},
845845
};
846846

847+
export const StickerPackApplicationId = '710982414301790216';
848+
849+
export const CDNRoutes = {
850+
/**
851+
* Route for:
852+
* - GET `/emojis/{emoji.id}.{png|jpeg|webp|gif}`
853+
*
854+
* As this route supports GIFs, the hash will begin with `a_` if it is available in GIF format
855+
*
856+
* This route supports the extensions: PNG, JPEG, WebP, GIF
857+
*/
858+
emoji(emojiId: Snowflake, format: EmojiFormat) {
859+
return `/emojis/${emojiId}.${format}` as const;
860+
},
861+
862+
/**
863+
* Route for:
864+
* - GET `/guilds/{guild.id}/icons/{guild.id}.{png|jpeg|webp|gif}`
865+
*
866+
* As this route supports GIFs, the hash will begin with `a_` if it is available in GIF format
867+
*
868+
* This route supports the extensions: PNG, JPEG, WebP, GIF
869+
*/
870+
guildIcon(guildId: Snowflake, guildIcon: string, format: GuildIconFormat) {
871+
return `icons/${guildId}/${guildIcon}.${format}` as const;
872+
},
873+
874+
/**
875+
* Route for:
876+
* - GET `/splashes/{guild.id}/{guild.splash}.{png|jpeg|webp}`
877+
*
878+
* This route supports the extensions: PNG, JPEG, WebP
879+
*/
880+
guildSplash(guildId: Snowflake, guildSplash: string, format: GuildSplashFormat) {
881+
return `/splashes/${guildId}/${guildSplash}.${format}` as const;
882+
},
883+
884+
/**
885+
* Route for:
886+
* - GET `/discovery-splashes/{guild.id}/{guild.discovery_splash}.{png|jpeg|webp}`
887+
*
888+
* This route supports the extensions: PNG, JPEG, WebP
889+
*/
890+
guildDiscoverySplash(guildId: Snowflake, guildDiscoverySplash: string, format: GuildDiscoverySplashFormat) {
891+
return `/discovery-splashes/${guildId}/${guildDiscoverySplash}.${format}` as const;
892+
},
893+
894+
/**
895+
* Route for:
896+
* - GET `/banners/{guild.id}/{guild.banner}.{png|jpeg|webp|gif}`
897+
*
898+
* As this route supports GIFs, the hash will begin with `a_` if it is available in GIF format
899+
*
900+
* This route supports the extensions: PNG, JPEG, WebP, GIF
901+
*/
902+
guildBanner(guildId: Snowflake, guildBanner: string, format: GuildBannerFormat) {
903+
return `/banners/${guildId}/${guildBanner}.${format}` as const;
904+
},
905+
906+
/**
907+
* Route for:
908+
* - GET `/banners/{user.id}/{user.banner}.{png|jpeg|webp|gif}`
909+
*
910+
* As this route supports GIFs, the hash will begin with `a_` if it is available in GIF format
911+
*
912+
* This route supports the extensions: PNG, JPEG, WebP, GIF
913+
*/
914+
userBanner(userId: Snowflake, userBanner: string, format: UserBannerFormat) {
915+
return `/banners/${userId}/${userBanner}.${format}` as const;
916+
},
917+
918+
/**
919+
* Route for:
920+
* - GET `/embed/avatars/{user.discriminator % 5}.png`
921+
*
922+
* The `userDiscriminator` parameter should be the user discriminator modulo 5 (e.g. 1337 % 5 = 2)
923+
*
924+
* This route supports the extension: PNG
925+
*/
926+
defaultUserAvatar(userDiscriminator: DefaultUserAvatarAssets) {
927+
return `/embed/avatars/${userDiscriminator}.png` as const;
928+
},
929+
930+
/**
931+
* Route for:
932+
* - GET `/avatars/{user.id}/{user.avatar}.{png|jpeg|webp|gif}`
933+
*
934+
* As this route supports GIFs, the hash will begin with `a_` if it is available in GIF format
935+
*
936+
* This route supports the extensions: PNG, JPEG, WebP, GIF
937+
*/
938+
userAvatar(userId: Snowflake, userAvatar: string, format: UserAvatarFormat) {
939+
return `/avatars/${userId}/${userAvatar}.${format}` as const;
940+
},
941+
942+
/**
943+
* Route for:
944+
* - GET `/guilds/{guild.id}/users/{user.id}/{guild_member.avatar}.{png|jpeg|webp|gif}`
945+
*
946+
* As this route supports GIFs, the hash will begin with `a_` if it is available in GIF format
947+
*
948+
* This route supports the extensions: PNG, JPEG, WebP, GIF
949+
*/
950+
guildMemberAvatar(guildId: Snowflake, userId: Snowflake, memberAvatar: string, format: GuildMemberAvatarFormat) {
951+
return `/guilds/${guildId}/users/${userId}/avatars/${memberAvatar}.${format}` as const;
952+
},
953+
954+
/**
955+
* Route for:
956+
* - GET `/app-icons/{application.id}/{application.icon}.{png|jpeg|webp}`
957+
*
958+
* This route supports the extensions: PNG, JPEG, WebP
959+
*/
960+
applicationIcon(applicationId: Snowflake, applicationIcon: string, format: ApplicationIconFormat) {
961+
return `/app-icons/${applicationId}/${applicationIcon}.${format}` as const;
962+
},
963+
964+
/**
965+
* Route for:
966+
* - GET `/app-icons/{application.id}/{application.cover_image}.{png|jpeg|webp}`
967+
*
968+
* This route supports the extensions: PNG, JPEG, WebP
969+
*/
970+
applicationCover(applicationId: Snowflake, applicationCoverImage: string, format: ApplicationCoverFormat) {
971+
return `/app-icons/${applicationId}/${applicationCoverImage}.${format}` as const;
972+
},
973+
974+
/**
975+
* Route for:
976+
* - GET `/app-icons/{application.id}/{application.asset_id}.{png|jpeg|webp}`
977+
*
978+
* This route supports the extensions: PNG, JPEG, WebP
979+
*/
980+
applicationAsset(applicationId: Snowflake, applicationAssetId: string, format: ApplicationAssetFormat) {
981+
return `/app-icons/${applicationId}/${applicationAssetId}.${format}` as const;
982+
},
983+
984+
/**
985+
* Route for:
986+
* - GET `/app-assets/{application.id}/achievements/{achievement.id}/icons/{achievement.icon}.{png|jpeg|webp}`
987+
*
988+
* This route supports the extensions: PNG, JPEG, WebP
989+
*/
990+
achievementIcon(
991+
applicationId: Snowflake,
992+
achievementId: Snowflake,
993+
achievementIconHash: string,
994+
format: AchievementIconFormat,
995+
) {
996+
return `/app-assets/${applicationId}/achievements/${achievementId}/icons/${achievementIconHash}.${format}` as const;
997+
},
998+
999+
/**
1000+
* Route for:
1001+
* - GET `/app-assets/710982414301790216/store/{sticker_pack.banner.asset_id}.{png|jpeg|webp}`
1002+
*
1003+
* This route supports the extensions: PNG, JPEG, WebP
1004+
*/
1005+
stickerPackBanner(stickerPackBannerAssetId: Snowflake, format: StickerPackBannerFormat) {
1006+
return `/app-assets/${StickerPackApplicationId}/store/${stickerPackBannerAssetId}.${format}` as const;
1007+
},
1008+
1009+
/**
1010+
* Route for:
1011+
* - GET `team-icons/{team.id}/{team.icon}.{png|jpeg|webp}`
1012+
*
1013+
* This route supports the extensions: PNG, JPEG, WebP
1014+
*/
1015+
teamIcon(teamId: Snowflake, teamIcon: string, format: TeamIconFormat) {
1016+
return `/team-icons/${teamId}/${teamIcon}.${format}` as const;
1017+
},
1018+
1019+
/**
1020+
* Route for:
1021+
* - GET `/stickers/{sticker.id}.{png|json}`
1022+
*
1023+
* This route supports the extensions: PNG, Lottie
1024+
*/
1025+
sticker(stickerId: Snowflake, format: StickerFormat) {
1026+
return `/stickers/${stickerId}.${format}` as const;
1027+
},
1028+
1029+
/**
1030+
* Route for:
1031+
* - GET `/role-icons/{role.id}/{role.icon}.{png|jpeg|webp}`
1032+
*
1033+
* This route supports the extensions: PNG, JPEG, WebP
1034+
*/
1035+
roleIcon(roleId: Snowflake, roleIcon: string, format: RoleIconFormat) {
1036+
return `/role-icons/${roleId}/${roleIcon}.${format}` as const;
1037+
},
1038+
1039+
/**
1040+
* Route for:
1041+
* - GET `/guild-events/{guild_scheduled_event.id}/{guild_scheduled_event.image}.{png|jpeg|webp}`
1042+
*
1043+
* This route supports the extensions: PNG, JPEG, WebP
1044+
*/
1045+
guildScheduledEventCover(
1046+
guildScheduledEventId: Snowflake,
1047+
guildScheduledEventCoverImage: string,
1048+
format: GuildScheduledEventCoverFormat,
1049+
) {
1050+
return `/guild-events/${guildScheduledEventId}/${guildScheduledEventCoverImage}.${format}` as const;
1051+
},
1052+
1053+
/**
1054+
* Route for:
1055+
* - GET `/guilds/${guild.id}/users/${user.id}/banners/${guild_member.banner}.{png|jpeg|webp|gif}`
1056+
*
1057+
* This route supports the extensions: PNG, JPEG, WebP, GIF
1058+
*/
1059+
guildMemberBanner(guildId: Snowflake, userId: Snowflake, guildMemberBanner: string, format: GuildMemberBannerFormat) {
1060+
return `/guilds/${guildId}/users/${userId}/banners/${guildMemberBanner}.${format}` as const;
1061+
},
1062+
};
1063+
1064+
export type DefaultUserAvatarAssets = 0 | 1 | 2 | 3 | 4 | 5;
1065+
1066+
export type EmojiFormat = Exclude<ImageFormat, ImageFormat.Lottie>;
1067+
export type GuildIconFormat = Exclude<ImageFormat, ImageFormat.Lottie>;
1068+
export type GuildSplashFormat = Exclude<ImageFormat, ImageFormat.Lottie | ImageFormat.GIF>;
1069+
export type GuildDiscoverySplashFormat = Exclude<ImageFormat, ImageFormat.Lottie | ImageFormat.GIF>;
1070+
export type GuildBannerFormat = Exclude<ImageFormat, ImageFormat.Lottie>;
1071+
export type UserBannerFormat = Exclude<ImageFormat, ImageFormat.Lottie>;
1072+
export type DefaultUserAvatar = Extract<ImageFormat, ImageFormat.PNG>;
1073+
export type UserAvatarFormat = Exclude<ImageFormat, ImageFormat.Lottie>;
1074+
export type GuildMemberAvatarFormat = Exclude<ImageFormat, ImageFormat.Lottie>;
1075+
export type ApplicationIconFormat = Exclude<ImageFormat, ImageFormat.Lottie | ImageFormat.GIF>;
1076+
export type ApplicationCoverFormat = Exclude<ImageFormat, ImageFormat.Lottie | ImageFormat.GIF>;
1077+
export type ApplicationAssetFormat = Exclude<ImageFormat, ImageFormat.Lottie | ImageFormat.GIF>;
1078+
export type AchievementIconFormat = Exclude<ImageFormat, ImageFormat.Lottie | ImageFormat.GIF>;
1079+
export type StickerPackBannerFormat = Exclude<ImageFormat, ImageFormat.Lottie | ImageFormat.GIF>;
1080+
export type TeamIconFormat = Exclude<ImageFormat, ImageFormat.Lottie | ImageFormat.GIF>;
1081+
export type StickerFormat = Extract<ImageFormat, ImageFormat.PNG | ImageFormat.Lottie>;
1082+
export type RoleIconFormat = Exclude<ImageFormat, ImageFormat.Lottie | ImageFormat.GIF>;
1083+
export type GuildScheduledEventCoverFormat = Exclude<ImageFormat, ImageFormat.Lottie | ImageFormat.GIF>;
1084+
export type GuildMemberBannerFormat = Exclude<ImageFormat, ImageFormat.Lottie>;
1085+
1086+
export enum ImageFormat {
1087+
JPEG = 'jpeg',
1088+
PNG = 'png',
1089+
WebP = 'webp',
1090+
GIF = 'gif',
1091+
Lottie = 'json',
1092+
}
1093+
1094+
export interface CDNQuery {
1095+
/**
1096+
* The returned image can have the size changed by using this query parameter
1097+
*
1098+
* Image size can be any power of two between 16 and 4096
1099+
*/
1100+
size?: number;
1101+
}
1102+
8471103
export const RouteBases = {
8481104
api: `https://discord.com/api/v${APIVersion}`,
8491105
cdn: 'https://cdn.discordapp.com',

0 commit comments

Comments
 (0)