today_ai_weather/app/controllers/application_controller.rb

56 lines
2.0 KiB
Ruby
Raw Normal View History

2025-01-19 01:13:59 +08:00
class ApplicationController < ActionController::Base
include SeoConcern
2025-01-19 01:13:59 +08:00
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
2025-01-27 06:53:01 +08:00
# allow_browser versions: :modern
2025-01-27 07:49:08 +08:00
allow_browser versions: :modern do |config|
2025-01-27 07:40:13 +08:00
# 通用移动浏览器
config.allow(/Mobile Safari/) # iOS Safari
config.allow(/Chrome\/[\d.]+/) # Chrome 内核浏览器
# 国内主流浏览器
config.allow(/Quark\/[\d.]+/) # 夸克浏览器
config.allow(/HuaweiBrowser\/[\d.]+/) # 华为浏览器
config.allow(/MiuiBrowser\/[\d.]+/) # 小米浏览器
config.allow(/VivoBrowser\/[\d.]+/) # vivo浏览器
config.allow(/OppoBrowser\/[\d.]+/) # OPPO浏览器
config.allow(/UCBrowser\/[\d.]+/) # UC浏览器
config.allow(/QQBrowser\/[\d.]+/) # QQ浏览器
config.allow(/MicroMessenger\/[\d.]+/) # 微信内置浏览器
config.allow(/Alipay/) # 支付宝内置浏览器
config.allow(/BaiduBoxApp/) # 百度 App
config.allow(/baiduboxapp/i) # 百度 App (小写)
config.allow(/SogouMobile/) # 搜狗移动浏览器
config.allow(/Weibo/) # 微博内置浏览器
config.allow(/DingTalk/) # 钉钉内置浏览器
config.allow(/ToutiaoMicroApp/) # 今日头条小程序
config.allow(/BytedanceWebview/) # 字节跳动系浏览器
config.allow(/ArkWeb/) # 鸿蒙浏览器
# 调试日志(开发环境)
if Rails.env.development?
config.on_failure do |browser|
Rails.logger.info <<~INFO
Browser blocked:
Name: #{browser.name}
Version: #{browser.version}
User Agent: #{browser.ua}
INFO
end
end
end
before_action :set_locale
after_action :track_action
protected
def track_action
ahoy.track "Viewed Application", request.path_parameters
end
private
def set_locale
I18n.locale = params[:locale] || I18n.default_locale
end
2025-01-19 01:13:59 +08:00
end