2015-05-05 01:50:13 -04:00
|
|
|
class StylesheetsController < ApplicationController
|
|
|
|
skip_before_filter :preload_json, :redirect_to_login_if_required, :check_xhr, :verify_authenticity_token, only: [:show]
|
|
|
|
|
|
|
|
def show
|
|
|
|
|
|
|
|
target,digest = params[:name].split("_")
|
|
|
|
|
2015-05-05 17:33:32 -04:00
|
|
|
digest_orig = digest
|
2015-05-05 01:50:13 -04:00
|
|
|
digest = "_" + digest if digest
|
|
|
|
|
|
|
|
# Security note, safe due to route constraint
|
2015-05-05 09:28:19 -04:00
|
|
|
location = "#{Rails.root}/#{DiscourseStylesheets::CACHE_PATH}/#{target}#{digest}.css"
|
2015-05-05 01:50:13 -04:00
|
|
|
|
|
|
|
unless File.exist?(location)
|
|
|
|
query = StylesheetCache.where(target: target)
|
|
|
|
if digest
|
2015-05-05 17:33:32 -04:00
|
|
|
query = query.where(digest: digest_orig)
|
2015-05-05 01:50:13 -04:00
|
|
|
else
|
|
|
|
query = query.order('id desc')
|
|
|
|
end
|
|
|
|
|
|
|
|
if current = query.first
|
|
|
|
File.write(location, current.content)
|
|
|
|
else
|
|
|
|
return render nothing: true, status: 404
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expires_in 1.year, public: true unless Rails.env == "development"
|
|
|
|
send_file(location, disposition: :inline)
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|