diff --git a/lib/music_library/secrets.ex b/lib/music_library/secrets.ex
index 332421f5..60826231 100644
--- a/lib/music_library/secrets.ex
+++ b/lib/music_library/secrets.ex
@@ -22,4 +22,11 @@ defmodule MusicLibrary.Secrets do
def get(name) do
Repo.get(Secret, name)
end
+
+ @spec delete(String.t()) :: :ok
+ def delete(name) do
+ import Ecto.Query
+ Repo.delete_all(from s in Secret, where: s.name == ^name)
+ :ok
+ end
end
diff --git a/lib/music_library_web/live/maintenance_live/index.ex b/lib/music_library_web/live/maintenance_live/index.ex
index 57b85c35..8a7b91f2 100644
--- a/lib/music_library_web/live/maintenance_live/index.ex
+++ b/lib/music_library_web/live/maintenance_live/index.ex
@@ -7,6 +7,7 @@ defmodule MusicLibraryWeb.MaintenanceLive.Index do
alias MusicLibrary.Assets.Cache
alias MusicLibrary.Maintenance
alias MusicLibrary.Records
+ alias MusicLibrary.Secrets
alias MusicLibrary.Worker.PruneAssets
alias MusicLibraryWeb.ErrorMessages
alias MusicLibraryWeb.RecordsOnThisDayEmail
@@ -208,6 +209,41 @@ defmodule MusicLibraryWeb.MaintenanceLive.Index do
+
+ {gettext("Last.fm")}
+
+
+ {gettext("Manage your Last.fm connection.")}
+
+ {gettext("Connected")}
+
+
+ {gettext("Not connected")}
+
+
+
+ -
+ <.button_group>
+ <.button
+ type="button"
+ phx-click="reconnect_lastfm"
+ data-confirm={
+ gettext(
+ "Are you sure you want to re-connect to Last.fm? This will disconnect the current account."
+ )
+ }
+ >
+ {gettext("Re-connect to Last.fm")}
+
+
+
+
"""
@@ -225,7 +261,8 @@ defmodule MusicLibraryWeb.MaintenanceLive.Index do
page_title: gettext("Maintenance"),
current_section: :maintenance
)
- |> assign_job_counts()}
+ |> assign_job_counts()
+ |> assign_lastfm_status()}
end
@impl true
@@ -235,6 +272,10 @@ defmodule MusicLibraryWeb.MaintenanceLive.Index do
{:noreply, assign_job_counts(socket)}
end
+ defp assign_lastfm_status(socket) do
+ assign(socket, :lastfm_connected, Secrets.get("last_fm_session_key") != nil)
+ end
+
defp assign_job_counts(socket) do
socket
|> assign(
@@ -386,4 +427,10 @@ defmodule MusicLibraryWeb.MaintenanceLive.Index do
)}
end
end
+
+ def handle_event("reconnect_lastfm", _params, socket) do
+ Secrets.delete("last_fm_session_key")
+
+ {:noreply, redirect(socket, external: LastFm.auth_url())}
+ end
end
diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot
index 9cb28a71..dd9b8d64 100644
--- a/priv/gettext/default.pot
+++ b/priv/gettext/default.pot
@@ -1938,6 +1938,7 @@ msgid "Error refreshing Last.fm data"
msgstr ""
#: lib/music_library_web/live/artist_live/show.ex
+#: lib/music_library_web/live/maintenance_live/index.ex
#, elixir-autogen, elixir-format
msgid "Last.fm"
msgstr ""
@@ -2319,3 +2320,28 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "No records yet"
msgstr ""
+
+#: lib/music_library_web/live/maintenance_live/index.ex
+#, elixir-autogen, elixir-format
+msgid "Are you sure you want to re-connect to Last.fm? This will disconnect the current account."
+msgstr ""
+
+#: lib/music_library_web/live/maintenance_live/index.ex
+#, elixir-autogen, elixir-format
+msgid "Connected"
+msgstr ""
+
+#: lib/music_library_web/live/maintenance_live/index.ex
+#, elixir-autogen, elixir-format
+msgid "Manage your Last.fm connection."
+msgstr ""
+
+#: lib/music_library_web/live/maintenance_live/index.ex
+#, elixir-autogen, elixir-format
+msgid "Not connected"
+msgstr ""
+
+#: lib/music_library_web/live/maintenance_live/index.ex
+#, elixir-autogen, elixir-format
+msgid "Re-connect to Last.fm"
+msgstr ""
diff --git a/priv/gettext/en/LC_MESSAGES/default.po b/priv/gettext/en/LC_MESSAGES/default.po
index 8368d1df..a9bac115 100644
--- a/priv/gettext/en/LC_MESSAGES/default.po
+++ b/priv/gettext/en/LC_MESSAGES/default.po
@@ -1938,6 +1938,7 @@ msgid "Error refreshing Last.fm data"
msgstr ""
#: lib/music_library_web/live/artist_live/show.ex
+#: lib/music_library_web/live/maintenance_live/index.ex
#, elixir-autogen, elixir-format
msgid "Last.fm"
msgstr ""
@@ -2319,3 +2320,28 @@ msgstr ""
#, elixir-autogen, elixir-format, fuzzy
msgid "No records yet"
msgstr ""
+
+#: lib/music_library_web/live/maintenance_live/index.ex
+#, elixir-autogen, elixir-format
+msgid "Are you sure you want to re-connect to Last.fm? This will disconnect the current account."
+msgstr ""
+
+#: lib/music_library_web/live/maintenance_live/index.ex
+#, elixir-autogen, elixir-format, fuzzy
+msgid "Connected"
+msgstr ""
+
+#: lib/music_library_web/live/maintenance_live/index.ex
+#, elixir-autogen, elixir-format
+msgid "Manage your Last.fm connection."
+msgstr ""
+
+#: lib/music_library_web/live/maintenance_live/index.ex
+#, elixir-autogen, elixir-format
+msgid "Not connected"
+msgstr ""
+
+#: lib/music_library_web/live/maintenance_live/index.ex
+#, elixir-autogen, elixir-format
+msgid "Re-connect to Last.fm"
+msgstr ""