mirror of
https://github.com/fly-apps/live_beats.git
synced 2024-11-21 15:41:00 +00:00
Do not delete admin songs
This commit is contained in:
parent
1934b68db6
commit
b5edfdd9cd
3 changed files with 8 additions and 0 deletions
|
@ -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"],
|
||||
|
|
|
@ -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"),
|
||||
|
|
|
@ -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}
|
||||
)
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue