PR Summary: 1. Added `Twenty Shared` Package to centralize utilitiies as mentioned in #8942 2. Optimization of `getImageAbsoluteURI.ts` to handle edge cases  --------- Co-authored-by: Antoine Moreaux <moreaux.antoine@gmail.com> Co-authored-by: Charles Bochet <charles@twenty.com>
20 lines
440 B
TypeScript
20 lines
440 B
TypeScript
type getImageAbsoluteURIProps = {
|
|
imageUrl: string;
|
|
baseUrl: string;
|
|
};
|
|
|
|
export const getImageAbsoluteURI = ({
|
|
imageUrl,
|
|
baseUrl,
|
|
}: getImageAbsoluteURIProps): string => {
|
|
if (imageUrl.startsWith('https:') || imageUrl.startsWith('http:')) {
|
|
return imageUrl;
|
|
}
|
|
|
|
if (imageUrl.startsWith('/')) {
|
|
return new URL(`/files${imageUrl}`, baseUrl).toString();
|
|
}
|
|
|
|
return new URL(`/files/${imageUrl}`, baseUrl).toString();
|
|
};
|