diff --git a/config/config.exs b/config/config.exs index c681ba4..f47e5d3 100644 --- a/config/config.exs +++ b/config/config.exs @@ -11,6 +11,10 @@ config :live_beats, replica: LiveBeats.ReplicaRepo, ecto_repos: [LiveBeats.Repo] + +config :live_beats, :files, + admin_usernames: [] + # Configures the endpoint config :live_beats, LiveBeatsWeb.Endpoint, url: [host: "localhost"], diff --git a/config/runtime.exs b/config/runtime.exs index 6b32f3a..ce760a4 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -62,6 +62,7 @@ if config_env() == :prod do secret_key_base: secret_key_base config :live_beats, :files, + admin_usernames: ~w(chrismccord mrkurt), uploads_dir: "/app/uploads", host: [scheme: "https", host: host, port: 443], server_ip: System.fetch_env!("LIVE_BEATS_SERVER_IP"), diff --git a/lib/live_beats/media_library.ex b/lib/live_beats/media_library.ex index 55bbefa..b8f9193 100644 --- a/lib/live_beats/media_library.ex +++ b/lib/live_beats/media_library.ex @@ -362,14 +362,17 @@ defmodule LiveBeats.MediaLibrary do end def expire_songs_older_than(count, interval) when interval in [:month, :day, :second] do + admin_usernames = LiveBeats.config([:files, :admin_usernames]) server_ip = LiveBeats.config([:files, :server_ip]) Ecto.Multi.new() |> Ecto.Multi.delete_all( :delete_expired_songs, from(s in Song, + join: u in assoc(s, :user), where: s.inserted_at < from_now(^(-count), ^to_string(interval)), where: s.server_ip == ^server_ip, + where: u.username not in ^admin_usernames, select: %{user_id: s.user_id, mp3_filepath: s.mp3_filepath} ) )