Remove compile-time dependencies for some config values
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
4f0041ae31
commit
005f7e20ca
@ -8,8 +8,6 @@ defmodule Mix.Tasks.Mobilizon.Media.CleanOrphan do
|
|||||||
|
|
||||||
@shortdoc "Clean orphan media"
|
@shortdoc "Clean orphan media"
|
||||||
|
|
||||||
@grace_period Mobilizon.Config.get([:instance, :orphan_upload_grace_period_hours], 48)
|
|
||||||
|
|
||||||
@impl Mix.Task
|
@impl Mix.Task
|
||||||
def run(options) do
|
def run(options) do
|
||||||
{options, [], []} =
|
{options, [], []} =
|
||||||
@ -26,9 +24,12 @@ defmodule Mix.Tasks.Mobilizon.Media.CleanOrphan do
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
default_grace_period =
|
||||||
|
Mobilizon.Config.get([:instance, :orphan_upload_grace_period_hours], 48)
|
||||||
|
|
||||||
dry_run = Keyword.get(options, :dry_run, false)
|
dry_run = Keyword.get(options, :dry_run, false)
|
||||||
grace_period = Keyword.get(options, :days)
|
grace_period = Keyword.get(options, :days)
|
||||||
grace_period = if is_nil(grace_period), do: @grace_period, else: grace_period * 24
|
grace_period = if is_nil(grace_period), do: default_grace_period, else: grace_period * 24
|
||||||
verbose = Keyword.get(options, :verbose, false)
|
verbose = Keyword.get(options, :verbose, false)
|
||||||
|
|
||||||
start_mobilizon()
|
start_mobilizon()
|
||||||
|
@ -8,7 +8,6 @@ defmodule Mix.Tasks.Mobilizon.Users.Clean do
|
|||||||
alias Mobilizon.Service.CleanUnconfirmedUsers
|
alias Mobilizon.Service.CleanUnconfirmedUsers
|
||||||
|
|
||||||
@shortdoc "Clean unconfirmed users from Mobilizon"
|
@shortdoc "Clean unconfirmed users from Mobilizon"
|
||||||
@grace_period Mobilizon.Config.get([:instance, :unconfirmed_user_grace_period_hours], 48)
|
|
||||||
|
|
||||||
@impl Mix.Task
|
@impl Mix.Task
|
||||||
def run(options) do
|
def run(options) do
|
||||||
@ -26,9 +25,12 @@ defmodule Mix.Tasks.Mobilizon.Users.Clean do
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
default_grace_period =
|
||||||
|
Mobilizon.Config.get([:instance, :unconfirmed_user_grace_period_hours], 48)
|
||||||
|
|
||||||
dry_run = Keyword.get(options, :dry_run, false)
|
dry_run = Keyword.get(options, :dry_run, false)
|
||||||
grace_period = Keyword.get(options, :days)
|
grace_period = Keyword.get(options, :days)
|
||||||
grace_period = if is_nil(grace_period), do: @grace_period, else: grace_period * 24
|
grace_period = if is_nil(grace_period), do: default_grace_period, else: grace_period * 24
|
||||||
verbose = Keyword.get(options, :verbose, false)
|
verbose = Keyword.get(options, :verbose, false)
|
||||||
|
|
||||||
start_mobilizon()
|
start_mobilizon()
|
||||||
|
@ -1740,17 +1740,14 @@ defmodule Mobilizon.Actors do
|
|||||||
from(a in query, where: a.preferred_username == ^name and is_nil(a.domain))
|
from(a in query, where: a.preferred_username == ^name and is_nil(a.domain))
|
||||||
end
|
end
|
||||||
|
|
||||||
@own_domain Mobilizon.Config.instance_hostname()
|
|
||||||
|
|
||||||
defp filter_by_name(query, [name, @own_domain]) do
|
|
||||||
filter_by_name(query, [name])
|
|
||||||
end
|
|
||||||
|
|
||||||
defp filter_by_name(query, [name, domain]) do
|
defp filter_by_name(query, [name, domain]) do
|
||||||
from(a in query, where: a.preferred_username == ^name and a.domain == ^domain)
|
if domain == Mobilizon.Config.instance_hostname() do
|
||||||
|
filter_by_name(query, [name])
|
||||||
|
else
|
||||||
|
where(query, [a], a.preferred_username == ^name and a.domain == ^domain)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec filter_by_name(Ecto.Query.t(), boolean | nil) :: Ecto.Query.t()
|
|
||||||
defp filter_followed_by_approved_status(query, nil), do: query
|
defp filter_followed_by_approved_status(query, nil), do: query
|
||||||
|
|
||||||
defp filter_followed_by_approved_status(query, approved) do
|
defp filter_followed_by_approved_status(query, approved) do
|
||||||
|
@ -9,8 +9,6 @@ defmodule Mobilizon.Service.CleanOrphanMedia do
|
|||||||
alias Mobilizon.Storage.Repo
|
alias Mobilizon.Storage.Repo
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
@grace_period Mobilizon.Config.get([:instance, :orphan_upload_grace_period_hours], 48)
|
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Clean orphan media
|
Clean orphan media
|
||||||
|
|
||||||
@ -37,7 +35,10 @@ defmodule Mobilizon.Service.CleanOrphanMedia do
|
|||||||
|
|
||||||
@spec find_media(Keyword.t()) :: list(Media.t())
|
@spec find_media(Keyword.t()) :: list(Media.t())
|
||||||
defp find_media(opts) do
|
defp find_media(opts) do
|
||||||
grace_period = Keyword.get(opts, :grace_period, @grace_period)
|
default_grace_period =
|
||||||
|
Mobilizon.Config.get([:instance, :orphan_upload_grace_period_hours], 48)
|
||||||
|
|
||||||
|
grace_period = Keyword.get(opts, :grace_period, default_grace_period)
|
||||||
expiration_date = DateTime.add(DateTime.utc_now(), grace_period * -3600)
|
expiration_date = DateTime.add(DateTime.utc_now(), grace_period * -3600)
|
||||||
|
|
||||||
Media
|
Media
|
||||||
|
@ -9,8 +9,6 @@ defmodule Mobilizon.Service.CleanUnconfirmedUsers do
|
|||||||
alias Mobilizon.Users.User
|
alias Mobilizon.Users.User
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
@grace_period Mobilizon.Config.get([:instance, :unconfirmed_user_grace_period_hours], 48)
|
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Clean unattached media
|
Clean unattached media
|
||||||
|
|
||||||
@ -49,7 +47,10 @@ defmodule Mobilizon.Service.CleanUnconfirmedUsers do
|
|||||||
|
|
||||||
@spec find_unconfirmed_users_to_clean(Keyword.t()) :: list(User.t())
|
@spec find_unconfirmed_users_to_clean(Keyword.t()) :: list(User.t())
|
||||||
defp find_unconfirmed_users_to_clean(opts) do
|
defp find_unconfirmed_users_to_clean(opts) do
|
||||||
grace_period = Keyword.get(opts, :grace_period, @grace_period)
|
default_grace_period =
|
||||||
|
Mobilizon.Config.get([:instance, :unconfirmed_user_grace_period_hours], 48)
|
||||||
|
|
||||||
|
grace_period = Keyword.get(opts, :grace_period, default_grace_period)
|
||||||
expiration_date = DateTime.add(DateTime.utc_now(), grace_period * -3600)
|
expiration_date = DateTime.add(DateTime.utc_now(), grace_period * -3600)
|
||||||
|
|
||||||
User
|
User
|
||||||
|
@ -10,8 +10,6 @@ defmodule Mobilizon.Service.Export.ICalendar do
|
|||||||
alias Mobilizon.Service.Export.Common
|
alias Mobilizon.Service.Export.Common
|
||||||
alias Mobilizon.Service.Formatter.HTML
|
alias Mobilizon.Service.Formatter.HTML
|
||||||
|
|
||||||
@vendor "Mobilizon #{Config.instance_version()}"
|
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Create cache for an actor, an event or an user token
|
Create cache for an actor, an event or an user token
|
||||||
"""
|
"""
|
||||||
@ -119,7 +117,7 @@ defmodule Mobilizon.Service.Export.ICalendar do
|
|||||||
@spec events_to_ics(list(Events.t())) :: String.t()
|
@spec events_to_ics(list(Events.t())) :: String.t()
|
||||||
defp events_to_ics(events) do
|
defp events_to_ics(events) do
|
||||||
%ICalendar{events: events |> Enum.map(&do_export_event/1)}
|
%ICalendar{events: events |> Enum.map(&do_export_event/1)}
|
||||||
|> ICalendar.to_ics(vendor: @vendor)
|
|> ICalendar.to_ics(vendor: vendor())
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec do_export_event(Event.t()) :: ICalendar.Event.t()
|
@spec do_export_event(Event.t()) :: ICalendar.Event.t()
|
||||||
@ -137,4 +135,8 @@ defmodule Mobilizon.Service.Export.ICalendar do
|
|||||||
categories: event.tags |> Enum.map(& &1.title)
|
categories: event.tags |> Enum.map(& &1.title)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp vendor do
|
||||||
|
"Mobilizon #{Config.instance_version()}"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -6,8 +6,6 @@ defmodule Mobilizon.Service.Workers.CleanOrphanMediaWorker do
|
|||||||
use Oban.Worker, queue: "background"
|
use Oban.Worker, queue: "background"
|
||||||
alias Mobilizon.Service.CleanOrphanMedia
|
alias Mobilizon.Service.CleanOrphanMedia
|
||||||
|
|
||||||
@grace_period Mobilizon.Config.get([:instance, :orphan_upload_grace_period_hours], 48)
|
|
||||||
|
|
||||||
@impl Oban.Worker
|
@impl Oban.Worker
|
||||||
def perform(%Job{}) do
|
def perform(%Job{}) do
|
||||||
if Mobilizon.Config.get!([:instance, :remove_orphan_uploads]) and should_perform?() do
|
if Mobilizon.Config.get!([:instance, :remove_orphan_uploads]) and should_perform?() do
|
||||||
@ -19,9 +17,12 @@ defmodule Mobilizon.Service.Workers.CleanOrphanMediaWorker do
|
|||||||
defp should_perform? do
|
defp should_perform? do
|
||||||
case Cachex.get(:key_value, "last_media_cleanup") do
|
case Cachex.get(:key_value, "last_media_cleanup") do
|
||||||
{:ok, %DateTime{} = last_media_cleanup} ->
|
{:ok, %DateTime{} = last_media_cleanup} ->
|
||||||
|
default_grace_period =
|
||||||
|
Mobilizon.Config.get([:instance, :orphan_upload_grace_period_hours], 48)
|
||||||
|
|
||||||
DateTime.compare(
|
DateTime.compare(
|
||||||
last_media_cleanup,
|
last_media_cleanup,
|
||||||
DateTime.add(DateTime.utc_now(), @grace_period * -3600)
|
DateTime.add(DateTime.utc_now(), default_grace_period * -3600)
|
||||||
) == :lt
|
) == :lt
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
|
@ -6,8 +6,6 @@ defmodule Mobilizon.Service.Workers.CleanUnconfirmedUsersWorker do
|
|||||||
use Oban.Worker, queue: "background"
|
use Oban.Worker, queue: "background"
|
||||||
alias Mobilizon.Service.CleanUnconfirmedUsers
|
alias Mobilizon.Service.CleanUnconfirmedUsers
|
||||||
|
|
||||||
@grace_period Mobilizon.Config.get([:instance, :unconfirmed_user_grace_period_hours], 48)
|
|
||||||
|
|
||||||
@impl Oban.Worker
|
@impl Oban.Worker
|
||||||
def perform(%Job{}) do
|
def perform(%Job{}) do
|
||||||
if Mobilizon.Config.get!([:instance, :remove_unconfirmed_users]) and should_perform?() do
|
if Mobilizon.Config.get!([:instance, :remove_unconfirmed_users]) and should_perform?() do
|
||||||
@ -19,9 +17,12 @@ defmodule Mobilizon.Service.Workers.CleanUnconfirmedUsersWorker do
|
|||||||
defp should_perform? do
|
defp should_perform? do
|
||||||
case Cachex.get(:key_value, "last_media_cleanup") do
|
case Cachex.get(:key_value, "last_media_cleanup") do
|
||||||
{:ok, %DateTime{} = last_media_cleanup} ->
|
{:ok, %DateTime{} = last_media_cleanup} ->
|
||||||
|
default_grace_period =
|
||||||
|
Mobilizon.Config.get([:instance, :unconfirmed_user_grace_period_hours], 48)
|
||||||
|
|
||||||
DateTime.compare(
|
DateTime.compare(
|
||||||
last_media_cleanup,
|
last_media_cleanup,
|
||||||
DateTime.add(DateTime.utc_now(), @grace_period * -3600)
|
DateTime.add(DateTime.utc_now(), default_grace_period * -3600)
|
||||||
) == :lt
|
) == :lt
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
|
Loading…
Reference in New Issue
Block a user