2014-12-22 20:46:10 -05:00
|
|
|
class SiteCustomizationsController < ApplicationController
|
2015-05-20 03:12:16 -04:00
|
|
|
skip_before_filter :preload_json, :check_xhr, :redirect_to_login_if_required
|
2014-12-22 20:46:10 -05:00
|
|
|
|
|
|
|
def show
|
2015-05-22 02:15:46 -04:00
|
|
|
no_cookies
|
|
|
|
|
2015-05-21 03:05:22 -04:00
|
|
|
cache_time = request.env["HTTP_IF_MODIFIED_SINCE"]
|
|
|
|
cache_time = Time.rfc2822(cache_time) rescue nil if cache_time
|
2015-05-21 03:23:54 -04:00
|
|
|
stylesheet_time =
|
|
|
|
begin
|
|
|
|
if params[:key].to_s == SiteCustomization::ENABLED_KEY
|
|
|
|
SiteCustomization.where(enabled: true)
|
|
|
|
.order('created_at desc')
|
|
|
|
.limit(1)
|
|
|
|
.pluck(:created_at)
|
|
|
|
.first
|
|
|
|
else
|
|
|
|
SiteCustomization.where(key: params[:key].to_s).pluck(:created_at).first
|
|
|
|
end
|
|
|
|
end
|
2015-05-21 02:09:23 -04:00
|
|
|
|
2015-05-21 03:05:22 -04:00
|
|
|
if !stylesheet_time
|
|
|
|
raise Discourse::NotFound
|
|
|
|
end
|
|
|
|
|
|
|
|
if cache_time && stylesheet_time <= cache_time
|
2015-05-21 02:09:23 -04:00
|
|
|
return render nothing: true, status: 304
|
|
|
|
end
|
|
|
|
|
2015-05-21 03:05:22 -04:00
|
|
|
response.headers["Last-Modified"] = stylesheet_time.httpdate
|
2014-12-22 20:46:10 -05:00
|
|
|
expires_in 1.year, public: true
|
2015-08-06 17:18:00 -04:00
|
|
|
render text: SiteCustomization.stylesheet_contents(params[:key], params[:target]),
|
2014-12-22 20:46:10 -05:00
|
|
|
content_type: "text/css"
|
|
|
|
end
|
|
|
|
end
|