discourse/app/controllers/themes_controller.rb
Sam Saffron 30990006a9 DEV: enable frozen string literal on all files
This reduces chances of errors where consumers of strings mutate inputs
and reduces memory usage of the app.

Test suite passes now, but there may be some stuff left, so we will run
a few sites on a branch prior to merging
2019-05-13 09:31:32 +08:00

30 lines
840 B
Ruby

# frozen_string_literal: true
class ThemesController < ::ApplicationController
def assets
theme_ids = params[:ids].to_s.split("-").map(&:to_i)
if params[:ids] == "default"
theme_ids = nil
else
raise Discourse::NotFound unless guardian.allow_themes?(theme_ids)
end
targets = view_context.mobile_view? ? [:mobile, :mobile_theme] : [:desktop, :desktop_theme]
targets << :admin if guardian.is_staff?
object = targets.map do |target|
Stylesheet::Manager.stylesheet_data(target, theme_ids).map do |hash|
next hash unless Rails.env.development?
dup_hash = hash.dup
dup_hash[:new_href] << (dup_hash[:new_href].include?("?") ? "&" : "?")
dup_hash[:new_href] << SecureRandom.hex
dup_hash
end
end.flatten
render json: object.as_json
end
end