Do not delete admin songs

This commit is contained in:
Chris McCord 2022-03-04 14:57:06 -05:00
parent 1934b68db6
commit b5edfdd9cd
3 changed files with 8 additions and 0 deletions

View file

@ -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"],

View file

@ -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"),

View file

@ -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}
)
)