2015-03-13 00:15:13 -05:00
|
|
|
class HighlightJsController < ApplicationController
|
2015-05-20 02:12:16 -05:00
|
|
|
skip_before_filter :preload_json, :redirect_to_login_if_required, :check_xhr, :verify_authenticity_token, only: [:show]
|
2015-03-13 00:15:13 -05:00
|
|
|
|
|
|
|
def show
|
2015-05-22 01:15:46 -05:00
|
|
|
|
|
|
|
no_cookies
|
|
|
|
|
2015-03-13 00:15:13 -05:00
|
|
|
RailsMultisite::ConnectionManagement.with_hostname(params[:hostname]) do
|
|
|
|
|
|
|
|
current_version = HighlightJs.version(SiteSetting.highlighted_languages)
|
|
|
|
|
|
|
|
if current_version != params[:version]
|
|
|
|
return redirect_to path(HighlightJs.path)
|
|
|
|
end
|
|
|
|
|
|
|
|
# note, this can be slightly optimised by caching the bundled file, it cuts down on N reads
|
|
|
|
# our nginx config caches this so in practical terms it does not really matter and keeps
|
|
|
|
# code simpler
|
|
|
|
highlight_js = HighlightJs.bundle(SiteSetting.highlighted_languages.split("|"))
|
|
|
|
|
|
|
|
response.headers["Last-Modified"] = 10.years.ago.httpdate
|
|
|
|
response.headers["Content-Length"] = highlight_js.bytesize.to_s
|
2017-02-23 12:05:00 -06:00
|
|
|
immutable_for 1.year
|
2015-03-13 00:15:13 -05:00
|
|
|
|
|
|
|
render text: highlight_js, disposition: nil, content_type: 'application/javascript'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|