Skip to content

Commit

Permalink
Avatar and GuildIcon
Browse files Browse the repository at this point in the history
  • Loading branch information
mentalisit committed May 15, 2024
1 parent bb6dd4f commit 0db5e4f
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/components/CompendiumPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@
>
<div class="avatar">
<img
:src="getDiscordIconUrl(guild!.id, guild!.icon).href"
:src="getIconUrl(guild!.url).href"
:alt="`${guild!.name} icon`"
@error="(e) => e.target.src = memberImage"
>
<img
:src="getDiscordAvatarUrl(user.id, user.avatar).href"
:src="getAvatarUrl(user.avatarUrl).href"
:alt="`${user.username} avatar`"
@error="(e) => e.target.src = memberImage"
>
Expand Down Expand Up @@ -142,7 +142,7 @@ import { useI18n } from 'vue-i18n';
import { Guild as Guild2, Identity as Identity2, User as User2 } from 'bot_client2';
import client, { init as clientInit, switchInstance } from '@Utils/compendium';
import { getDiscordAvatarUrl, getDiscordIconUrl } from '@Utils/getDiscordUrl';
import { getAvatarUrl, getIconUrl } from '@Utils/getDiscordUrl';
import memberImage from '@Img/icons/member.png';
import types from '@/store/types';
import types2 from '@/store/modules/userSettings/types';
Expand Down
4 changes: 2 additions & 2 deletions src/pages/CompendiumCorp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<div class="meta">
<div class="avatar">
<img
:src="getDiscordAvatarUrl(mem.userId, mem.avatar)"
:src="getAvatarUrl(mem.avatarUrl)"
:alt="`${mem.name} avatar`"
@error="(e) => e.target.src = memberImage"
></div>
Expand Down Expand Up @@ -143,7 +143,7 @@ import { onMounted, reactive, Ref, ref, watch } from 'vue';
import { useStore } from 'vuex';
import { useI18n } from 'vue-i18n';
import { getDiscordAvatarUrl } from '@Utils/getDiscordUrl';
import { getAvatarUrl } from '@Utils/getDiscordUrl';
import client from '../utils/compendium';
import types from '@/store/modules/userSettings/types';
Expand Down
33 changes: 28 additions & 5 deletions src/utils/getDiscordUrl.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,37 @@
const ENDPOINT = 'https://cdn.discordapp.com/';
// const ENDPOINT = 'https://cdn.discordapp.com/';


export function getDiscordAvatarUrl(userId: string, avatarHash: string, size = 80): URL {
const url = new URL(`avatars/${userId}/${avatarHash}.webp`, ENDPOINT);
// export function getDiscordAvatarUrl(userId: string, avatarHash: string, size = 80): URL {
// const url = new URL(`avatars/${userId}/${avatarHash}.webp`, ENDPOINT);
//
// url.searchParams.set('size', String(size));
// return url;
// }

export function getAvatarUrl(userAvatarUrl: string, size = 80): URL {
if (userAvatarUrl === '') {
userAvatarUrl = 'https://github.com/userXinos/HadesSpace/blob/master/src/img/icons/member.png';
}
userAvatarUrl = userAvatarUrl.replace(/\.png/g, '.webp');
const url = new URL(`${userAvatarUrl}`);

url.searchParams.set('size', String(size));
return url;
}
export function getDiscordIconUrl(guildId: string, iconHash: string, size = 96): URL {
const url = new URL(`icons/${guildId}/${iconHash}.webp`, ENDPOINT);

// export function getDiscordIconUrl(guildId: string, iconHash: string, size = 96): URL {
// const url = new URL(`icons/${guildId}/${iconHash}.webp`, ENDPOINT);
//
// url.searchParams.set('size', String(size));
// return url;
// }

export function getIconUrl(urlGuild: string, size = 96): URL {
if (urlGuild === '') {
urlGuild = 'https://github.com/userXinos/HadesSpace/blob/master/src/img/icons/member.png';
}
urlGuild = urlGuild.replace(/\.png/g, '.webp');
const url = new URL(`${urlGuild}`);

url.searchParams.set('size', String(size));
return url;
Expand Down

0 comments on commit 0db5e4f

Please sign in to comment.