/* * SPDX-FileCopyrightText: 2020 Stalwart Labs LLC * * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL */ import { useState, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { getApiBaseUrl } from '@/services/api'; export function DefaultLogo() { const { t } = useTranslation(); return ( ); } export default function Logo() { const { t } = useTranslation(); const [logoUrl, setLogoUrl] = useState(null); const [failed, setFailed] = useState(false); useEffect(() => { const controller = new AbortController(); async function fetchLogo() { try { const response = await fetch(`${getApiBaseUrl()}/logo`, { signal: controller.signal, }); const contentType = response.headers.get('content-type') ?? ''; if (response.ok && contentType.startsWith('image/')) { const blob = await response.blob(); if (!controller.signal.aborted) { const url = URL.createObjectURL(blob); setLogoUrl(url); } } else { if (!controller.signal.aborted) setFailed(true); } } catch { if (!controller.signal.aborted) setFailed(true); } } fetchLogo(); return () => { controller.abort(); }; }, []); useEffect(() => { return () => { if (logoUrl) { URL.revokeObjectURL(logoUrl); } }; }, [logoUrl]); if (logoUrl && !failed) { return {t('logo.alt',; } if (!failed) { return