edit cdn.ts
This commit is contained in:
		
							parent
							
								
									45eadb5d11
								
							
						
					
					
						commit
						a143399f6e
					
				
					 2 changed files with 8 additions and 6 deletions
				
			
		|  | @ -1,11 +1,13 @@ | ||||||
| import { ImageFormats, ImageSize } from '../types/cdn.ts' | import { ImageFormats, ImageSize } from '../types/cdn.ts' | ||||||
| 
 | 
 | ||||||
|  | /** Function to get Image URL from a resource on Discord CDN */ | ||||||
| export const ImageURL = ( | export const ImageURL = ( | ||||||
|   url: string, |   url: string, | ||||||
|   format: ImageFormats, |   format: ImageFormats | undefined = 'webp', | ||||||
|   size?: ImageSize | 128 |   size: ImageSize | undefined = 128 | ||||||
| ): string => { | ): string => { | ||||||
|  |   size = size === undefined ? 128 : size | ||||||
|   if (url.includes('a_')) { |   if (url.includes('a_')) { | ||||||
|     return `${url}.gif?size=${size}` |     return `${url}.${format === undefined ? 'gif' : format}?size=${size}` | ||||||
|   } else return `${url}.${format}?size=${size}` |   } else return `${url}.${format === 'gif' ? 'webp' : format}?size=${size}` | ||||||
| } | } | ||||||
|  | @ -42,7 +42,7 @@ export class User extends Base { | ||||||
| 
 | 
 | ||||||
|   avatarURL(format: ImageFormats = 'webp', size: ImageSize = 512, dynamic: boolean = true): string { |   avatarURL(format: ImageFormats = 'webp', size: ImageSize = 512, dynamic: boolean = true): string { | ||||||
|     return this.avatar != null |     return this.avatar != null | ||||||
|       ? `${ImageURL(USER_AVATAR(this.id, dynamic ? this.avatar : this.avatar.replace('a_', '')), format, size)}` |       ? `${ImageURL(USER_AVATAR(this.id, this.avatar), format, size)}` | ||||||
|       : `${DEFAULT_USER_AVATAR(String(Number(this.discriminator) % 5))}.png` |       : `${DEFAULT_USER_AVATAR(String(Number(this.discriminator) % 5))}.png` | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue