FIX: favicon update broken when favicon lived on a CDN

This commit is contained in:
Sam
2015-08-25 11:54:23 +10:00
parent d74d5c47ad
commit 2c59ad3dd3
6 changed files with 37 additions and 6 deletions

View File

@@ -57,7 +57,11 @@ window.Discourse = Ember.Application.createWithMixins(Discourse.Ajax, {
faviconChanged: function() {
if(Discourse.User.currentProp('dynamic_favicon')) {
new Favcount(Discourse.SiteSettings.favicon_url).set(
var url = Discourse.SiteSettings.favicon_url;
if (/^http/.test(url)) {
url = Discourse.getURL("/favicon/proxied?" + encodeURIComponent(url));
}
new Favcount(url).set(
this.get('notifyCount')
);
}

View File

@@ -1,7 +1,10 @@
require_dependency 'distributed_memoizer'
require_dependency 'file_helper'
class StaticController < ApplicationController
skip_before_filter :check_xhr, :redirect_to_login_if_required
skip_before_filter :verify_authenticity_token, only: [:enter]
skip_before_filter :verify_authenticity_token, only: [:cdn_asset, :enter, :favicon]
def show
return redirect_to(path '/') if current_user && params[:id] == 'login'
@@ -82,7 +85,28 @@ class StaticController < ApplicationController
redirect_to destination
end
skip_before_filter :verify_authenticity_token, only: [:cdn_asset]
# We need to be able to draw our favicon on a canvas
# and pull it off the canvas into a data uri
# This can work by ensuring people set all the right CORS
# settings in the CDN asset, BUT its annoying and error prone
# instead we cache the favicon in redis and serve it out real quick with
# a huge expiry, we also cache these assets in nginx so it bypassed if needed
def favicon
data = DistributedMemoizer.memoize('favicon' + SiteSetting.favicon_url, 60*60*24) do
file = FileHelper.download(SiteSetting.favicon_url, 50.kilobytes, "favicon.png")
data = file.read
file.unlink
data
end
expires_in 1.year, public: true
response.headers["Expires"] = 1.year.from_now.httpdate
response.headers["Content-Length"] = data.bytesize.to_s
response.headers["Last-Modified"] = Time.new('2000-01-01').httpdate
render text: data, content_type: "image/png"
end
def cdn_asset
path = File.expand_path(Rails.root + "public/assets/" + params[:path])