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 - - -
-

Who's Here

- -
- - -
-
-

Projects

-
- -
- - - <.table rows={@songs}> - <:col let={song} label="Song"> - <%= song.title %> - - <:col let={song} label="Artist"> - <%= song.artist %> - - <:col let={song} label="Time"> - <%= song.duration %> - - <:col label=""> - - """ - end - - def mount(_parmas, _session, socket) do - {:ok, assign(socket, :songs, fetch_songs(socket))} - end - - defp fetch_songs(_socket) do - [] - end -end diff --git a/lib/live_beats_web/live/settings_live.ex b/lib/live_beats_web/live/settings_live.ex index aad6e5c..d18c529 100644 --- a/lib/live_beats_web/live/settings_live.ex +++ b/lib/live_beats_web/live/settings_live.ex @@ -79,7 +79,7 @@ defmodule LiveBeatsWeb.SettingsLive do end def handle_event("save", %{"user" => params}, socket) do - case Accounts.update_settings(socket.assigns.current_user, params) do + case Accounts.update_public_settings(socket.assigns.current_user, params) do {:ok, user} -> {:noreply, socket