2021-04-04 09:29:56 +00:00
|
|
|
import type { ImageFormats, ImageSize } from '../types/cdn.ts'
|
2020-10-23 03:19:40 +00:00
|
|
|
|
2020-12-03 04:04:44 +00:00
|
|
|
/** Function to get Image URL from a resource on Discord CDN */
|
2020-10-23 03:19:40 +00:00
|
|
|
export const ImageURL = (
|
2020-10-25 17:03:53 +00:00
|
|
|
url: string,
|
2021-03-04 12:13:50 +00:00
|
|
|
format: ImageFormats = 'png',
|
|
|
|
size: ImageSize = 128
|
2020-10-25 17:03:53 +00:00
|
|
|
): string => {
|
|
|
|
if (url.includes('a_')) {
|
2021-03-04 12:13:50 +00:00
|
|
|
return `${url}.${format === 'dynamic' ? 'gif' : format}?size=${size}`
|
|
|
|
} else
|
|
|
|
return `${url}.${
|
|
|
|
format === 'gif' || format === 'dynamic' ? 'png' : format
|
|
|
|
}?size=${size}`
|
2020-12-05 07:20:08 +00:00
|
|
|
}
|