feat(front): improve logo component (#8720)

This commit is contained in:
Antoine Moreaux
2024-11-27 19:26:45 +01:00
committed by GitHub
parent 3ad1113173
commit 2fab2266d5
3 changed files with 43 additions and 35 deletions

View File

@ -1,15 +1,26 @@
import { REACT_APP_SERVER_BASE_URL } from '~/config';
export const getImageAbsoluteURI = (imageUrl?: string | null) => {
type ImageAbsoluteURI<T extends string | null | undefined> = T extends string
? string
: null;
export const getImageAbsoluteURI = <T extends string | null | undefined>(
imageUrl: T,
): ImageAbsoluteURI<T> => {
if (!imageUrl) {
return null;
return null as ImageAbsoluteURI<T>;
}
if (imageUrl?.startsWith('https:') || imageUrl?.startsWith('http:')) {
return imageUrl;
if (imageUrl.startsWith('https:') || imageUrl.startsWith('http:')) {
return imageUrl as ImageAbsoluteURI<T>;
}
const serverFilesUrl = REACT_APP_SERVER_BASE_URL;
const serverFilesUrl = new URL(REACT_APP_SERVER_BASE_URL);
return `${serverFilesUrl}/files/${imageUrl}`;
serverFilesUrl.pathname = `/files/`;
serverFilesUrl.pathname += imageUrl.startsWith('/')
? imageUrl.slice(1)
: imageUrl;
return serverFilesUrl.toString() as ImageAbsoluteURI<T>;
};