fix: handle cdnPrefix without protocol (#5373)

* fix: handle cdnPrefix without protocol

* cdnPrefix trim
This commit is contained in:
Reinaldo Neto 2023-12-11 12:35:33 -03:00 committed by GitHub
parent e295cbbcc6
commit 7c0a2692dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

@ -24,9 +24,10 @@ export const formatAttachmentUrl = (attachmentUrl: string | undefined, userId: s
} }
return setParamInUrl({ url: attachmentUrl, token, userId }); return setParamInUrl({ url: attachmentUrl, token, userId });
} }
const cdnPrefix = store?.getState().settings.CDN_PREFIX as string; let cdnPrefix = store?.getState().settings.CDN_PREFIX as string;
if (cdnPrefix) { cdnPrefix = cdnPrefix?.trim();
server = cdnPrefix.trim().replace(/\/+$/, ''); if (cdnPrefix && cdnPrefix.startsWith('http')) {
server = cdnPrefix.replace(/\/+$/, '');
} }
return setParamInUrl({ url: `${server}${attachmentUrl}`, token, userId }); return setParamInUrl({ url: `${server}${attachmentUrl}`, token, userId });
}; };

View File

@ -49,8 +49,9 @@ export const getAvatarURL = ({
query += `&etag=${avatarETag}`; query += `&etag=${avatarETag}`;
} }
if (cdnPrefix) { cdnPrefix = cdnPrefix?.trim();
server = cdnPrefix.trim().replace(/\/+$/, ''); if (cdnPrefix && cdnPrefix.startsWith('http')) {
server = cdnPrefix.replace(/\/+$/, '');
} }
if (avatar) { if (avatar) {