feat(front): improve logo component (#8720)
This commit is contained in:
@ -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>;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user