2019-05-02 18:17:27 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-12 10:52:52 -04:00
|
|
|
class ThemesController < ::ApplicationController
|
|
|
|
def assets
|
2018-08-08 00:46:34 -04:00
|
|
|
theme_ids = params[:ids].to_s.split("-").map(&:to_i)
|
2017-04-12 10:52:52 -04:00
|
|
|
|
2018-08-08 00:46:34 -04:00
|
|
|
if params[:ids] == "default"
|
|
|
|
theme_ids = nil
|
2017-04-12 10:52:52 -04:00
|
|
|
else
|
2018-08-08 00:46:34 -04:00
|
|
|
raise Discourse::NotFound unless guardian.allow_themes?(theme_ids)
|
2017-04-12 10:52:52 -04:00
|
|
|
end
|
|
|
|
|
2018-08-08 00:46:34 -04:00
|
|
|
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|
|
2018-08-08 03:58:45 -04:00
|
|
|
next hash unless Rails.env.development?
|
2018-08-08 00:46:34 -04:00
|
|
|
|
|
|
|
dup_hash = hash.dup
|
2019-05-13 10:25:11 -04:00
|
|
|
dup_hash[:new_href] = dup_hash[:new_href].dup
|
2018-08-08 00:46:34 -04:00
|
|
|
dup_hash[:new_href] << (dup_hash[:new_href].include?("?") ? "&" : "?")
|
|
|
|
dup_hash[:new_href] << SecureRandom.hex
|
|
|
|
dup_hash
|
2017-04-12 10:52:52 -04:00
|
|
|
end
|
2018-08-08 00:46:34 -04:00
|
|
|
end.flatten
|
2017-04-12 10:52:52 -04:00
|
|
|
|
|
|
|
render json: object.as_json
|
|
|
|
end
|
|
|
|
end
|