verdnatura-chat/app/lib/methods/helpers/formatAttachmentUrl.ts

10 lines
437 B
TypeScript
Raw Normal View History

2022-04-28 18:45:00 +00:00
export const formatAttachmentUrl = (attachmentUrl: string | undefined, userId: string, token: string, server: string): string => {
if (attachmentUrl && attachmentUrl.startsWith('http')) {
if (attachmentUrl.includes('rc_token')) {
return encodeURI(attachmentUrl);
}
return encodeURI(`${attachmentUrl}?rc_uid=${userId}&rc_token=${token}`);
}
return encodeURI(`${server}${attachmentUrl}?rc_uid=${userId}&rc_token=${token}`);
};