From 7c0a2692dc0ccbb56f143b81e12d2f0d154a0cab Mon Sep 17 00:00:00 2001 From: Reinaldo Neto <47038980+reinaldonetof@users.noreply.github.com> Date: Mon, 11 Dec 2023 12:35:33 -0300 Subject: [PATCH] fix: handle cdnPrefix without protocol (#5373) * fix: handle cdnPrefix without protocol * cdnPrefix trim --- app/lib/methods/helpers/formatAttachmentUrl.ts | 7 ++++--- app/lib/methods/helpers/getAvatarUrl.ts | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) 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) {