fix: use proxied image for instance icon on ticker

Closes #9426
This commit is contained in:
ThatOneCalculator 2023-01-24 15:51:34 -08:00
parent d06ed1b477
commit 2fda83c321
No known key found for this signature in database
GPG Key ID: 8703CACD01000000
2 changed files with 21 additions and 1 deletions

View File

@ -1,6 +1,6 @@
<template> <template>
<div class="hpaizdrt" :style="bg"> <div class="hpaizdrt" :style="bg">
<img v-if="instance.faviconUrl" class="icon" :src="instance.faviconUrl" aria-hidden="true"/> <img class="icon" :src="getInstanceIcon(instance)" aria-hidden="true"/>
<span class="name">{{ instance.name }}</span> <span class="name">{{ instance.name }}</span>
</div> </div>
</template> </template>
@ -8,6 +8,7 @@
<script lang="ts" setup> <script lang="ts" setup>
import { instanceName } from '@/config'; import { instanceName } from '@/config';
import { instance as Instance } from '@/instance'; import { instance as Instance } from '@/instance';
import { getProxiedImageUrlNullable } from '@/scripts/media-proxy';
const props = defineProps<{ const props = defineProps<{
instance?: { instance?: {
@ -29,6 +30,10 @@ const themeColor = instance.themeColor ?? '#777777';
const bg = { const bg = {
background: `linear-gradient(90deg, ${themeColor}, ${themeColor}11)`, background: `linear-gradient(90deg, ${themeColor}, ${themeColor}11)`,
}; };
function getInstanceIcon(instance): string {
return getProxiedImageUrlNullable(instance.iconUrl, 'preview') ?? getProxiedImageUrlNullable(instance.faviconUrl, 'preview') ?? '/client-assets/dummy.png';
}
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -0,0 +1,15 @@
import { query } from '@/scripts/url';
import { url } from '@/config';
export function getProxiedImageUrl(imageUrl: string, type?: 'preview'): string {
return `${url}/proxy/image.webp?${query({
url: imageUrl,
fallback: '1',
...(type ? { [type]: '1' } : {}),
})}`;
}
export function getProxiedImageUrlNullable(imageUrl: string | null | undefined, type?: 'preview'): string | null {
if (imageUrl == null) return null;
return getProxiedImageUrl(imageUrl, type);
}