Skip to content

Commit

Permalink
fix: add userId and rcToken on attachmentURL only if protect files is…
Browse files Browse the repository at this point in the history
… enabled (#6078)
  • Loading branch information
OtavioStasiak authored Feb 27, 2025
1 parent 44e19e3 commit 435fdc3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/lib/constants/defaultSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ export const defaultSettings = {
E2E_Enable_Encrypt_Files: {
type: 'valueAsBoolean'
},
FileUpload_ProtectFiles: {
type: 'valueAsBoolean'
},
Accounts_Directory_DefaultView: {
type: 'valueAsString'
},
Expand Down
9 changes: 7 additions & 2 deletions app/lib/methods/helpers/formatAttachmentUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,24 @@ function setParamInUrl({ url, token, userId }: { url: string; token: string; use
}

export const formatAttachmentUrl = (attachmentUrl: string | undefined, userId: string, token: string, server: string): string => {
const protectFiles = store.getState().settings.FileUpload_ProtectFiles;

if ((attachmentUrl && isImageBase64(attachmentUrl)) || attachmentUrl?.startsWith('file://')) {
return attachmentUrl;
}
if (attachmentUrl && attachmentUrl.startsWith('http')) {
if (attachmentUrl.includes('rc_token')) {
return encodeURI(attachmentUrl);
}
return setParamInUrl({ url: attachmentUrl, token, userId });

if (protectFiles) return setParamInUrl({ url: attachmentUrl, token, userId });
return attachmentUrl;
}
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 });
if (protectFiles) return setParamInUrl({ url: `${server}${attachmentUrl}`, token, userId });
return `${server}${attachmentUrl}`;
};

0 comments on commit 435fdc3

Please sign in to comment.