mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 01:32:23 +08:00
d6d4a5ba4a
* First take * Add support for sprites in themes Automatically register any custom icons added via themes or plugins * Fix theme sprite caching * Simplify test * Update lib/svg_sprite/svg_sprite.rb Co-Authored-By: pmusaraj <pmusaraj@gmail.com> * Fix /svg-sprite/search request
43 lines
1.2 KiB
Ruby
43 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class SvgSpriteController < ApplicationController
|
|
skip_before_action :preload_json, :redirect_to_login_if_required, :check_xhr, :verify_authenticity_token, only: [:show, :search]
|
|
|
|
requires_login except: [:show]
|
|
|
|
def show
|
|
|
|
no_cookies
|
|
|
|
RailsMultisite::ConnectionManagement.with_hostname(params[:hostname]) do
|
|
theme_ids = params[:theme_ids].split(",").map(&:to_i)
|
|
|
|
if SvgSprite.version(theme_ids) != params[:version]
|
|
return redirect_to path(SvgSprite.path(theme_ids))
|
|
end
|
|
|
|
svg_sprite = "window.__svg_sprite = #{SvgSprite.bundle(theme_ids).inspect};"
|
|
|
|
response.headers["Last-Modified"] = 10.years.ago.httpdate
|
|
response.headers["Content-Length"] = svg_sprite.bytesize.to_s
|
|
immutable_for 1.year
|
|
|
|
render plain: svg_sprite, disposition: nil, content_type: 'application/javascript'
|
|
end
|
|
end
|
|
|
|
def search
|
|
RailsMultisite::ConnectionManagement.with_hostname(params[:hostname]) do
|
|
|
|
keyword = params.require(:keyword)
|
|
data = SvgSprite.search(keyword)
|
|
|
|
if data.blank?
|
|
render body: nil, status: 404
|
|
else
|
|
render plain: data.inspect, disposition: nil, content_type: 'text/plain'
|
|
end
|
|
end
|
|
end
|
|
end
|