diff --git a/lib/live_beats/accounts.ex b/lib/live_beats/accounts.ex index c2c6a24..982f712 100644 --- a/lib/live_beats/accounts.ex +++ b/lib/live_beats/accounts.ex @@ -5,7 +5,6 @@ defmodule LiveBeats.Accounts do alias LiveBeats.Repo alias LiveBeats.Accounts.{User, Identity, Events} - @admin_emails ["chris@chrismccord.com"] @pubsub LiveBeats.PubSub def subscribe(user_id) do @@ -22,7 +21,26 @@ defmodule LiveBeats.Accounts do Repo.all(from u in User, limit: ^Keyword.fetch!(opts, :limit)) end - def admin?(%User{} = user), do: user.email in @admin_emails + def admin?(%User{} = user) do + user.email in Application.fetch_env!(:live_beats, :admin_emails) + end + + @doc """ + Updates a user public's settings and exectes event. + """ + def update_public_settings(%User{} = user, attrs) do + user + |> change_settings(attrs) + |> Repo.update() + |> case do + {:ok, new_user} -> + LiveBeats.execute(__MODULE__, %Events.PublicSettingsChanged{user: new_user}) + {:ok, new_user} + + {:error, _} = error -> + error + end + end ## Database getters @@ -109,20 +127,6 @@ defmodule LiveBeats.Accounts do User.settings_changeset(user, attrs) end - def update_settings(%User{} = user, attrs) do - user - |> change_settings(attrs) - |> Repo.update() - |> case do - {:ok, new_user} -> - LiveBeats.execute(__MODULE__, %Events.PublicSettingsChanged{user: new_user}) - {:ok, new_user} - - {:error, _} = error -> - error - end - end - defp update_github_token(%User{} = user, new_token) do identity = Repo.one!(from(i in Identity, where: i.user_id == ^user.id and i.provider == "github")) diff --git a/lib/live_beats_web/controllers/file_controller.ex b/lib/live_beats_web/controllers/file_controller.ex index 3b3a60b..78cc1c6 100644 --- a/lib/live_beats_web/controllers/file_controller.ex +++ b/lib/live_beats_web/controllers/file_controller.ex @@ -1,4 +1,7 @@ defmodule LiveBeatsWeb.FileController do + @moduledoc """ + Serves files based on short-term token grants. + """ use LiveBeatsWeb, :controller alias LiveBeats.MediaLibrary @@ -14,7 +17,7 @@ defmodule LiveBeatsWeb.FileController do defp do_send_file(conn, path) do # accept-ranges headers required for chrome to seek via currentTime conn - |> put_resp_header("content-type", "audio/mp3") + |> put_resp_header("content-type", MIME.from_path(path)) |> put_resp_header("accept-ranges", "bytes") |> send_file(200, path) end diff --git a/lib/live_beats_web/live/home_live.ex b/lib/live_beats_web/live/home_live.ex deleted file mode 100644 index d4de3dd..0000000 --- a/lib/live_beats_web/live/home_live.ex +++ /dev/null @@ -1,351 +0,0 @@ -defmodule LiveBeatsWeb.HomeLive do - use LiveBeatsWeb, :live_view - - # alias LiveBeats.MediaLibrary - - def render(assigns) do - ~H""" - <.title_bar> - LiveBeats - Chill - - <:actions> - <.button>Share - <.button primary phx-click={show_modal("add-songs")}>Add Songs - - - - <.modal id="add-songs"> - <:title>Add Songs - a modal - <:cancel>Close - <:confirm>Add - - -