harmony/src/structures/cdn.ts

13 lines
480 B
TypeScript
Raw Normal View History

2020-10-31 12:33:34 +00:00
import { ImageFormats, ImageSize } from '../types/cdn.ts'
2020-12-03 04:04:44 +00:00
/** Function to get Image URL from a resource on Discord CDN */
export const ImageURL = (
url: string,
2020-12-03 04:04:44 +00:00
format: ImageFormats | undefined = 'webp',
size: ImageSize | undefined = 128
): string => {
2020-12-03 04:04:44 +00:00
size = size === undefined ? 128 : size
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}`
}