Skip to content
Snippets Groups Projects
Unverified Commit fdde637f authored by Tasso Evangelista's avatar Tasso Evangelista Committed by GitHub
Browse files

fix: Local avatars prioritized over external avatar provider and remove...

fix: Local avatars prioritized over external avatar provider and remove remnant references on client of `Accounts_AvatarExternalProviderUrl` (#33296)

Co-authored-by: default avatargabriellsh <40830821+gabriellsh@users.noreply.github.com>
parent 9a38c8e1
No related branches found
No related tags found
No related merge requests found
---
'@rocket.chat/meteor': patch
---
Fixed remaining direct references to external user avatar URLs
Fixed local avatars having priority over external provider
It mainly corrects the behavior of E2E encryption messages and desktop notifications.
import { settings } from '../../settings/client';
import { getAvatarURL } from './getAvatarURL';
export const getUserAvatarURL = function (username: string, cache = ''): string | undefined {
const externalSource = (settings.get<string>('Accounts_AvatarExternalProviderUrl') || '').trim().replace(/\/$/, '');
if (externalSource !== '') {
return externalSource.replace('{username}', username);
}
if (username == null) {
return;
}
......
import { settings } from '../../settings/server';
import { getAvatarURL } from './getAvatarURL';
export const getUserAvatarURL = function (username: string, cache = ''): string | undefined {
const externalSource = (settings.get<string>('Accounts_AvatarExternalProviderUrl') || '').trim().replace(/\/$/, '');
if (externalSource !== '') {
return externalSource.replace('{username}', username);
}
if (username == null) {
return;
}
......
import { AvatarUrlContext, useSetting } from '@rocket.chat/ui-contexts';
import { AvatarUrlContext } from '@rocket.chat/ui-contexts';
import type { ReactNode } from 'react';
import React, { useMemo } from 'react';
......@@ -10,19 +10,15 @@ type AvatarUrlProviderProps = {
};
const AvatarUrlProvider = ({ children }: AvatarUrlProviderProps) => {
const cdnAvatarUrl = String(useSetting('CDN_PREFIX') || '');
const contextValue = useMemo(
() => ({
getUserPathAvatar: ((): ((uid: string, etag?: string) => string) => {
if (cdnAvatarUrl) {
return (uid: string, etag?: string): string => `${cdnAvatarUrl}/avatar/${uid}${etag ? `?etag=${etag}` : ''}`;
}
return (uid: string, etag?: string): string => getURL(`/avatar/${uid}${etag ? `?etag=${etag}` : ''}`);
})(),
getRoomPathAvatar: ({ type, ...room }: any): string =>
roomCoordinator.getRoomDirectives(type || room.t).getAvatarPath({ username: room._id, ...room }) || '',
}),
[cdnAvatarUrl],
[],
);
return <AvatarUrlContext.Provider children={children} value={contextValue} />;
......
......@@ -32,6 +32,13 @@ export const userAvatar = async function (req, res) {
return;
}
if (settings.get('Accounts_AvatarExternalProviderUrl')) {
const response = await fetch(settings.get('Accounts_AvatarExternalProviderUrl').replace('{username}', requestUsername));
response.headers.forEach((value, key) => res.setHeader(key, value));
response.body.pipe(res);
return;
}
const reqModifiedHeader = req.headers['if-modified-since'];
const file = await Avatars.findOneByName(requestUsername);
......@@ -52,13 +59,6 @@ export const userAvatar = async function (req, res) {
return FileUpload.get(file, req, res);
}
if (settings.get('Accounts_AvatarExternalProviderUrl')) {
const response = await fetch(settings.get('Accounts_AvatarExternalProviderUrl').replace('{username}', requestUsername));
response.headers.forEach((value, key) => res.setHeader(key, value));
response.body.pipe(res);
return;
}
// if still using "letters fallback"
if (!wasFallbackModified(reqModifiedHeader, res)) {
res.writeHead(304);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment