mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2025-01-05 06:48:41 +00:00
RichMedia: Add extra checks on configuration
This commit is contained in:
parent
c16ef40f13
commit
65c8763907
2 changed files with 18 additions and 10 deletions
|
@ -77,19 +77,23 @@ defmodule Pleroma.Web.RichMedia.Card do
|
||||||
|
|
||||||
@spec get_or_backfill_by_url(String.t(), map()) :: t() | nil
|
@spec get_or_backfill_by_url(String.t(), map()) :: t() | nil
|
||||||
def get_or_backfill_by_url(url, backfill_opts \\ %{}) do
|
def get_or_backfill_by_url(url, backfill_opts \\ %{}) do
|
||||||
case get_by_url(url) do
|
if @config_impl.get([:rich_media, :enabled]) do
|
||||||
%__MODULE__{} = card ->
|
case get_by_url(url) do
|
||||||
card
|
%__MODULE__{} = card ->
|
||||||
|
card
|
||||||
|
|
||||||
nil ->
|
nil ->
|
||||||
backfill_opts = Map.put(backfill_opts, :url, url)
|
backfill_opts = Map.put(backfill_opts, :url, url)
|
||||||
|
|
||||||
Backfill.start(backfill_opts)
|
Backfill.start(backfill_opts)
|
||||||
|
|
||||||
nil
|
nil
|
||||||
|
|
||||||
:error ->
|
:error ->
|
||||||
nil
|
nil
|
||||||
|
end
|
||||||
|
else
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -15,10 +15,14 @@ defmodule Pleroma.Web.RichMedia.Parser do
|
||||||
|
|
||||||
@spec parse(String.t()) :: {:ok, map()} | {:error, any()}
|
@spec parse(String.t()) :: {:ok, map()} | {:error, any()}
|
||||||
def parse(url) do
|
def parse(url) do
|
||||||
with :ok <- validate_page_url(url),
|
with {_, true} <- {:config, @config_impl.get([:rich_media, :enabled])},
|
||||||
|
:ok <- validate_page_url(url),
|
||||||
{:ok, data} <- parse_url(url) do
|
{:ok, data} <- parse_url(url) do
|
||||||
data = Map.put(data, "url", url)
|
data = Map.put(data, "url", url)
|
||||||
{:ok, data}
|
{:ok, data}
|
||||||
|
else
|
||||||
|
{:config, _} -> {:error, :rich_media_disabled}
|
||||||
|
e -> e
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue