Class: ExtraLocalesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ExtraLocalesController
- Defined in:
- app/controllers/extra_locales_controller.rb
Constant Summary collapse
- OVERRIDES_BUNDLE =
"overrides"
- MD5_HASH_LENGTH =
32
- MF_BUNDLE =
"mf"
- BUNDLES =
[OVERRIDES_BUNDLE, MF_BUNDLE]
Constants inherited from ApplicationController
ApplicationController::CHALLENGE_KEY, ApplicationController::HONEYPOT_KEY, ApplicationController::LEGACY_NO_THEMES, ApplicationController::LEGACY_NO_UNOFFICIAL_PLUGINS, ApplicationController::NO_PLUGINS, ApplicationController::NO_THEMES, ApplicationController::NO_UNOFFICIAL_PLUGINS, ApplicationController::SAFE_MODE
Constants included from CanonicalURL::ControllerExtensions
CanonicalURL::ControllerExtensions::ALLOWED_CANONICAL_PARAMS
Instance Attribute Summary
Attributes inherited from ApplicationController
Class Method Summary collapse
- .bundle_js(bundle) ⇒ Object
- .bundle_js_hash(bundle) ⇒ Object
- .bundle_js_with_hash(bundle) ⇒ Object
- .clear_cache! ⇒ Object
- .client_overrides_exist? ⇒ Boolean
- .js_digests ⇒ Object
- .url(bundle) ⇒ Object
Instance Method Summary collapse
Methods inherited from ApplicationController
#application_layout, #can_cache_content?, #clear_notifications, #conditionally_allow_site_embedding, #current_homepage, #discourse_expires_in, #dont_cache_page, #ember_cli_required?, #fetch_user_from_params, #guardian, #handle_permalink, #handle_theme, #handle_unverified_request, #has_escaped_fragment?, #immutable_for, #login_method, #no_cookies, #perform_refresh_session, #post_ids_including_replies, #preload_json, #rate_limit_second_factor!, #redirect_with_client_support, #render_json_dump, #render_serialized, requires_plugin, #rescue_discourse_actions, #resolve_safe_mode, #secure_session, #serialize_data, #set_current_user_for_logs, #set_layout, #set_mobile_view, #set_mp_snapshot_fields, #show_browser_update?, #store_preloaded, #use_crawler_layout?, #with_resolved_locale
Methods included from VaryHeader
Methods included from ThemeResolver
Methods included from ReadOnlyMixin
#add_readonly_header, #allowed_in_staff_writes_only_mode?, #block_if_readonly_mode, #check_readonly_mode, #get_or_check_readonly_mode, #get_or_check_staff_writes_only_mode, included, #staff_writes_only_mode?
Methods included from Hijack
Methods included from GlobalPath
#cdn_path, #cdn_relative_path, #full_cdn_url, #path, #upload_cdn_path
Methods included from JsonError
Methods included from CanonicalURL::ControllerExtensions
#canonical_url, #default_canonical, included
Methods included from CurrentUser
#clear_current_user, #current_user, has_auth_cookie?, #is_api?, #is_user_api?, #log_off_user, #log_on_user, lookup_from_env, #refresh_session
Class Method Details
.bundle_js(bundle) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/controllers/extra_locales_controller.rb', line 45 def bundle_js(bundle) locale_str = I18n.locale.to_s bundle_str = "#{bundle}_js" case bundle when OVERRIDES_BUNDLE JsLocaleHelper.output_client_overrides(locale_str) when MF_BUNDLE JsLocaleHelper.output_MF(locale_str) else JsLocaleHelper.output_extra_locales(bundle_str, locale_str) end end |
.bundle_js_hash(bundle) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/controllers/extra_locales_controller.rb', line 22 def bundle_js_hash(bundle) bundle_key = "#{bundle}_#{I18n.locale}" if bundle.in?(BUNDLES) site = RailsMultisite::ConnectionManagement.current_db js_digests[site] ||= {} js_digests[site][bundle_key] ||= begin js = bundle_js(bundle) js.present? ? Digest::MD5.hexdigest(js) : nil end else js_digests[bundle_key] ||= Digest::MD5.hexdigest(bundle_js(bundle)) end end |
.bundle_js_with_hash(bundle) ⇒ Object
59 60 61 62 |
# File 'app/controllers/extra_locales_controller.rb', line 59 def bundle_js_with_hash(bundle) js = bundle_js(bundle) [js, Digest::MD5.hexdigest(js)] end |
.clear_cache! ⇒ Object
64 65 66 67 |
# File 'app/controllers/extra_locales_controller.rb', line 64 def clear_cache! site = RailsMultisite::ConnectionManagement.current_db js_digests.delete(site) end |
.client_overrides_exist? ⇒ Boolean
41 42 43 |
# File 'app/controllers/extra_locales_controller.rb', line 41 def client_overrides_exist? bundle_js_hash(OVERRIDES_BUNDLE).present? end |
.js_digests ⇒ Object
18 19 20 |
# File 'app/controllers/extra_locales_controller.rb', line 18 def js_digests @js_digests ||= {} end |
Instance Method Details
#show ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/controllers/extra_locales_controller.rb', line 70 def show bundle = params[:bundle] raise Discourse::InvalidAccess.new if !valid_bundle?(bundle) version = params[:v] if version.present? raise Discourse::InvalidParameters.new(:v) unless version.to_s.size == MD5_HASH_LENGTH end content, hash = ExtraLocalesController.bundle_js_with_hash(bundle) immutable_for(1.year) if hash == version render plain: content, content_type: "application/javascript" end |