Skip to content

Commit cf9e7ca

Browse files
committed
refactor: include hash for discord cdn routing
1 parent 351d9b9 commit cf9e7ca

File tree

18 files changed

+39
-27
lines changed

18 files changed

+39
-27
lines changed

components/BotCard.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const BotCard: React.FC<BotCardProps> = ({ manage = false, bot }) => {
3434
<DiscordAvatar
3535
size={128}
3636
userID={bot.id}
37+
hash={bot.avatar}
3738
alt='Avatar'
3839
className='absolute -left-2 -top-8 mx-auto h-32 w-32 rounded-full bg-white'
3940
/>

components/DiscordAvatar.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ const DiscordAvatar: React.FC<DiscordAvatarProps> = (props) => {
1111
src={KoreanbotsEndPoints.CDN.avatar(props.userID, {
1212
format: 'webp',
1313
size: props.size ?? 256,
14+
hash: props.hash,
1415
})}
1516
fallbackSrc={KoreanbotsEndPoints.CDN.avatar(props.userID, {
1617
format: 'png',
1718
size: props.size ?? 256,
19+
hash: props.hash,
1820
})}
1921
/>
2022
)
@@ -25,6 +27,7 @@ interface DiscordAvatarProps {
2527
userID: string
2628
className?: string
2729
size?: 128 | 256 | 512
30+
hash?: string
2831
}
2932

3033
interface ImageEvent extends Event {

components/Search.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ const Search: React.FC = () => {
138138
data.data.bots.map((el) => (
139139
<Link key={el.id} href={makeBotURL(el)} legacyBehavior>
140140
<li className='h-15 flex cursor-pointer px-3 py-2'>
141-
<DiscordAvatar className='mt-1 h-12 w-12' size={128} userID={el.id} />
141+
<DiscordAvatar className='mt-1 h-12 w-12' size={128} userID={el.id} hash={el.avatar}/>
142142
<div className='ml-2'>
143143
<h1 className='text-lg text-black dark:text-gray-100'>{el.name}</h1>
144144
<p className='text-sm text-gray-400'>{el.intro}</p>
@@ -156,7 +156,7 @@ const Search: React.FC = () => {
156156
data.data.servers.map((el) => (
157157
<Link key={el.id} href={makeServerURL(el)} legacyBehavior>
158158
<li className='h-15 flex cursor-pointer px-3 py-2'>
159-
<ServerIcon className='mt-1 h-12 w-12' size={128} id={el.id} />
159+
<ServerIcon className='mt-1 h-12 w-12' size={128} id={el.id} hash={el.icon} />
160160
<div className='ml-2'>
161161
<h1 className='text-lg text-black dark:text-gray-100'>{el.name}</h1>
162162
<p className='text-sm text-gray-400'>{el.intro}</p>

components/ServerCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ const ServerCard: React.FC<BotCardProps> = ({ type, server }) => {
4343
<ServerIcon
4444
size={128}
4545
id={server.id}
46-
hash={type === 'add' && server.icon}
46+
hash={server.icon}
4747
alt='Icon'
4848
className='absolute -left-2 -top-8 mx-auto h-32 w-32 rounded-full bg-white'
4949
/>

components/ServerIcon.tsx

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { SyntheticEvent } from 'react'
22
import dynamic from 'next/dynamic'
3-
import { DiscordEnpoints, KoreanbotsEndPoints } from '@utils/Constants'
3+
import { KoreanbotsEndPoints } from '@utils/Constants'
44

55
const Image = dynamic(() => import('@components/Image'))
66

@@ -9,16 +9,8 @@ const ServerIcon: React.FC<ServerIconProps> = ({ id, size, className, alt, hash
99
<Image
1010
className={className}
1111
alt={alt}
12-
src={
13-
hash
14-
? DiscordEnpoints.CDN.guild(id, hash, { format: 'webp', size: size ?? 256 })
15-
: KoreanbotsEndPoints.CDN.icon(id, { format: 'webp', size: size ?? 256 })
16-
}
17-
fallbackSrc={
18-
hash
19-
? DiscordEnpoints.CDN.guild(id, hash, { format: 'png', size: size ?? 256 })
20-
: KoreanbotsEndPoints.CDN.icon(id, { format: 'png', size: size ?? 256 })
21-
}
12+
src={KoreanbotsEndPoints.CDN.icon(id, { format: 'webp', size: size ?? 256, hash })}
13+
fallbackSrc={KoreanbotsEndPoints.CDN.icon(id, { format: 'png', size: size ?? 256, hash })}
2214
/>
2315
)
2416
}

pages/api/v2/bots/[id]/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
} from '@utils/Tools'
2626
import { discordLog, getMainGuild, webhookClients } from '@utils/DiscordBot'
2727
import { KoreanbotsEndPoints } from '@utils/Constants'
28+
import { userInfo } from 'os'
2829

2930
const patchLimiter = rateLimit({
3031
windowMs: 2 * 60 * 1000,
@@ -127,7 +128,7 @@ const Bots = RequestHandler()
127128
: `${userinfo.username}#${userinfo.tag}`,
128129
iconURL:
129130
KoreanbotsEndPoints.URL.root +
130-
KoreanbotsEndPoints.CDN.avatar(userinfo.id, { format: 'png', size: 256 }),
131+
KoreanbotsEndPoints.CDN.avatar(userinfo.id, { format: 'png', size: 256, hash: userinfo.avatar }),
131132
url: KoreanbotsEndPoints.URL.user(userinfo.id),
132133
})
133134
.setTitle('대기 중')

pages/bots/[id]/edit.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ const ManageBotPage: NextPage<ManageBotProps> = ({ bot, user, csrfToken, theme }
9595
{({ errors, touched, values, setFieldTouched, setFieldValue }) => (
9696
<Form>
9797
<div className='text-center md:flex md:text-left'>
98-
<DiscordAvatar userID={bot.id} className='mx-auto rounded-full md:mx-1' />
98+
<DiscordAvatar userID={bot.id} className='mx-auto rounded-full md:mx-1' hash={bot.avatar}/>
9999
<div className='px-8 py-6 md:w-2/3'>
100100
<h1 className='text-3xl font-bold'>
101101
{bot.name}#{bot.tag}
@@ -344,6 +344,7 @@ const ManageBotPage: NextPage<ManageBotProps> = ({ bot, user, csrfToken, theme }
344344
<DiscordAvatar
345345
userID={el.id}
346346
size={128}
347+
hash={el.avatar}
347348
className='mr-1 h-6 w-6 rounded-full'
348349
/>{' '}
349350
{el.tag === '0'

pages/bots/[id]/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ const Bots: NextPage<BotsProps> = ({ data, desc, date, user, theme, csrfToken })
122122
</div>
123123
<div className='w-full lg:flex'>
124124
<div className='w-full text-center lg:w-2/12'>
125-
<DiscordAvatar userID={data.id} size={256} className='w-full rounded-full' />
125+
<DiscordAvatar userID={data.id} size={256} className='w-full rounded-full' hash={data.avatar}/>
126126
</div>
127127
<div className='w-full grow px-5 py-12 text-center lg:w-5/12 lg:text-left'>
128128
<Tag

pages/bots/[id]/vote.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ const VoteBot: NextPage<VoteBotProps> = ({ data, user, theme, csrfToken }) => {
9292
<div className='text-center'>
9393
<DiscordAvatar
9494
userID={data.id}
95+
hash={data.avatar}
9596
className='mx-auto mb-4 h-52 w-52 rounded-full bg-white'
9697
/>
9798
<Tag

pages/developers/applications/bots/[id].tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const BotApplication: NextPage<BotApplicationProps> = ({ user, spec, bot, theme,
7070
</p>
7171
<div className='pt-6 lg:flex'>
7272
<div className='lg:w-1/5'>
73-
<DiscordAvatar userID={bot.id} />
73+
<DiscordAvatar userID={bot.id} hash={bot.avatar} />
7474
</div>
7575
<div className='relative lg:w-4/5'>
7676
<div className='mt-4'>

0 commit comments

Comments
 (0)