2016-02-14 02:29:53 +08:00
|
|
|
class MetadataController < ApplicationController
|
2015-09-20 23:00:30 +08:00
|
|
|
layout false
|
2017-08-31 12:06:56 +08:00
|
|
|
skip_before_action :preload_json, :check_xhr, :redirect_to_login_if_required
|
2015-09-20 23:00:30 +08:00
|
|
|
|
2016-02-14 02:29:53 +08:00
|
|
|
def manifest
|
2018-06-14 11:13:28 +08:00
|
|
|
render json: default_manifest.to_json, content_type: 'application/manifest+json'
|
2016-06-30 12:03:52 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def opensearch
|
|
|
|
render file: "#{Rails.root}/app/views/metadata/opensearch.xml"
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def default_manifest
|
2018-11-14 15:03:02 +08:00
|
|
|
logo = SiteSetting.site_large_icon_url.presence ||
|
|
|
|
SiteSetting.site_logo_small_url.presence ||
|
|
|
|
SiteSetting.site_apple_touch_icon_url.presence
|
|
|
|
|
2018-05-22 10:10:59 +08:00
|
|
|
if !logo
|
2018-11-14 15:03:02 +08:00
|
|
|
logo = '/images/d-logo-sketch-small.png'
|
2018-05-22 10:10:59 +08:00
|
|
|
end
|
2018-11-14 15:03:02 +08:00
|
|
|
|
2018-05-18 05:43:22 +08:00
|
|
|
file_info = get_file_info(logo)
|
2017-11-01 11:51:51 +08:00
|
|
|
|
2018-10-27 00:47:22 +08:00
|
|
|
display = Regexp.new(SiteSetting.pwa_display_browser_regex).match(request.user_agent) ? 'browser' : 'standalone'
|
2018-08-16 10:36:08 +08:00
|
|
|
|
2017-01-04 01:50:45 +08:00
|
|
|
manifest = {
|
2016-04-20 22:54:01 +08:00
|
|
|
name: SiteSetting.title,
|
2018-08-16 10:36:08 +08:00
|
|
|
display: display,
|
2018-06-16 01:29:33 +08:00
|
|
|
start_url: Discourse.base_uri.present? ? "#{Discourse.base_uri}/" : '.',
|
2018-09-12 09:04:58 +08:00
|
|
|
background_color: "##{ColorScheme.hex_for_name('secondary', view_context.scheme_id)}",
|
|
|
|
theme_color: "##{ColorScheme.hex_for_name('header_background', view_context.scheme_id)}",
|
2016-04-20 22:54:01 +08:00
|
|
|
icons: [
|
|
|
|
{
|
2018-11-14 15:03:02 +08:00
|
|
|
src: UrlHelper.absolute(logo),
|
2018-05-18 05:43:22 +08:00
|
|
|
sizes: file_info[:size],
|
|
|
|
type: file_info[:type]
|
2016-04-20 22:54:01 +08:00
|
|
|
}
|
2018-12-07 23:48:09 +08:00
|
|
|
],
|
|
|
|
share_target: {
|
|
|
|
action: "/new-topic",
|
|
|
|
params: {
|
|
|
|
title: "title",
|
|
|
|
text: "body"
|
|
|
|
}
|
|
|
|
}
|
2015-09-20 23:00:30 +08:00
|
|
|
}
|
2017-01-04 01:50:45 +08:00
|
|
|
|
2018-11-28 21:55:52 +08:00
|
|
|
manifest[:short_name] = SiteSetting.short_title if SiteSetting.short_title.present?
|
|
|
|
|
2017-01-04 01:50:45 +08:00
|
|
|
if SiteSetting.native_app_install_banner
|
2017-07-28 09:20:09 +08:00
|
|
|
manifest = manifest.merge(
|
2017-01-04 01:50:45 +08:00
|
|
|
prefer_related_applications: true,
|
|
|
|
related_applications: [
|
|
|
|
{
|
|
|
|
platform: "play",
|
|
|
|
id: "com.discourse"
|
|
|
|
}
|
|
|
|
]
|
2017-07-28 09:20:09 +08:00
|
|
|
)
|
2017-01-04 01:50:45 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
manifest
|
2016-02-14 02:29:53 +08:00
|
|
|
end
|
2018-05-18 03:10:35 +08:00
|
|
|
|
2018-05-18 05:43:22 +08:00
|
|
|
def get_file_info(filename)
|
|
|
|
type = MiniMime.lookup_by_filename(filename)&.content_type || "image/png"
|
|
|
|
upload = Upload.find_by_url(filename)
|
|
|
|
{ size: "#{upload&.width || 512}x#{upload&.height || 512}", type: type }
|
2018-05-18 03:10:35 +08:00
|
|
|
end
|
|
|
|
|
2015-09-20 23:00:30 +08:00
|
|
|
end
|