Skip to content
This repository has been archived by the owner on Jan 8, 2022. It is now read-only.

Commit

Permalink
feat(CDN#guildIcon): implement dynamic logic (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fyko authored Sep 7, 2021
1 parent 78212bb commit c4b2803
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 8 additions & 0 deletions packages/rest/__tests__/CDN.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ test('icon default', () => {
expect(cdn.icon(id, hash)).toBe(`${base}/icons/${id}/${hash}.png`);
});

test('guildIcon dynamic-animated', () => {
expect(cdn.icon(id, animatedHash, { dynamic: true })).toBe(`${base}/icons/${id}/${animatedHash}.gif`);
});

test('guildIcon dynamic-not-animated', () => {
expect(cdn.icon(id, hash, { dynamic: true })).toBe(`${base}/icons/${id}/${hash}.png`);
});

test('splash default', () => {
expect(cdn.splash(id, hash)).toBe(`${base}/splashes/${id}/${hash}.png`);
});
Expand Down
8 changes: 6 additions & 2 deletions packages/rest/src/lib/CDN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,12 @@ export class CDN {
* @param iconHash The hash provided by Discord for this icon
* @param options Optional options for the icon
*/
public icon(id: string, iconHash: string, options?: ImageURLOptions): string {
return this.makeURL(`/icons/${id}/${iconHash}`, options);
public icon(guildId: string, iconHash: string, { dynamic = false, ...options }: ImageURLOptions = {}): string {
if (dynamic && iconHash.startsWith('a_')) {
options.extension = 'gif';
}

return this.makeURL(`/icons/${guildId}/${iconHash}`, options);
}

/**
Expand Down

0 comments on commit c4b2803

Please sign in to comment.