2020-10-31 12:33:34 +00:00
|
|
|
import { 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,
|
2020-12-03 04:04:44 +00:00
|
|
|
format: ImageFormats | undefined = 'webp',
|
|
|
|
size: ImageSize | undefined = 128
|
2020-10-25 17:03:53 +00:00
|
|
|
): string => {
|
2020-12-03 04:04:44 +00:00
|
|
|
size = size === undefined ? 128 : size
|
2020-10-25 17:03:53 +00:00
|
|
|
if (url.includes('a_')) {
|
2020-12-03 04:04:44 +00:00
|
|
|
return `${url}.${format === undefined ? 'gif' : format}?size=${size}`
|
|
|
|
} else return `${url}.${format === 'gif' ? 'webp' : format}?size=${size}`
|
|
|
|
}
|