update files consistency after rebase
This commit is contained in:
parent
3c8c540707
commit
207211a2b3
8 changed files with 0 additions and 0 deletions
59
lib/pleroma/web/preload/providers/instance.ex
Normal file
59
lib/pleroma/web/preload/providers/instance.ex
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Preload.Providers.Instance do
|
||||
alias Pleroma.Plugs.InstanceStatic
|
||||
alias Pleroma.Web.MastodonAPI.InstanceView
|
||||
alias Pleroma.Web.Nodeinfo.Nodeinfo
|
||||
alias Pleroma.Web.Preload.Providers.Provider
|
||||
alias Pleroma.Web.TwitterAPI.UtilView
|
||||
|
||||
@behaviour Provider
|
||||
@instance_url "/api/v1/instance"
|
||||
@panel_url "/instance/panel.html"
|
||||
@nodeinfo_url "/nodeinfo/2.0.json"
|
||||
@fe_config_url "/api/pleroma/frontend_configurations"
|
||||
|
||||
@impl Provider
|
||||
def generate_terms(_params) do
|
||||
%{}
|
||||
|> build_info_tag()
|
||||
|> build_panel_tag()
|
||||
|> build_nodeinfo_tag()
|
||||
|> build_fe_config_tag()
|
||||
end
|
||||
|
||||
defp build_info_tag(acc) do
|
||||
info_data = InstanceView.render("show.json", %{})
|
||||
|
||||
Map.put(acc, @instance_url, info_data)
|
||||
end
|
||||
|
||||
defp build_panel_tag(acc) do
|
||||
instance_path = InstanceStatic.file_path(@panel_url |> to_string())
|
||||
|
||||
if File.exists?(instance_path) do
|
||||
panel_data = File.read!(instance_path)
|
||||
Map.put(acc, @panel_url, panel_data)
|
||||
else
|
||||
acc
|
||||
end
|
||||
end
|
||||
|
||||
defp build_nodeinfo_tag(acc) do
|
||||
case Nodeinfo.get_nodeinfo("2.0") do
|
||||
{:error, _} ->
|
||||
acc
|
||||
|
||||
nodeinfo_data ->
|
||||
Map.put(acc, @nodeinfo_url, nodeinfo_data)
|
||||
end
|
||||
end
|
||||
|
||||
defp build_fe_config_tag(acc) do
|
||||
fe_data = UtilView.render("frontend_configurations.json", %{})
|
||||
|
||||
Map.put(acc, @fe_config_url, fe_data)
|
||||
end
|
||||
end
|
||||
7
lib/pleroma/web/preload/providers/provider.ex
Normal file
7
lib/pleroma/web/preload/providers/provider.ex
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Preload.Providers.Provider do
|
||||
@callback generate_terms(map()) :: map()
|
||||
end
|
||||
39
lib/pleroma/web/preload/providers/timelines.ex
Normal file
39
lib/pleroma/web/preload/providers/timelines.ex
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Preload.Providers.Timelines do
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
alias Pleroma.Web.MastodonAPI.StatusView
|
||||
alias Pleroma.Web.Preload.Providers.Provider
|
||||
|
||||
@behaviour Provider
|
||||
@public_url "/api/v1/timelines/public"
|
||||
|
||||
@impl Provider
|
||||
def generate_terms(params) do
|
||||
build_public_tag(%{}, params)
|
||||
end
|
||||
|
||||
def build_public_tag(acc, params) do
|
||||
if Pleroma.Config.restrict_unauthenticated_access?(:timelines, :federated) do
|
||||
acc
|
||||
else
|
||||
Map.put(acc, @public_url, public_timeline(params))
|
||||
end
|
||||
end
|
||||
|
||||
defp public_timeline(%{"path" => ["main", "all"]}), do: get_public_timeline(false)
|
||||
|
||||
defp public_timeline(_params), do: get_public_timeline(true)
|
||||
|
||||
defp get_public_timeline(local_only) do
|
||||
activities =
|
||||
ActivityPub.fetch_public_activities(%{
|
||||
type: ["Create"],
|
||||
local_only: local_only
|
||||
})
|
||||
|
||||
StatusView.render("index.json", activities: activities, for: nil, as: :activity)
|
||||
end
|
||||
end
|
||||
26
lib/pleroma/web/preload/providers/user.ex
Normal file
26
lib/pleroma/web/preload/providers/user.ex
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.Preload.Providers.User do
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.MastodonAPI.AccountView
|
||||
alias Pleroma.Web.Preload.Providers.Provider
|
||||
|
||||
@behaviour Provider
|
||||
@account_url_base "/api/v1/accounts"
|
||||
|
||||
@impl Provider
|
||||
def generate_terms(%{user: user}) do
|
||||
build_accounts_tag(%{}, user)
|
||||
end
|
||||
|
||||
def generate_terms(_params), do: %{}
|
||||
|
||||
def build_accounts_tag(acc, %User{} = user) do
|
||||
account_data = AccountView.render("show.json", %{user: user, for: user})
|
||||
Map.put(acc, "#{@account_url_base}/#{user.id}", account_data)
|
||||
end
|
||||
|
||||
def build_accounts_tag(acc, _), do: acc
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue