diff --git a/app/lib/methods/helpers/formatAttachmentUrl.ts b/app/lib/methods/helpers/formatAttachmentUrl.ts index 143188594..b40a2b87c 100644 --- a/app/lib/methods/helpers/formatAttachmentUrl.ts +++ b/app/lib/methods/helpers/formatAttachmentUrl.ts @@ -24,9 +24,10 @@ export const formatAttachmentUrl = (attachmentUrl: string | undefined, userId: s } return setParamInUrl({ url: attachmentUrl, token, userId }); } - const cdnPrefix = store?.getState().settings.CDN_PREFIX as string; - if (cdnPrefix) { - server = cdnPrefix.trim().replace(/\/+$/, ''); + let cdnPrefix = store?.getState().settings.CDN_PREFIX as string; + cdnPrefix = cdnPrefix?.trim(); + if (cdnPrefix && cdnPrefix.startsWith('http')) { + server = cdnPrefix.replace(/\/+$/, ''); } return setParamInUrl({ url: `${server}${attachmentUrl}`, token, userId }); }; diff --git a/app/lib/methods/helpers/getAvatarUrl.ts b/app/lib/methods/helpers/getAvatarUrl.ts index 1702369ef..91f10b62b 100644 --- a/app/lib/methods/helpers/getAvatarUrl.ts +++ b/app/lib/methods/helpers/getAvatarUrl.ts @@ -49,8 +49,9 @@ export const getAvatarURL = ({ query += `&etag=${avatarETag}`; } - if (cdnPrefix) { - server = cdnPrefix.trim().replace(/\/+$/, ''); + cdnPrefix = cdnPrefix?.trim(); + if (cdnPrefix && cdnPrefix.startsWith('http')) { + server = cdnPrefix.replace(/\/+$/, ''); } if (avatar) {