From 752fe1731e4dc7c7e0494256e95ba0a3bb1a8ff1 Mon Sep 17 00:00:00 2001 From: Renaud Chaput Date: Tue, 7 May 2024 11:42:10 +0200 Subject: [PATCH] Add `icon` field to instance endpoint As we now allow admins to customize their app icon, it may be useful to expose it so apps can use it in the UI. This is using the Android icons as they provide a good range of sizes. --- app/serializers/rest/instance_serializer.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/app/serializers/rest/instance_serializer.rb b/app/serializers/rest/instance_serializer.rb index 8df79db6c77..926d0f069b8 100644 --- a/app/serializers/rest/instance_serializer.rb +++ b/app/serializers/rest/instance_serializer.rb @@ -7,10 +7,12 @@ class REST::InstanceSerializer < ActiveModel::Serializer has_one :account, serializer: REST::AccountSerializer end + include InstanceHelper + include ApplicationHelper include RoutingHelper attributes :domain, :title, :version, :source_url, :description, - :usage, :thumbnail, :languages, :configuration, + :usage, :thumbnail, :icon, :languages, :configuration, :registrations has_one :contact, serializer: ContactSerializer @@ -33,6 +35,18 @@ class REST::InstanceSerializer < ActiveModel::Serializer end end + def icon + SiteUpload::ANDROID_ICON_SIZES.map do |size| + src = app_icon_path(size.to_i) + src = URI.join(root_url, src).to_s if src.present? + + { + src: src || frontend_asset_url("icons/android-chrome-#{size}x#{size}.png"), + size: "#{size}x#{size}", + } + end + end + def usage { users: {