Proxy letter avatars by default
On sites that don't otherwise configure an avatar fallback, Discourse will now tell the client to get its letter avatars from a location which nginx proxies to the centralised `avatars.discourse.org` service. This alleviates privacy concerns, whilst still providing some degree of performance benefit (no need for every site to delay avatar response by 300ms for image rendering). It is still possible to gain the benefits of global image caching and the lower latency of requesting directly from a CDN, by explicitly changing the `external_system_avatars_url` site setting to `https://avatars.discourse.org/letter/{first_letter}/{color}/{size}.png`.
This commit is contained in:
parent
85daf56ed4
commit
c09f345cff
|
@ -475,6 +475,7 @@ class User < ActiveRecord::Base
|
|||
url.gsub! "{color}", letter_avatar_color(username.downcase)
|
||||
url.gsub! "{username}", username
|
||||
url.gsub! "{first_letter}", username[0].downcase
|
||||
url.gsub! "{hostname}", RailsMultisite::ConnectionManagement.current_hostname
|
||||
url
|
||||
else
|
||||
"#{Discourse.base_uri}/letter_avatar/#{username.downcase}/{size}/#{LetterAvatar.version}.png"
|
||||
|
|
|
@ -192,6 +192,11 @@ server {
|
|||
break;
|
||||
}
|
||||
|
||||
location /letter_avatar_proxy {
|
||||
rewrite /letter_avatar_proxy/(.*)$ /$1 break;
|
||||
proxy_pass https://avatars.discourse.org;
|
||||
}
|
||||
|
||||
# this means every file in public is tried first
|
||||
try_files $uri @discourse;
|
||||
}
|
||||
|
|
|
@ -593,9 +593,9 @@ files:
|
|||
client: true
|
||||
shadowed_by_global: true
|
||||
external_system_avatars_url:
|
||||
default: "https://avatars.discourse.org/v2/letter/{first_letter}/{color}/{size}.png"
|
||||
default: "//{hostname}/letter_avatar_proxy/v2/letter/{first_letter}/{color}/{size}.png"
|
||||
client: true
|
||||
regex: '^https?:\/\/.+[^\/]'
|
||||
regex: '^((https?:)?\/)?\/.+[^\/]'
|
||||
default_opengraph_image_url: ''
|
||||
|
||||
trust:
|
||||
|
|
|
@ -912,7 +912,7 @@ describe User do
|
|||
expect(user.small_avatar_url).to eq("//test.localhost/letter_avatar/sam/45/#{LetterAvatar.version}.png")
|
||||
|
||||
SiteSetting.external_system_avatars_enabled = true
|
||||
expect(user.small_avatar_url).to eq("https://avatars.discourse.org/v2/letter/s/5f9b8f/45.png")
|
||||
expect(user.small_avatar_url).to eq("//test.localhost/letter_avatar_proxy/v2/letter/s/5f9b8f/45.png")
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue