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
|
2016-06-30 12:03:52 +08:00
|
|
|
render json: default_manifest.to_json
|
|
|
|
end
|
|
|
|
|
|
|
|
def opensearch
|
|
|
|
render file: "#{Rails.root}/app/views/metadata/opensearch.xml"
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def default_manifest
|
2017-11-03 13:19:31 +08:00
|
|
|
logo = SiteSetting.large_icon_url.presence || SiteSetting.logo_small_url.presence || SiteSetting.apple_touch_icon_url.presence
|
2018-05-22 10:10:59 +08:00
|
|
|
if !logo
|
|
|
|
logo = path('/images/d-logo-sketch-small.png')
|
|
|
|
end
|
2018-05-18 05:43:22 +08:00
|
|
|
file_info = get_file_info(logo)
|
2017-11-01 11:51:51 +08:00
|
|
|
|
2017-01-04 01:50:45 +08:00
|
|
|
manifest = {
|
2016-04-20 22:54:01 +08:00
|
|
|
name: SiteSetting.title,
|
2015-09-20 23:00:30 +08:00
|
|
|
short_name: SiteSetting.title,
|
2016-03-21 10:18:40 +08:00
|
|
|
display: 'standalone',
|
2017-02-13 02:04:06 +08:00
|
|
|
orientation: 'natural',
|
2016-03-21 10:18:40 +08:00
|
|
|
start_url: "#{Discourse.base_uri}/",
|
2018-04-20 04:00:05 +08:00
|
|
|
share_target: {
|
|
|
|
url_template: 'new-topic?title={title}&body={text}%0A%0A{url}'
|
|
|
|
},
|
2016-03-21 10:18:40 +08:00
|
|
|
background_color: "##{ColorScheme.hex_for_name('secondary')}",
|
2016-04-20 22:54:01 +08:00
|
|
|
theme_color: "##{ColorScheme.hex_for_name('header_background')}",
|
|
|
|
icons: [
|
|
|
|
{
|
2017-11-01 11:51:51 +08:00
|
|
|
src: 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
|
|
|
}
|
|
|
|
]
|
2015-09-20 23:00:30 +08:00
|
|
|
}
|
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
|