2019-05-02 01:57:12 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-13 12:29:53 -06:00
|
|
|
class MetadataController < ApplicationController
|
2015-09-20 10:00:30 -05:00
|
|
|
layout false
|
2024-06-25 06:32:18 -05:00
|
|
|
skip_before_action :preload_json,
|
|
|
|
:check_xhr,
|
|
|
|
:redirect_to_login_if_required,
|
|
|
|
:redirect_to_profile_if_required
|
2015-09-20 10:00:30 -05:00
|
|
|
|
2016-02-13 12:29:53 -06:00
|
|
|
def manifest
|
2020-06-30 21:58:02 -05:00
|
|
|
expires_in 1.minutes
|
2018-06-13 22:13:28 -05:00
|
|
|
render json: default_manifest.to_json, content_type: "application/manifest+json"
|
2016-06-29 23:03:52 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def opensearch
|
2020-06-30 21:58:02 -05:00
|
|
|
expires_in 1.minutes
|
2021-04-21 04:36:32 -05:00
|
|
|
render template: "metadata/opensearch", formats: [:xml]
|
2016-06-29 23:03:52 -05:00
|
|
|
end
|
|
|
|
|
2019-08-27 13:05:37 -05:00
|
|
|
def app_association_android
|
2024-05-27 05:27:13 -05:00
|
|
|
raise Discourse::NotFound if SiteSetting.app_association_android.blank?
|
2020-06-30 21:58:02 -05:00
|
|
|
expires_in 1.minutes
|
2019-08-27 13:05:37 -05:00
|
|
|
render plain: SiteSetting.app_association_android, content_type: "application/json"
|
|
|
|
end
|
|
|
|
|
|
|
|
def app_association_ios
|
2024-05-27 05:27:13 -05:00
|
|
|
raise Discourse::NotFound if SiteSetting.app_association_ios.blank?
|
2020-06-30 21:58:02 -05:00
|
|
|
expires_in 1.minutes
|
2019-08-27 13:05:37 -05:00
|
|
|
render plain: SiteSetting.app_association_ios, content_type: "application/json"
|
|
|
|
end
|
|
|
|
|
2016-06-29 23:03:52 -05:00
|
|
|
private
|
|
|
|
|
|
|
|
def default_manifest
|
2019-11-27 20:13:13 -06:00
|
|
|
display = "standalone"
|
|
|
|
if request.user_agent
|
|
|
|
regex = Regexp.new(SiteSetting.pwa_display_browser_regex)
|
|
|
|
display = "browser" if regex.match(request.user_agent)
|
|
|
|
end
|
2018-08-15 21:36:08 -05:00
|
|
|
|
2020-06-01 23:04:02 -05:00
|
|
|
scheme_id = view_context.scheme_id
|
|
|
|
primary_color = ColorScheme.hex_for_name("primary", scheme_id)
|
2020-05-14 14:32:53 -05:00
|
|
|
icon_url_base =
|
|
|
|
UrlHelper.absolute("/svg-sprite/#{Discourse.current_hostname}/icon/#{primary_color}")
|
|
|
|
|
2017-01-03 11:50:45 -06:00
|
|
|
manifest = {
|
2016-04-20 09:54:01 -05:00
|
|
|
name: SiteSetting.title,
|
2020-02-04 11:16:00 -06:00
|
|
|
short_name:
|
|
|
|
SiteSetting.short_title.presence ||
|
|
|
|
SiteSetting.title.truncate(12, separator: " ", omission: ""),
|
2021-02-25 15:23:19 -06:00
|
|
|
description: SiteSetting.site_description,
|
2018-08-15 21:36:08 -05:00
|
|
|
display: display,
|
2023-02-03 13:48:05 -06:00
|
|
|
start_url: Discourse.base_path.present? ? "#{Discourse.base_path}/" : "/",
|
2020-06-01 23:04:02 -05:00
|
|
|
background_color: "##{ColorScheme.hex_for_name("secondary", scheme_id)}",
|
|
|
|
theme_color: "##{ColorScheme.hex_for_name("header_background", scheme_id)}",
|
2016-04-20 09:54:01 -05:00
|
|
|
icons: [],
|
2018-12-07 09:48:09 -06:00
|
|
|
share_target: {
|
2020-10-09 05:40:40 -05:00
|
|
|
action: "#{Discourse.base_path}/new-topic",
|
2019-03-15 15:10:05 -05:00
|
|
|
method: "GET",
|
|
|
|
enctype: "application/x-www-form-urlencoded",
|
2018-12-07 09:48:09 -06:00
|
|
|
params: {
|
|
|
|
title: "title",
|
|
|
|
text: "body",
|
|
|
|
},
|
2020-05-12 10:24:33 -05:00
|
|
|
},
|
|
|
|
shortcuts: [
|
|
|
|
{
|
|
|
|
name: I18n.t("js.topic.create_long"),
|
|
|
|
short_name: I18n.t("js.topic.create"),
|
2020-10-09 05:40:40 -05:00
|
|
|
url: "#{Discourse.base_path}/new-topic",
|
2020-05-12 10:24:33 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: I18n.t("js.user.messages.inbox"),
|
|
|
|
short_name: I18n.t("js.user.messages.inbox"),
|
2020-10-09 05:40:40 -05:00
|
|
|
url: "#{Discourse.base_path}/my/messages",
|
2020-05-12 10:24:33 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: I18n.t("js.user.bookmarks"),
|
|
|
|
short_name: I18n.t("js.user.bookmarks"),
|
2021-03-14 23:36:50 -05:00
|
|
|
url: "#{Discourse.base_path}/my/activity/bookmarks",
|
2020-05-12 10:24:33 -05:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: I18n.t("js.filters.top.title"),
|
|
|
|
short_name: I18n.t("js.filters.top.title"),
|
2020-10-09 05:40:40 -05:00
|
|
|
url: "#{Discourse.base_path}/top",
|
2020-05-12 10:24:33 -05:00
|
|
|
},
|
|
|
|
],
|
2015-09-20 10:00:30 -05:00
|
|
|
}
|
2017-01-03 11:50:45 -06:00
|
|
|
|
2019-05-01 08:44:45 -05:00
|
|
|
logo = SiteSetting.site_manifest_icon_url
|
2019-09-21 23:20:25 -05:00
|
|
|
if logo
|
|
|
|
icon_entry = {
|
|
|
|
src: UrlHelper.absolute(logo),
|
|
|
|
sizes: "512x512",
|
|
|
|
type: MiniMime.lookup_by_filename(logo)&.content_type || "image/png",
|
|
|
|
}
|
|
|
|
manifest[:icons] << icon_entry.dup
|
|
|
|
icon_entry[:purpose] = "maskable"
|
|
|
|
manifest[:icons] << icon_entry
|
|
|
|
end
|
2019-05-01 08:44:45 -05:00
|
|
|
|
2021-03-04 15:39:58 -06:00
|
|
|
SiteSetting
|
|
|
|
.manifest_screenshots
|
|
|
|
.split("|")
|
|
|
|
.each do |image|
|
|
|
|
next unless Discourse.store.has_been_uploaded?(image)
|
|
|
|
|
|
|
|
upload = Upload.find_by(sha1: Upload.extract_sha1(image))
|
|
|
|
next if upload.nil?
|
|
|
|
|
|
|
|
manifest[:screenshots] = [] if manifest.dig(:screenshots).nil?
|
|
|
|
|
|
|
|
manifest[:screenshots] << {
|
|
|
|
src: UrlHelper.absolute(image),
|
|
|
|
sizes: "#{upload.width}x#{upload.height}",
|
|
|
|
type: "image/#{upload.extension}",
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-04-17 11:25:13 -05:00
|
|
|
if current_user && current_user.trust_level >= 1 &&
|
|
|
|
SiteSetting.native_app_install_banner_android
|
2017-01-03 11:50:45 -06:00
|
|
|
manifest =
|
|
|
|
manifest.merge(
|
|
|
|
prefer_related_applications: true,
|
2019-04-17 11:25:13 -05:00
|
|
|
related_applications: [{ platform: "play", id: SiteSetting.android_app_id }],
|
2017-01-03 11:50:45 -06:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
manifest
|
2016-02-13 12:29:53 -06:00
|
|
|
end
|
2015-09-20 10:00:30 -05:00
|
|
|
end
|