docbrown/app/controllers/concerns/api/instances_controller.rb
Fernando Valverde 8c836430ca
API V1 transition (#17835)
* API Articles v0-v1 restructure

* Remove unused helper

* Bulk move API controllers into concerns + add V1 controllers

* Extract API routes + some fixes

* Fix v1 api_controller authenticate! + add more article_controller specs

* Completed spec/requests/api/v1/articles_spec.rb

* specs up to listings

* All v1 specs except for 9 skips

* mime_types cleanup + authenticate! relocation

Co-authored-by: Fernando Valverde <fernando@visualcosita.com>
2022-06-23 14:26:00 -06:00

46 lines
1.6 KiB
Ruby

module Api
module InstancesController
extend ActiveSupport::Concern
def show
render json: {
context: ApplicationConfig["FOREM_CONTEXT"],
cover_image_url: Settings::General.main_social_image,
description: Settings::Community.community_description,
display_in_directory: Settings::UserExperience.display_in_directory,
domain: Settings::General.app_domain,
logo_image_url: Settings::General.logo_png,
name: Settings::Community.community_name,
tagline: Settings::Community.tagline,
version: release_version,
visibility: visibility
}, status: :ok
end
private
def visibility
return "pending" if Settings::General.waiting_on_first_user
Settings::UserExperience.public ? "public" : "private"
end
def release_version
File.read(Rails.root.join(".release-version"))
# Accommodate the .release-version file not existing in the case where
# this deployment is deployed from a checkout/snapshot of the code.
rescue StandardError
# Get the latest modified file in the app. We don't use git in case it's
# being run from a snapshot of the code outside a git repo (for example:
# https://github.com/forem/forem/archive/refs/heads/main.zip), but
# instead we use the latest modified time ("mtime") from application
# code.
latest_mtime = Dir[Rails.root.join("{app,config,db,lib}/**/*")]
.max_by { |filename| File.mtime(filename) }
.then { |filename| File.mtime(filename) }
"edge.#{latest_mtime.strftime('%Y%m%d')}.0"
end
end
end