From 9958e90eb5eb5a2cc171c40860745e95a96bd429 Mon Sep 17 00:00:00 2001 From: Jordan Bracco Date: Tue, 20 Dec 2022 02:19:42 +0000 Subject: Actually do not prefix folders with nola_ refs T77 --- lib/nola_web/channels/user_socket.ex | 37 --- lib/nola_web/components/component.ex | 44 --- lib/nola_web/components/event_component.ex | 43 --- lib/nola_web/components/message_component.ex | 12 - lib/nola_web/context_plug.ex | 92 ------ lib/nola_web/controllers/alcoolog_controller.ex | 323 --------------------- lib/nola_web/controllers/gpt_controller.ex | 33 --- lib/nola_web/controllers/icecast_see_controller.ex | 41 --- .../controllers/irc_auth_sse_controller.ex | 66 ----- lib/nola_web/controllers/irc_controller.ex | 101 ------- lib/nola_web/controllers/network_controller.ex | 11 - lib/nola_web/controllers/open_id_controller.ex | 64 ---- lib/nola_web/controllers/page_controller.ex | 53 ---- lib/nola_web/controllers/sms_controller.ex | 10 - lib/nola_web/controllers/untappd_controller.ex | 18 -- lib/nola_web/endpoint.ex | 62 ---- lib/nola_web/gettext.ex | 24 -- lib/nola_web/live/chat_live.ex | 120 -------- lib/nola_web/live/chat_live.html.heex | 91 ------ lib/nola_web/router.ex | 85 ------ lib/nola_web/templates/alcoolog/auth.html.eex | 43 --- lib/nola_web/templates/alcoolog/index.html.eex | 205 ------------- lib/nola_web/templates/alcoolog/user.html.eex | 170 ----------- lib/nola_web/templates/irc/index.html.eex | 44 --- lib/nola_web/templates/irc/txt.html.eex | 27 -- lib/nola_web/templates/irc/txts.html.eex | 49 ---- lib/nola_web/templates/layout/app.html.eex | 126 -------- lib/nola_web/templates/layout/root.html.leex | 18 -- lib/nola_web/templates/network/index.html.eex | 1 - lib/nola_web/templates/open_id/error.html.eex | 3 - lib/nola_web/templates/page/api.html.eex | 35 --- lib/nola_web/templates/page/index.html.eex | 1 - lib/nola_web/templates/page/irc.html.eex | 19 -- lib/nola_web/templates/page/user.html.eex | 43 --- lib/nola_web/templates/page/widget.html.eex | 20 -- lib/nola_web/views/alcoolog_view.ex | 6 - lib/nola_web/views/error_helpers.ex | 40 --- lib/nola_web/views/error_view.ex | 17 -- lib/nola_web/views/irc_view.ex | 3 - lib/nola_web/views/layout_view.ex | 81 ------ lib/nola_web/views/network_view.ex | 4 - lib/nola_web/views/open_id_view.ex | 4 - lib/nola_web/views/page_view.ex | 3 - lib/nola_web/web.ex | 99 ------- 44 files changed, 2391 deletions(-) delete mode 100644 lib/nola_web/channels/user_socket.ex delete mode 100644 lib/nola_web/components/component.ex delete mode 100644 lib/nola_web/components/event_component.ex delete mode 100644 lib/nola_web/components/message_component.ex delete mode 100644 lib/nola_web/context_plug.ex delete mode 100644 lib/nola_web/controllers/alcoolog_controller.ex delete mode 100644 lib/nola_web/controllers/gpt_controller.ex delete mode 100644 lib/nola_web/controllers/icecast_see_controller.ex delete mode 100644 lib/nola_web/controllers/irc_auth_sse_controller.ex delete mode 100644 lib/nola_web/controllers/irc_controller.ex delete mode 100644 lib/nola_web/controllers/network_controller.ex delete mode 100644 lib/nola_web/controllers/open_id_controller.ex delete mode 100644 lib/nola_web/controllers/page_controller.ex delete mode 100644 lib/nola_web/controllers/sms_controller.ex delete mode 100644 lib/nola_web/controllers/untappd_controller.ex delete mode 100644 lib/nola_web/endpoint.ex delete mode 100644 lib/nola_web/gettext.ex delete mode 100644 lib/nola_web/live/chat_live.ex delete mode 100644 lib/nola_web/live/chat_live.html.heex delete mode 100644 lib/nola_web/router.ex delete mode 100644 lib/nola_web/templates/alcoolog/auth.html.eex delete mode 100644 lib/nola_web/templates/alcoolog/index.html.eex delete mode 100644 lib/nola_web/templates/alcoolog/user.html.eex delete mode 100644 lib/nola_web/templates/irc/index.html.eex delete mode 100644 lib/nola_web/templates/irc/txt.html.eex delete mode 100644 lib/nola_web/templates/irc/txts.html.eex delete mode 100644 lib/nola_web/templates/layout/app.html.eex delete mode 100644 lib/nola_web/templates/layout/root.html.leex delete mode 100644 lib/nola_web/templates/network/index.html.eex delete mode 100644 lib/nola_web/templates/open_id/error.html.eex delete mode 100644 lib/nola_web/templates/page/api.html.eex delete mode 100644 lib/nola_web/templates/page/index.html.eex delete mode 100644 lib/nola_web/templates/page/irc.html.eex delete mode 100644 lib/nola_web/templates/page/user.html.eex delete mode 100644 lib/nola_web/templates/page/widget.html.eex delete mode 100644 lib/nola_web/views/alcoolog_view.ex delete mode 100644 lib/nola_web/views/error_helpers.ex delete mode 100644 lib/nola_web/views/error_view.ex delete mode 100644 lib/nola_web/views/irc_view.ex delete mode 100644 lib/nola_web/views/layout_view.ex delete mode 100644 lib/nola_web/views/network_view.ex delete mode 100644 lib/nola_web/views/open_id_view.ex delete mode 100644 lib/nola_web/views/page_view.ex delete mode 100644 lib/nola_web/web.ex (limited to 'lib/nola_web') diff --git a/lib/nola_web/channels/user_socket.ex b/lib/nola_web/channels/user_socket.ex deleted file mode 100644 index eadd4e0..0000000 --- a/lib/nola_web/channels/user_socket.ex +++ /dev/null @@ -1,37 +0,0 @@ -defmodule NolaWeb.UserSocket do - use Phoenix.Socket - - ## Channels - # channel "room:*", NolaWeb.RoomChannel - - ## Transports - #transport :websocket, Phoenix.Transports.WebSocket - # transport :longpoll, Phoenix.Transports.LongPoll - - # Socket params are passed from the client and can - # be used to verify and authenticate a user. After - # verification, you can put default assigns into - # the socket that will be set for all channels, ie - # - # {:ok, assign(socket, :user_id, verified_user_id)} - # - # To deny connection, return `:error`. - # - # See `Phoenix.Token` documentation for examples in - # performing token verification on connect. - def connect(_params, socket) do - {:ok, socket} - end - - # Socket id's are topics that allow you to identify all sockets for a given user: - # - # def id(socket), do: "user_socket:#{socket.assigns.user_id}" - # - # Would allow you to broadcast a "disconnect" event and terminate - # all active sockets and channels for a given user: - # - # NolaWeb.Endpoint.broadcast("user_socket:#{user.id}", "disconnect", %{}) - # - # Returning `nil` makes this socket anonymous. - def id(_socket), do: nil -end diff --git a/lib/nola_web/components/component.ex b/lib/nola_web/components/component.ex deleted file mode 100644 index fff8263..0000000 --- a/lib/nola_web/components/component.ex +++ /dev/null @@ -1,44 +0,0 @@ -defmodule NolaWeb.Component do - use Phoenix.Component - - @date_time_default_format "%F %H:%M" - @date_time_formats %{"time-24-with-seconds" => "%H:%M:%S"} - def naive_date_time_utc(assigns = %{at: nil}) do - "" - end - - def naive_date_time_utc(assigns = %{format: format}) do - assigns = assign(assigns, :format, Map.get(@date_time_formats, format, format)) - ~H""" - - """ - end - def naive_date_time_utc(assigns) do - naive_date_time_utc(assign(assigns, :format, "%F %H:%M")) - end - def get_luxon_format("%H:%M:%S"), do: "TIME_24_WITH_SECONDS" - - def nick(assigns = %{self: false}) do - ~H""" - - <%= @nick %> - - """ - end - - def nick(assigns = %{self: true}) do - ~H""" - - You - - """ - end - - -end diff --git a/lib/nola_web/components/event_component.ex b/lib/nola_web/components/event_component.ex deleted file mode 100644 index 8af3c67..0000000 --- a/lib/nola_web/components/event_component.ex +++ /dev/null @@ -1,43 +0,0 @@ -defmodule NolaWeb.EventComponent do - use Phoenix.Component - - def content(assigns = %{event: %{type: :day_changed}}) do - ~H""" - Day changed: - <%= Date.to_string(@date) %> - """ - end - - def content(assigns = %{event: %{type: :quit}}) do - ~H""" - - has quit: - <%= @reason %> - """ - end - - def content(assigns = %{event: %{type: :part}}) do - ~H""" - - has left: - <%= @reason %> - """ - end - - def content(assigns = %{event: %{type: :nick}}) do - ~H""" - <%= @old_nick %> - is now known as - - """ - end - - def content(assigns = %{event: %{type: :join}}) do - ~H""" - - joined - """ - end - - -end diff --git a/lib/nola_web/components/message_component.ex b/lib/nola_web/components/message_component.ex deleted file mode 100644 index 5d0386b..0000000 --- a/lib/nola_web/components/message_component.ex +++ /dev/null @@ -1,12 +0,0 @@ -defmodule NolaWeb.MessageComponent do - use Phoenix.Component - - def content(assigns) do - ~H""" - -
<%= @message.sender.nick %>
-
<%= @text %>
- """ - end - -end diff --git a/lib/nola_web/context_plug.ex b/lib/nola_web/context_plug.ex deleted file mode 100644 index ebededa..0000000 --- a/lib/nola_web/context_plug.ex +++ /dev/null @@ -1,92 +0,0 @@ -defmodule NolaWeb.ContextPlug do - import Plug.Conn - import Phoenix.Controller - - def init(opts \\ []) do - opts || [] - end - - def get_account(conn) do - cond do - get_session(conn, :account) -> get_session(conn, :account) - get_session(conn, :oidc_id) -> if account = IRC.Account.find_meta_account("identity-id", get_session(conn, :oidc_id)), do: account.id - true -> nil - end - end - - def call(conn, opts) do - account = with \ - {:account, account_id} when is_binary(account_id) <- {:account, get_account(conn)}, - {:account, account} when not is_nil(account) <- {:account, IRC.Account.get(account_id)} - do - account - else - _ -> nil - end - - network = Map.get(conn.params, "network") - network = if network == "-", do: nil, else: network - - oidc_account = IRC.Account.find_meta_account("identity-id", get_session(conn, :oidc_id)) - - conns = IRC.Connection.get_network(network) - chan = if c = Map.get(conn.params, "chan") do - NolaWeb.reformat_chan(c) - end - chan_conn = IRC.Connection.get_network(network, chan) - - memberships = if account do - IRC.Membership.of_account(account) - end - - auth_required = cond do - Keyword.get(opts, :restrict) == :public -> false - account == nil -> true - network == nil -> false - Keyword.get(opts, :restrict) == :logged_in -> false - network && chan -> - !Enum.member?(memberships, {network, chan}) - network -> - !Enum.any?(memberships, fn({n, _}) -> n == network end) - end - - bot = cond do - network && chan && chan_conn -> chan_conn.nick - network && conns -> conns.nick - true -> nil - end - - - cond do - account && auth_required -> - conn - |> put_status(404) - |> text("Page not found") - |> halt() - auth_required -> - conn - |> put_status(403) - |> render(NolaWeb.AlcoologView, "auth.html", bot: bot, no_header: true, network: network) - |> halt() - (network && !conns) -> - conn - |> put_status(404) - |> text("Page not found") - |> halt() - (chan && !chan_conn) -> - conn - |> put_status(404) - |> text("Page not found") - |> halt() - true -> - conn = conn - |> assign(:network, network) - |> assign(:chan, chan) - |> assign(:bot, bot) - |> assign(:account, account) - |> assign(:oidc_account, oidc_account) - |> assign(:memberships, memberships) - end - end - -end diff --git a/lib/nola_web/controllers/alcoolog_controller.ex b/lib/nola_web/controllers/alcoolog_controller.ex deleted file mode 100644 index 3c812c5..0000000 --- a/lib/nola_web/controllers/alcoolog_controller.ex +++ /dev/null @@ -1,323 +0,0 @@ -defmodule NolaWeb.AlcoologController do - use NolaWeb, :controller - require Logger - - plug NolaWeb.ContextPlug when action not in [:token] - plug NolaWeb.ContextPlug, [restrict: :public] when action in [:token] - - def token(conn, %{"token" => token}) do - case Nola.Token.lookup(token) do - {:ok, {:alcoolog, :index, network, channel}} -> index(conn, nil, network, channel) - err -> - Logger.debug("AlcoologControler: token #{inspect err} invalid") - conn - |> put_status(404) - |> text("Page not found") - end - end - - def nick(conn = %{assigns: %{account: account}}, params = %{"network" => network, "nick" => nick}) do - profile_account = IRC.Account.find_always_by_nick(network, nick, nick) - days = String.to_integer(Map.get(params, "days", "180")) - friend? = Enum.member?(IRC.Membership.friends(account), profile_account.id) - if friend? do - stats = Nola.Plugins.Alcoolog.get_full_statistics(profile_account.id) - history = for {{nick, ts}, points, active, cl, deg, type, descr, meta} <- Nola.Plugins.Alcoolog.nick_history(profile_account) do - %{ - at: ts |> DateTime.from_unix!(:millisecond), - points: points, - active: active, - cl: cl, - deg: deg, - type: type, - description: descr, - meta: meta - } - end - history = Enum.sort(history, &(DateTime.compare(&1.at, &2.at) != :lt)) - |> IO.inspect() - conn - |> assign(:title, "alcoolog #{nick}") - |> render("user.html", network: network, profile: profile_account, days: days, nick: nick, history: history, stats: stats) - else - conn - |> put_status(404) - |> text("Page not found") - end - end - - def nick_stats_json(conn = %{assigns: %{account: account}}, params = %{"network" => network, "nick" => nick}) do - profile_account = IRC.Account.find_always_by_nick(network, nick, nick) - friend? = Enum.member?(IRC.Membership.friends(account), profile_account.id) - if friend? do - stats = Nola.Plugins.Alcoolog.get_full_statistics(profile_account.id) - - conn - |> put_resp_content_type("application/json") - |> text(Jason.encode!(stats)) - else - conn - |> put_status(404) - |> json([]) - end - end - - def nick_gls_json(conn = %{assigns: %{account: account}}, params = %{"network" => network, "nick" => nick}) do - profile_account = IRC.Account.find_always_by_nick(network, nick, nick) - friend? = Enum.member?(IRC.Membership.friends(account), profile_account.id) - count = String.to_integer(Map.get(params, "days", "180")) - if friend? do - data = Nola.Plugins.Alcoolog.user_over_time_gl(profile_account, count) - delay = count*((24 * 60)*60) - now = DateTime.utc_now() - start_date = DateTime.utc_now() - |> DateTime.shift_zone!("Europe/Paris", Tzdata.TimeZoneDatabase) - |> DateTime.add(-delay, :second, Tzdata.TimeZoneDatabase) - |> DateTime.to_date() - |> Date.to_erl() - filled = (:calendar.date_to_gregorian_days(start_date) .. :calendar.date_to_gregorian_days(DateTime.utc_now |> DateTime.to_date() |> Date.to_erl)) - |> Enum.to_list - |> Enum.map(&(:calendar.gregorian_days_to_date(&1))) - |> Enum.map(&Date.from_erl!(&1)) - |> Enum.map(fn(date) -> - %{date: date, gls: Map.get(data, date, 0)} - end) - |> Enum.sort(&(Date.compare(&1.date, &2.date) != :gt)) - - conn - |> put_resp_content_type("application/json") - |> text(Jason.encode!(filled)) - else - conn - |> put_status(404) - |> json([]) - end - end - - - - def nick_volumes_json(conn = %{assigns: %{account: account}}, params = %{"network" => network, "nick" => nick}) do - profile_account = IRC.Account.find_always_by_nick(network, nick, nick) - friend? = Enum.member?(IRC.Membership.friends(account), profile_account.id) - count = String.to_integer(Map.get(params, "days", "180")) - if friend? do - data = Nola.Plugins.Alcoolog.user_over_time(profile_account, count) - delay = count*((24 * 60)*60) - now = DateTime.utc_now() - start_date = DateTime.utc_now() - |> DateTime.shift_zone!("Europe/Paris", Tzdata.TimeZoneDatabase) - |> DateTime.add(-delay, :second, Tzdata.TimeZoneDatabase) - |> DateTime.to_date() - |> Date.to_erl() - filled = (:calendar.date_to_gregorian_days(start_date) .. :calendar.date_to_gregorian_days(DateTime.utc_now |> DateTime.to_date() |> Date.to_erl)) - |> Enum.to_list - |> Enum.map(&(:calendar.gregorian_days_to_date(&1))) - |> Enum.map(&Date.from_erl!(&1)) - |> Enum.map(fn(date) -> - %{date: date, volumes: Map.get(data, date, 0)} - end) - |> Enum.sort(&(Date.compare(&1.date, &2.date) != :gt)) - - conn - |> put_resp_content_type("application/json") - |> text(Jason.encode!(filled)) - else - conn - |> put_status(404) - |> json([]) - end - end - - def nick_log_json(conn = %{assigns: %{account: account}}, %{"network" => network, "nick" => nick}) do - profile_account = IRC.Account.find_always_by_nick(network, nick, nick) - friend? = Enum.member?(IRC.Membership.friends(account), profile_account.id) - if friend? do - history = for {{nick, ts}, points, active, cl, deg, type, descr, meta} <- Nola.Plugins.Alcoolog.nick_history(profile_account) do - %{ - at: ts |> DateTime.from_unix!(:millisecond) |> DateTime.to_iso8601(), - points: points, - active: active, - cl: cl, - deg: deg, - type: type, - description: descr, - meta: meta - } - end - last = List.last(history) - {_, active} = Nola.Plugins.Alcoolog.user_stats(profile_account) - last = %{last | active: active, at: DateTime.utc_now() |> DateTime.to_iso8601()} - history = history ++ [last] - - conn - |> put_resp_content_type("application/json") - |> text(Jason.encode!(history)) - else - conn - |> put_status(404) - |> json([]) - end - end - - def nick_history_json(conn = %{assigns: %{account: account}}, %{"network" => network, "nick" => nick}) do - profile_account = IRC.Account.find_always_by_nick(network, nick, nick) - friend? = Enum.member?(IRC.Membership.friends(account), profile_account.id) - if friend? do - history = for {_, date, value} <- Nola.Plugs.AlcoologAnnouncer.log(profile_account) do - %{date: DateTime.to_iso8601(date), value: value} - end - conn - |> put_resp_content_type("application/json") - |> text(Jason.encode!(history)) - else - conn - |> put_status(404) - |> json([]) - end - end - - def index(conn = %{assigns: %{account: account}}, %{"network" => network, "chan" => channel}) do - index(conn, account, network, NolaWeb.reformat_chan(channel)) - end - - def index(conn = %{assigns: %{account: account}}, _) do - index(conn, account, nil, nil) - end - - #def index(conn, params) do - # network = Map.get(params, "network") - # chan = if c = Map.get(params, "chan") do - # NolaWeb.reformat_chan(c) - # end - # irc_conn = if network do - # IRC.Connection.get_network(network, chan) - # end - # bot = if(irc_conn, do: irc_conn.nick)# - # - # conn - # |> put_status(403) - # |> render("auth.html", network: network, channel: chan, irc_conn: conn, bot: bot) - #end - - def index(conn, account, network, channel) do - aday = ((24 * 60)*60) - now = DateTime.utc_now() - before7 = now - |> DateTime.add(-(7*aday), :second) - |> DateTime.to_unix(:millisecond) - before15 = now - |> DateTime.add(-(15*aday), :second) - |> DateTime.to_unix(:millisecond) - before31 = now - |> DateTime.add(-(31*aday), :second) - |> DateTime.to_unix(:millisecond) - #match = :ets.fun2ms(fn(obj = {{^nick, date}, _, _, _, _}) when date > before -> obj end) - match = [ - {{{:_, :"$1"}, :_, :_, :_, :_, :_, :_, :_}, - [ - {:>, :"$1", {:const, before15}}, - ], [:"$_"]} - ] - - # tuple ets: {{nick, date}, volumes, current, nom, commentaire} - members = IRC.Membership.expanded_members_or_friends(account, network, channel) - members_ids = Enum.map(members, fn({account, _, nick}) -> account.id end) - member_names = Enum.reduce(members, %{}, fn({account, _, nick}, acc) -> Map.put(acc, account.id, nick) end) - drinks = :ets.select(Nola.Plugins.Alcoolog.ETS, match) - |> Enum.filter(fn({{account, _}, _vol, _cur, _cl, _deg, _name, _cmt, _meta}) -> Enum.member?(members_ids, account) end) - |> Enum.map(fn({{account, _}, _, _, _, _, _, _, _} = object) -> {object, Map.get(member_names, account)} end) - |> Enum.sort_by(fn({{{_, ts}, _, _, _, _, _, _, _}, _}) -> ts end, &>/2) - - stats = Nola.Plugins.Alcoolog.get_channel_statistics(account, network, channel) - - top = Enum.reduce(drinks, %{}, fn({{{account_id, _}, vol, _, _, _, _, _, _}, _}, acc) -> - nick = Map.get(member_names, account_id) - all = Map.get(acc, nick, 0) - Map.put(acc, nick, all + vol) - end) - |> Enum.sort_by(fn({_nick, count}) -> count end, &>/2) - # {date, single_peak} - # - conn - |> assign(:title, "alcoolog") - |> render("index.html", network: network, channel: channel, drinks: drinks, top: top, stats: stats) - end - - def index_gls_json(conn = %{assigns: %{account: account}}, %{"network" => network, "chan" => channel}) do - count = 30 - channel = NolaWeb.reformat_chan(channel) - members = IRC.Membership.expanded_members_or_friends(account, network, channel) - members_ids = Enum.map(members, fn({account, _, nick}) -> account.id end) - member_names = Enum.reduce(members, %{}, fn({account, _, nick}, acc) -> Map.put(acc, account.id, nick) end) - delay = count*((24 * 60)*60) - now = DateTime.utc_now() - start_date = DateTime.utc_now() - |> DateTime.shift_zone!("Europe/Paris", Tzdata.TimeZoneDatabase) - |> DateTime.add(-delay, :second, Tzdata.TimeZoneDatabase) - |> DateTime.to_date() - |> Date.to_erl() - filled = (:calendar.date_to_gregorian_days(start_date) .. :calendar.date_to_gregorian_days(DateTime.utc_now |> DateTime.to_date() |> Date.to_erl)) - |> Enum.to_list - |> Enum.map(&(:calendar.gregorian_days_to_date(&1))) - |> Enum.map(&Date.from_erl!(&1)) - |> Enum.map(fn(date) -> - {date, (for {a, _, _} <- members, into: Map.new, do: {Map.get(member_names, a.id, a.id), 0})} - end) - |> Enum.into(Map.new) - - gls = Enum.reduce(members, filled, fn({account, _, _}, gls) -> - Enum.reduce(Nola.Plugins.Alcoolog.user_over_time_gl(account, count), gls, fn({date, gl}, gls) -> - u = Map.get(gls, date, %{}) - |> Map.put(Map.get(member_names, account.id, account.id), gl) - Map.put(gls, date, u) - end) - end) - - dates = (:calendar.date_to_gregorian_days(start_date) .. :calendar.date_to_gregorian_days(DateTime.utc_now |> DateTime.to_date() |> Date.to_erl)) - |> Enum.to_list - |> Enum.map(&(:calendar.gregorian_days_to_date(&1))) - |> Enum.map(&Date.from_erl!(&1)) - - filled2 = Enum.map(member_names, fn({_, name}) -> - history = (:calendar.date_to_gregorian_days(start_date) .. :calendar.date_to_gregorian_days(DateTime.utc_now |> DateTime.to_date() |> Date.to_erl)) - |> Enum.to_list - |> Enum.map(&(:calendar.gregorian_days_to_date(&1))) - |> Enum.map(&Date.from_erl!(&1)) - |> Enum.map(fn(date) -> - get_in(gls, [date, name]) #%{date: date, gl: get_in(gls, [date, name])} - end) - if Enum.all?(history, fn(x) -> x == 0 end) do - nil - else - %{name: name, history: history} - end - end) - |> Enum.filter(fn(x) -> x end) - - conn - |> put_resp_content_type("application/json") - |> text(Jason.encode!(%{labels: dates, data: filled2})) - end - - def minisync(conn, %{"user_id" => user_id, "key" => key, "value" => value}) do - account = IRC.Account.get(user_id) - if account do - ds = Nola.Plugins.Alcoolog.data_state() - meta = Nola.Plugins.Alcoolog.get_user_meta(ds, account.id) - case Float.parse(value) do - {val, _} -> - new_meta = Map.put(meta, String.to_existing_atom(key), val) - Nola.Plugins.Alcoolog.put_user_meta(ds, account.id, new_meta) - _ -> - conn - |> put_status(:unprocessable_entity) - |> text("invalid value") - end - else - conn - |> put_status(:not_found) - |> text("not found") - end - end - -end diff --git a/lib/nola_web/controllers/gpt_controller.ex b/lib/nola_web/controllers/gpt_controller.ex deleted file mode 100644 index 810a875..0000000 --- a/lib/nola_web/controllers/gpt_controller.ex +++ /dev/null @@ -1,33 +0,0 @@ -defmodule NolaWeb.GptController do - use NolaWeb, :controller - require Logger - - plug NolaWeb.ContextPlug - - def result(conn, params = %{"id" => result_id}) do - case Nola.Plugins.Gpt.get_result(result_id) do - {:ok, result} -> - network = Map.get(params, "network") - channel = if c = Map.get(params, "chan"), do: NolaWeb.reformat_chan(c) - render(conn, "result.html", network: network, channel: channel, result: result) - {:error, :not_found} -> - conn - |> put_status(404) - |> text("Page not found") - end - end - - def prompt(conn, params = %{"id" => prompt_id}) do - case Nola.Plugins.Gpt.get_prompt(prompt_id) do - {:ok, prompt} -> - network = Map.get(params, "network") - channel = if c = Map.get(params, "chan"), do: NolaWeb.reformat_chan(c) - render(conn, "prompt.html", network: network, channel: channel, prompt: prompt) - {:error, :not_found} -> - conn - |> put_status(404) - |> text("Page not found") - end - end - -end diff --git a/lib/nola_web/controllers/icecast_see_controller.ex b/lib/nola_web/controllers/icecast_see_controller.ex deleted file mode 100644 index 877ad4e..0000000 --- a/lib/nola_web/controllers/icecast_see_controller.ex +++ /dev/null @@ -1,41 +0,0 @@ -defmodule NolaWeb.IcecastSseController do - use NolaWeb, :controller - require Logger - - @ping_interval 20_000 - - def sse(conn, _params) do - conn - |> put_resp_header("X-Accel-Buffering", "no") - |> put_resp_header("content-type", "text/event-stream") - |> send_chunked(200) - |> subscribe - |> send_sse_message("ping", "ping") - |> send_sse_message("icecast", Nola.IcecastAgent.get) - |> sse_loop - end - - def subscribe(conn) do - :timer.send_interval(@ping_interval, {:event, :ping}) - {:ok, _} = Registry.register(Nola.BroadcastRegistry, "icecast", []) - conn - end - - def sse_loop(conn) do - {type, event} = receive do - {:event, :ping} -> {"ping", "ping"} - {:icecast, stats} -> {"icecast", stats} - end - - conn - |> send_sse_message(type, event) - |> sse_loop() - end - - defp send_sse_message(conn, type, data) do - json = Jason.encode!(%{type => data}) - {:ok, conn} = chunk(conn, "event: #{type}\ndata: #{json}\n\n") - conn - end - -end diff --git a/lib/nola_web/controllers/irc_auth_sse_controller.ex b/lib/nola_web/controllers/irc_auth_sse_controller.ex deleted file mode 100644 index 62ee2b5..0000000 --- a/lib/nola_web/controllers/irc_auth_sse_controller.ex +++ /dev/null @@ -1,66 +0,0 @@ -defmodule NolaWeb.IrcAuthSseController do - use NolaWeb, :controller - require Logger - - @ping_interval 20_000 - @expire_delay :timer.minutes(3) - - def sse(conn, params) do - perks = if uri = Map.get(params, "redirect_to") do - {:redirect, uri} - else - nil - end - token = String.downcase(EntropyString.random_string(65)) - conn - |> assign(:token, token) - |> assign(:perks, perks) - |> put_resp_header("X-Accel-Buffering", "no") - |> put_resp_header("content-type", "text/event-stream") - |> send_chunked(200) - |> subscribe() - |> send_sse_message("token", token) - |> sse_loop - end - - def subscribe(conn) do - :timer.send_interval(@ping_interval, {:event, :ping}) - :timer.send_after(@expire_delay, {:event, :expire}) - {:ok, _} = Registry.register(IRC.PubSub, "messages:private", []) - conn - end - - def sse_loop(conn) do - {type, event, exit} = receive do - {:event, :ping} -> {"ping", "ping", false} - {:event, :expire} -> {"expire", "expire", true} - {:irc, :text, %{account: account, text: token} = m} -> - if String.downcase(String.trim(token)) == conn.assigns.token do - path = Nola.AuthToken.new_path(account.id, conn.assigns.perks) - m.replyfun.("ok!") - {"authenticated", path, true} - else - {nil, nil, false} - end - _ -> {nil, nil, false} - end - - conn = if type do - send_sse_message(conn, type, event) - else - conn - end - - if exit do - conn - else - sse_loop(conn) - end - end - - defp send_sse_message(conn, type, data) do - {:ok, conn} = chunk(conn, "event: #{type}\ndata: #{data}\n\n") - conn - end - -end diff --git a/lib/nola_web/controllers/irc_controller.ex b/lib/nola_web/controllers/irc_controller.ex deleted file mode 100644 index d6114e6..0000000 --- a/lib/nola_web/controllers/irc_controller.ex +++ /dev/null @@ -1,101 +0,0 @@ -defmodule NolaWeb.IrcController do - use NolaWeb, :controller - - plug NolaWeb.ContextPlug - - def index(conn, params) do - network = Map.get(params, "network") - channel = if c = Map.get(params, "chan"), do: NolaWeb.reformat_chan(c) - commands = for mod <- Enum.uniq([Nola.Plugins.Account] ++ Nola.Plugins.enabled()) do - if is_atom(mod) do - identifier = Module.split(mod) |> List.last |> Macro.underscore - {identifier, mod.irc_doc()} - end - end - |> Enum.filter(& &1) - |> Enum.filter(fn({_, doc}) -> doc end) - members = cond do - network && channel -> Enum.map(IRC.UserTrack.channel(network, channel), fn(tuple) -> IRC.UserTrack.User.from_tuple(tuple) end) - true -> - IRC.Membership.of_account(conn.assigns.account) - end - render conn, "index.html", network: network, commands: commands, channel: channel, members: members - end - - def txt(conn, %{"name" => name}) do - if String.contains?(name, ".txt") do - name = String.replace(name, ".txt", "") - data = data() - if Map.has_key?(data, name) do - lines = Enum.join(data[name], "\n") - text(conn, lines) - else - conn - |> put_status(404) - |> text("Not found") - end - else - do_txt(conn, name) - end - end - def txt(conn, _), do: do_txt(conn, nil) - - - defp do_txt(conn, nil) do - doc = Nola.IRC.Txt.irc_doc() - data = data() - main = Enum.filter(data, fn({trigger, _}) -> !String.contains?(trigger, ".") end) |> Enum.into(Map.new) - system = Enum.filter(data, fn({trigger, _}) -> String.contains?(trigger, ".") end) |> Enum.into(Map.new) - lines = Enum.reduce(main, 0, fn({_, lines}, acc) -> acc + Enum.count(lines) end) - conn - |> assign(:title, "txt") - |> render("txts.html", data: main, doc: doc, files: Enum.count(main), lines: lines, system: system) - end - - defp do_txt(conn, txt) do - data = data() - base_url = cond do - conn.assigns[:chan] -> "/#{conn.assigns.network}/#{NolaWeb.format_chan(conn.assigns.chan)}" - true -> "/-" - end - if lines = Map.get(data, txt) do - lines = Enum.map(lines, fn(line) -> - line - |> String.split("\\\\") - |> Enum.intersperse(Phoenix.HTML.Tag.tag(:br)) - end) - conn - |> assign(:breadcrumbs, [{"txt", "#{base_url}/txt"}]) - |> assign(:title, "#{txt}.txt") - |> render("txt.html", name: txt, data: lines, doc: nil) - else - conn - |> put_status(404) - |> text("Not found") - end - end - - defp data() do - dir = Application.get_env(:nola, :data_path) <> "/irc.txt/" - Path.wildcard(dir <> "/*.txt") - |> Enum.reduce(%{}, fn(path, m) -> - path = String.split(path, "/") - file = List.last(path) - key = String.replace(file, ".txt", "") - data = dir <> file - |> File.read! - |> String.split("\n") - |> Enum.reject(fn(line) -> - cond do - line == "" -> true - !line -> true - true -> false - end - end) - Map.put(m, key, data) - end) - |> Enum.sort - |> Enum.into(Map.new) - end - -end diff --git a/lib/nola_web/controllers/network_controller.ex b/lib/nola_web/controllers/network_controller.ex deleted file mode 100644 index 800294f..0000000 --- a/lib/nola_web/controllers/network_controller.ex +++ /dev/null @@ -1,11 +0,0 @@ -defmodule NolaWeb.NetworkController do - use NolaWeb, :controller - plug NolaWeb.ContextPlug - - def index(conn, %{"network" => network}) do - conn - |> assign(:title, network) - |> render("index.html") - end - -end diff --git a/lib/nola_web/controllers/open_id_controller.ex b/lib/nola_web/controllers/open_id_controller.ex deleted file mode 100644 index d3fef5d..0000000 --- a/lib/nola_web/controllers/open_id_controller.ex +++ /dev/null @@ -1,64 +0,0 @@ -defmodule NolaWeb.OpenIdController do - use NolaWeb, :controller - plug NolaWeb.ContextPlug, restrict: :public - require Logger - - def login(conn, _) do - url = OAuth2.Client.authorize_url!(new_client(), scope: "openid", state: Base.url_encode64(:crypto.strong_rand_bytes(32), padding: false)) - redirect(conn, external: url) - end - - def callback(conn, %{"error" => error_code, "error_description" => error}) do - Logger.warn("OpenId error: #{error_code} #{error}") - render(conn, "error.html", error: error) - end - - def callback(conn, %{"code" => code, "state" => state}) do - with \ - client = %{token: %OAuth2.AccessToken{access_token: json}} = OAuth2.Client.get_token!(new_client(), state: state, code: code), - {:ok, %{"access_token" => token}} <- Jason.decode(json), - client = %OAuth2.Client{client | token: %OAuth2.AccessToken{access_token: token}}, - {:ok, %OAuth2.Response{body: body}} <- OAuth2.Client.get(client, "/userinfo"), - {:ok, %{"sub" => id, "preferred_username" => username}} <- Jason.decode(body) - do - if account = conn.assigns.account do - if !IRC.Account.get_meta(account, "identity-id") do # XXX: And oidc id not linked yet - IRC.Account.put_meta(account, "identity-id", id) - end - IRC.Account.put_meta(account, "identity-username", username) - conn - else - conn - end - - conn - |> put_session(:oidc_id, id) - |> put_flash(:info, "Logged in!") - |> redirect(to: Routes.path(conn, "/")) - else - {:error, %OAuth2.Response{status_code: 401}} -> - Logger.error("OpenID: Unauthorized token") - render(conn, "error.html", error: "The token is invalid.") - {:error, %OAuth2.Error{reason: reason}} -> - Logger.error("Error: #{inspect reason}") - render(conn, "error.html", error: reason) - end - end - - def callback(conn, _params) do - render(conn, "error.html", error: "Unspecified error.") - end - - defp new_client() do - config = Application.get_env(:nola, :oidc) - OAuth2.Client.new([ - strategy: OAuth2.Strategy.AuthCode, - client_id: config[:client_id], - client_secret: config[:client_secret], - site: config[:base_url], - authorize_url: config[:authorize_url], - token_url: config[:token_url], - redirect_uri: Routes.open_id_url(NolaWeb.Endpoint, :callback) - ]) - end -end diff --git a/lib/nola_web/controllers/page_controller.ex b/lib/nola_web/controllers/page_controller.ex deleted file mode 100644 index 2ac4d0a..0000000 --- a/lib/nola_web/controllers/page_controller.ex +++ /dev/null @@ -1,53 +0,0 @@ -defmodule NolaWeb.PageController do - use NolaWeb, :controller - - plug NolaWeb.ContextPlug when action not in [:token] - plug NolaWeb.ContextPlug, [restrict: :public] when action in [:token] - - def token(conn, %{"token" => token}) do - with \ - {:ok, account, perks} <- Nola.AuthToken.lookup(token) - do - IO.puts("Authenticated account #{inspect account}") - conn = put_session(conn, :account, account) - case perks do - nil -> redirect(conn, to: "/") - {:redirect, path} -> redirect(conn, to: path) - {:external_redirect, url} -> redirect(conn, external: url) - end - else - z -> - IO.inspect(z) - text(conn, "Error: invalid or expired token") - end - end - - def index(conn = %{assigns: %{account: account}}, _) do - memberships = IRC.Membership.of_account(account) - users = IRC.UserTrack.find_by_account(account) - metas = IRC.Account.get_all_meta(account) - predicates = IRC.Account.get_predicates(account) - conn - |> assign(:title, account.name) - |> render("user.html", users: users, memberships: memberships, metas: metas, predicates: predicates) - end - - def irc(conn, _) do - bot_helps = for mod <- Nola.IRC.env(:handlers) do - mod.irc_doc() - end - render conn, "irc.html", bot_helps: bot_helps - end - - def authenticate(conn, _) do - with \ - {:account, account_id} when is_binary(account_id) <- {:account, get_session(conn, :account)}, - {:account, account} when not is_nil(account) <- {:account, IRC.Account.get(account_id)} - do - assign(conn, :account, account) - else - _ -> conn - end - end - -end diff --git a/lib/nola_web/controllers/sms_controller.ex b/lib/nola_web/controllers/sms_controller.ex deleted file mode 100644 index 0fffa23..0000000 --- a/lib/nola_web/controllers/sms_controller.ex +++ /dev/null @@ -1,10 +0,0 @@ -defmodule NolaWeb.SmsController do - use NolaWeb, :controller - require Logger - - def ovh_callback(conn, %{"senderid" => from, "message" => message}) do - spawn(fn() -> Nola.Plugins.Sms.incoming(from, String.trim(message)) end) - text(conn, "") - end - -end diff --git a/lib/nola_web/controllers/untappd_controller.ex b/lib/nola_web/controllers/untappd_controller.ex deleted file mode 100644 index d3a540d..0000000 --- a/lib/nola_web/controllers/untappd_controller.ex +++ /dev/null @@ -1,18 +0,0 @@ -defmodule NolaWeb.UntappdController do - use NolaWeb, :controller - - def callback(conn, %{"code" => code}) do - with \ - {:account, account_id} when is_binary(account_id) <- {:account, get_session(conn, :account)}, - {:account, account} when not is_nil(account) <- {:account, IRC.Account.get(account_id)}, - {:ok, auth_token} <- Untappd.auth_callback(code) - do - IRC.Account.put_meta(account, "untappd-token", auth_token) - text(conn, "OK!") - else - {:account, _} -> text(conn, "Error: account not found") - :error -> text(conn, "Error: untappd authentication failed") - end - end - -end diff --git a/lib/nola_web/endpoint.ex b/lib/nola_web/endpoint.ex deleted file mode 100644 index a401f54..0000000 --- a/lib/nola_web/endpoint.ex +++ /dev/null @@ -1,62 +0,0 @@ -defmodule NolaWeb.Endpoint do - use Sentry.PlugCapture - use Phoenix.Endpoint, otp_app: :nola - - # Serve at "/" the static files from "priv/static" directory. - # - # You should set gzip to true if you are running phoenix.digest - # when deploying your static files in production. - plug Plug.Static, - at: "/", from: :nola, gzip: false, - only: ~w(assets css js fonts images favicon.ico robots.txt) - - # Code reloading can be explicitly enabled under the - # :code_reloader configuration of your endpoint. - if 42==43 && code_reloading? do - socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket - plug Phoenix.LiveReloader - plug Phoenix.CodeReloader - end - - plug Plug.RequestId - plug Plug.Logger - - plug Plug.Parsers, - parsers: [:urlencoded, :multipart, :json], - pass: ["*/*"], - json_decoder: Jason - - plug Sentry.PlugContext - plug Plug.MethodOverride - plug Plug.Head - - @session_options [store: :cookie, - key: "_nola_key", - signing_salt: "+p7K3wrj"] - - - socket "/live", Phoenix.LiveView.Socket, - websocket: [connect_info: [session: @session_options]] - - # The session will be stored in the cookie and signed, - # this means its contents can be read but not tampered with. - # Set :encryption_salt if you would also like to encrypt it. - plug Plug.Session, @session_options - - plug NolaWeb.Router - - @doc """ - Callback invoked for dynamically configuring the endpoint. - - It receives the endpoint configuration and checks if - configuration should be loaded from the system environment. - """ - def init(_key, config) do - if config[:load_from_system_env] do - port = System.get_env("PORT") || raise "expected the PORT environment variable to be set" - {:ok, Keyword.put(config, :http, [:inet6, port: port])} - else - {:ok, config} - end - end -end diff --git a/lib/nola_web/gettext.ex b/lib/nola_web/gettext.ex deleted file mode 100644 index a43cb0d..0000000 --- a/lib/nola_web/gettext.ex +++ /dev/null @@ -1,24 +0,0 @@ -defmodule NolaWeb.Gettext do - @moduledoc """ - A module providing Internationalization with a gettext-based API. - - By using [Gettext](https://hexdocs.pm/gettext), - your module gains a set of macros for translations, for example: - - import NolaWeb.Gettext - - # Simple translation - gettext "Here is the string to translate" - - # Plural translation - ngettext "Here is the string to translate", - "Here are the strings to translate", - 3 - - # Domain-based translation - dgettext "errors", "Here is the error message to translate" - - See the [Gettext Docs](https://hexdocs.pm/gettext) for detailed usage. - """ - use Gettext, otp_app: :nola -end diff --git a/lib/nola_web/live/chat_live.ex b/lib/nola_web/live/chat_live.ex deleted file mode 100644 index 678ea36..0000000 --- a/lib/nola_web/live/chat_live.ex +++ /dev/null @@ -1,120 +0,0 @@ -defmodule NolaWeb.ChatLive do - use Phoenix.LiveView - use Phoenix.HTML - require Logger - - def mount(%{"network" => network, "chan" => chan}, %{"account" => account_id}, socket) do - chan = NolaWeb.reformat_chan(chan) - connection = IRC.Connection.get_network(network, chan) - account = IRC.Account.get(account_id) - membership = IRC.Membership.of_account(IRC.Account.get("DRgpD4fLf8PDJMLp8Dtb")) - if account && connection && Enum.member?(membership, {connection.network, chan}) do - {:ok, _} = Registry.register(IRC.PubSub, "#{connection.network}:events", plugin: __MODULE__) - for t <- ["messages", "triggers", "outputs", "events"] do - {:ok, _} = Registry.register(IRC.PubSub, "#{connection.network}/#{chan}:#{t}", plugin: __MODULE__) - end - - IRC.PuppetConnection.start(account, connection) - - users = IRC.UserTrack.channel(connection.network, chan) - |> Enum.map(fn(tuple) -> IRC.UserTrack.User.from_tuple(tuple) end) - |> Enum.reduce(Map.new, fn(user = %{id: id}, acc) -> - Map.put(acc, id, user) - end) - - backlog = case Nola.IRC.Buffer.select_buffer(connection.network, chan) do - {backlog, _} -> - {backlog, _} = Enum.reduce(backlog, {backlog, nil}, &reduce_contextual_event/2) - Enum.reverse(backlog) - _ -> [] - end - - socket = socket - |> assign(:connection_id, connection.id) - |> assign(:network, connection.network) - |> assign(:chan, chan) - |> assign(:title, "live") - |> assign(:channel, chan) - |> assign(:account_id, account.id) - |> assign(:backlog, backlog) - |> assign(:users, users) - |> assign(:counter, 0) - - {:ok, socket} - else - {:ok, redirect(socket, to: "/")} - end - end - - def handle_event("send", %{"message" => %{"text" => text}}, socket) do - account = IRC.Account.get(socket.assigns.account_id) - IRC.send_message_as(account, socket.assigns.network, socket.assigns.channel, text, true) - {:noreply, assign(socket, :counter, socket.assigns.counter + 1)} - end - - def handle_info({:irc, :event, event = %{type: :join, user_id: id}}, socket) do - if user = IRC.UserTrack.lookup(id) do - socket = socket - |> assign(:users, Map.put(socket.assigns.users, id, user)) - |> append_to_backlog(event) - {:noreply, socket} - else - {:noreply, socket} - end - end - - def handle_info({:irc, :event, event = %{type: :nick, user_id: id, nick: nick}}, socket) do - socket = socket - |> assign(:users, update_in(socket.assigns.users, [id, :nick], nick)) - |> append_to_backlog(event) - {:noreply, socket} - end - - def handle_info({:irc, :event, event = %{type: :quit, user_id: id}}, socket) do - socket = socket - |> assign(:users, Map.delete(socket.assigns.users, id)) - |> append_to_backlog(event) - {:noreply, socket} - end - - def handle_info({:irc, :event, event = %{type: :part, user_id: id}}, socket) do - socket = socket - |> assign(:users, Map.delete(socket.assigns.users, id)) - |> append_to_backlog(event) - {:noreply, socket} - end - - def handle_info({:irc, :trigger, _, message}, socket) do - handle_info({:irc, nil, message}, socket) - end - - def handle_info({:irc, :text, message}, socket) do - IO.inspect({:live_message, message}) - socket = socket - |> append_to_backlog(message) - {:noreply, socket} - end - - def handle_info(info, socket) do - Logger.debug("Unhandled info: #{inspect info}") - {:noreply, socket} - end - - defp append_to_backlog(socket, line) do - {add, _} = reduce_contextual_event(line, {[], List.last(socket.assigns.backlog)}) - assign(socket, :backlog, socket.assigns.backlog ++ add) - end - - defp reduce_contextual_event(line, {acc, nil}) do - {[line | acc], line} - end - defp reduce_contextual_event(line, {acc, last}) do - if NaiveDateTime.to_date(last.at) != NaiveDateTime.to_date(line.at) do - {[%{type: :day_changed, date: NaiveDateTime.to_date(line.at), at: nil}, line | acc], line} - else - {[line | acc], line} - end - - end - -end diff --git a/lib/nola_web/live/chat_live.html.heex b/lib/nola_web/live/chat_live.html.heex deleted file mode 100644 index 29cd6a1..0000000 --- a/lib/nola_web/live/chat_live.html.heex +++ /dev/null @@ -1,91 +0,0 @@ -
- -
-
-

- <%= @network %> - <%= @chan %> -

- -
-
- -
- -
-

- Disconnected :'( -

-

- Oh no error >:( -

- -
    - <%= for message <- @backlog do %> - <%= if is_map(message) && Map.get(message, :__struct__) == IRC.Message do %> -
  • - -
  • - <% end %> - - <%= if is_binary(message) do %> -
  • <%= message %>
  • - <% end %> - - <%= if is_map(message) && Map.get(message, :type) do %> -
  • - - * * * - - - -
  • - <% end %> - <% end %> -
-
- - - -
- - <.form let={f} id={"form-#{@counter}"} for={:message} phx-submit="send" class="w-full px-4 pt-4"> -
-
- <%= text_input f, :text, class: "focus:ring-indigo-500 focus:border-indigo-500 block w-full border rounded-md pl-4 sm:text-sm border-gray-300", autofocus: true, 'phx-hook': "AutoFocus", autocomplete: "off", placeholder: "Don't be shy, say something…" %> - <%= submit content_tag(:span, "Send"), class: "-ml-px relative inline-flex items-center space-x-2 px-4 py-2 border border-gray-300 text-sm font-medium rounded-r-md text-gray-700 bg-gray-50 hover:bg-gray-100 focus:outline-none focus:ring-1 focus:ring-indigo-500 focus:border-indigo-500"%> -
-
- -
diff --git a/lib/nola_web/router.ex b/lib/nola_web/router.ex deleted file mode 100644 index 5658fda..0000000 --- a/lib/nola_web/router.ex +++ /dev/null @@ -1,85 +0,0 @@ -defmodule NolaWeb.Router do - use NolaWeb, :router - - pipeline :browser do - plug :accepts, ["html", "txt"] - plug :fetch_session - plug :fetch_flash - plug :fetch_live_flash - plug :protect_from_forgery - plug :put_secure_browser_headers - plug :put_root_layout, {NolaWeb.LayoutView, :root} - end - - pipeline :api do - plug :accepts, ["json", "sse"] - end - - pipeline :matrix_app_service do - plug :accepts, ["json"] - plug Nola.Matrix.Plug.Auth - plug Nola.Matrix.Plug.SetConfig - end - - scope "/api", NolaWeb do - pipe_through :api - get "/irc-auth.sse", IrcAuthSseController, :sse - post "/sms/callback/Ovh", SmsController, :ovh_callback, as: :sms - end - - scope "/", NolaWeb do - pipe_through :browser - get "/", PageController, :index - - get "/login/irc/:token", PageController, :token, as: :login - get "/login/oidc", OpenIdController, :login - get "/login/oidc/callback", OpenIdController, :callback - - get "/api/untappd/callback", UntappdController, :callback, as: :untappd_callback - - get "/-", IrcController, :index - get "/-/txt", IrcController, :txt - get "/-/txt/:name", IrcController, :txt - get "/-/gpt/prompt/:id", GptController, :task - get "/-/gpt/result/:id", GptController, :result - - get "/-/alcoolog", AlcoologController, :index - get "/-/alcoolog/~/:account_name", AlcoologController, :index - get "/:network", NetworkController, :index - get "/:network/~:nick/alcoolog", AlcoologController, :nick - get "/:network/~:nick/alcoolog/log.json", AlcoologController, :nick_log_json - get "/:network/~:nick/alcoolog/gls.json", AlcoologController, :nick_gls_json - get "/:network/~:nick/alcoolog/volumes.json", AlcoologController, :nick_volumes_json - get "/:network/~:nick/alcoolog/history.json", AlcoologController, :nick_history_json - get "/:network/~:nick/alcoolog/stats.json", AlcoologController, :nick_stats_json - get "/:network/:chan/alcoolog", AlcoologController, :index - get "/:network/:chan/alcoolog/gls.json", AlcoologController, :index_gls_json - get "/:network/:chan/gpt/prompt/:id", GptController, :task - get "/:network/:chan/gpt/result/:id", GptController, :result - put "/api/alcoolog/minisync/:user_id/meta/:key", AlcoologController, :minisync_put_meta - - get "/:network/:chan", IrcController, :index - live "/:network/:chan/live", ChatLive - get "/:network/:chan/txt", IrcController, :txt - get "/:network/:chan/txt/:name", IrcController, :txt - get "/:network/:channel/preums", IrcController, :preums - get "/:network/:chan/alcoolog/t/:token", AlcoologController, :token - end - - scope "/_matrix/:appservice", MatrixAppServiceWeb.V1, as: :matrix do - pipe_through :matrix_app_service - - put "/transactions/:txn_id", TransactionController, :push - - get "/users/:user_id", UserController, :query - get "/rooms/*room_alias", RoomController, :query - - get "/thirdparty/protocol/:protocol", ThirdPartyController, :query_protocol - get "/thirdparty/user/:protocol", ThirdPartyController, :query_users - get "/thirdparty/location/:protocol", ThirdPartyController, :query_locations - get "/thirdparty/location", ThirdPartyController, :query_location_by_alias - get "/thirdparty/user", ThirdPartyController, :query_user_by_id - end - - -end diff --git a/lib/nola_web/templates/alcoolog/auth.html.eex b/lib/nola_web/templates/alcoolog/auth.html.eex deleted file mode 100644 index 6e5cedc..0000000 --- a/lib/nola_web/templates/alcoolog/auth.html.eex +++ /dev/null @@ -1,43 +0,0 @@ -
-

authentication

-
- <%= link("connect using random.sh", to: "/login/oidc", class: "inline-block font-medium underline") %> -
-
- -
-

- <%= if @bot, do: "Send this to #{@bot} on #{@network}:", else: "Find your bot nickname and send:" %>

- /msg <%= @bot || "the-bot-nickname" %> web -

- ... then come back to this address. -

-
- - diff --git a/lib/nola_web/templates/alcoolog/index.html.eex b/lib/nola_web/templates/alcoolog/index.html.eex deleted file mode 100644 index 5a5423a..0000000 --- a/lib/nola_web/templates/alcoolog/index.html.eex +++ /dev/null @@ -1,205 +0,0 @@ - - -<%= if @stats == [] do %> -
-
-
- - - -
-
-

- CATASTROPHE! Personne n'a bu!!!! -

-
-
-
-<% end %> - -
    - <%= for {nick, status} <- @stats do %> -
  • -
    -
    -
    -

    <%= link nick, to: alcoolog_path(@conn, :nick, @network, nick) %>

    - <% rising_class = if status.rising, do: "teal", else: "red" %> - - <%= status.trend_symbol %> <%= Float.round(status.active, 4) %> g/l - -
    -

    - <%= status.last_cl %>cl @ <%= status.last_deg %>° - <%= if status.last_descr && status.last_descr != "" do %> -
    <%= status.last_descr %> - <% end %> -
    <%= NolaWeb.LayoutView.format_time(status.last_at) %> -

    - -

    -
    - — sobre dans: <%= status.sober_in_s %>
    - <%= if status.since do %> - — depuis: <%= status.since_s %>
    - <% end %> - - — 15m: <%= status.active15m %> g/l - 30m: <%= status.active30m %> g/l - 1h: <%= status.active1h %> g/l
    - — aujourd'hui: <%= status.daily_volumes %> points, <%= status.daily_gl %> g/l -
    -

    - - -
    -
    -
  • - <% end %> -
- -<%= if @stats == %{} do %> -
-
-
- - - -
-
-

- ENCORE PIRE! Aucune boisson enregistrée! -

-
-
-
-<% else %> - - - -

Classement 15 jours

- -
    - <%= for {{nick, count}, rank} <- Enum.with_index(@top) do %> - <% rank = rank + 1 %> - <% trophy = rank <= 3 %> - <% {colour, text} = case rank do -1 -> {"yellow-500", "font-semibold text-base"} -2 -> {"gray-500", "font-medium text-base"} -3 -> {"orange-300", "font-medium text-base"} -_ -> {"gray-300", ""} - end %> -
  • - <%= if trophy do %> - - - - <% end %> - #<%= rank %>: <%= link nick, to: alcoolog_path(@conn, :nick, @network, nick) %> -
    - <%= Float.round(count, 4) %> -
  • - <% end %> -
- -

Historique

-
-
-
- - - - - - - - - - - <%= for {{{{account, date}, points, _active, cl, deg, nom, comment, _meta}, nick}, index} <- Enum.with_index(@drinks) do %> - <% class = if(Integer.is_even(index), do: "bg-gray-50", else: "bg-white") %> - <% date = DateTime.from_unix!(date, :millisecond) %> - - - - - - - <% end %> - -
- date - - nick - -   - -   -
- <%= NolaWeb.LayoutView.format_time(date, false) %> - - <%= link nick, to: alcoolog_path(@conn, :nick, @network, nick) %> - <%= cl %>cl <%= deg %>°<%= comment||"" %>
-
-
-
-<% end %> - -<%= if @conn.assigns.account && (@network || @channel) do %> - <%= link("alcoolog global", to: alcoolog_path(@conn, :index)) %> -<% end %> - - - - - - - - diff --git a/lib/nola_web/templates/alcoolog/user.html.eex b/lib/nola_web/templates/alcoolog/user.html.eex deleted file mode 100644 index d7f716b..0000000 --- a/lib/nola_web/templates/alcoolog/user.html.eex +++ /dev/null @@ -1,170 +0,0 @@ -<%= if @stats.active > 0 do %> -

- <% rising_class = if @stats.rising, do: "teal", else: "red" %> - - <%= @stats.trend_symbol %> <%= Float.round(@stats.active, 4) %> g/l - - - <%= @stats.last_cl %>cl @ <%= @stats.last_deg %>° - - <%= if @stats.last_descr && @stats.last_descr != "" do %> - <%= @stats.last_descr %> - <% end %> - - - <%= NolaWeb.LayoutView.format_time(@stats.last_at) %> - -

- -

- a commencé il y a <%= @stats.since_s %> - — - sobre dans <%= @stats.sober_in_s %> -

-<% else %> -

- est sobre! - -

- dernier verre - <%= @stats.last_cl %>cl @ <%= @stats.last_deg %>° - - <%= if @stats.last_descr && @stats.last_descr != "" do %> - <%= @stats.last_descr %> - <% end %> - - - <%= NolaWeb.LayoutView.format_time(@stats.last_at) %> -

-<% end %> - - - - - -

Historique

-
-
-
- - - - - - - - - - <%= for {%{at: date, cl: cl, deg: deg, description: comment}, index} <- Enum.with_index(@history) do %> - <% class = if(Integer.is_even(index), do: "bg-gray-50", else: "bg-white") %> - - - - - - <% end %> - -
- date - -   - -   -
- <%= NolaWeb.LayoutView.format_time(date, false) %> - <%= cl %>cl <%= deg %>°<%= comment||"" %>
-
-
-
- -
- - - - - - - - diff --git a/lib/nola_web/templates/irc/index.html.eex b/lib/nola_web/templates/irc/index.html.eex deleted file mode 100644 index 182624d..0000000 --- a/lib/nola_web/templates/irc/index.html.eex +++ /dev/null @@ -1,44 +0,0 @@ - - -<%= if @members != [] do %> -
    - <%= for user <- @members do %>
  • <%= user.nick %>
  • <% end %> -
-<% end %> - -
- <%= for {identifier, help} <- @commands do %> - <%= if help do %> -
-
<%= NolaWeb.LayoutView.liquid_markdown(@conn, help) %>
-
- <% end %> - <% end %> -
- -


- -

- - Légende:
- entre < >: argument obligatoire,
- entre [ ]: argument optionel; [1 | ]: argument optionel avec valeur par défaut. -
-

- -


- -

- - running beautte version <%= Nola.version() %> — git - -

diff --git a/lib/nola_web/templates/irc/txt.html.eex b/lib/nola_web/templates/irc/txt.html.eex deleted file mode 100644 index fd4ea00..0000000 --- a/lib/nola_web/templates/irc/txt.html.eex +++ /dev/null @@ -1,27 +0,0 @@ - - -
    - <%= for {txt, id} <- Enum.with_index(@data) do %> -
  1. - - <%= txt %> - # -
  2. - <% end %> -
- -

- télécharger au format texte -

diff --git a/lib/nola_web/templates/irc/txts.html.eex b/lib/nola_web/templates/irc/txts.html.eex deleted file mode 100644 index aff0c5d..0000000 --- a/lib/nola_web/templates/irc/txts.html.eex +++ /dev/null @@ -1,49 +0,0 @@ -
-

- <%= @lines %> lignes dans <%= @files %> fichiers - Aide - Fichiers système -

-
    - <%= for {txt, data} <- @data do %> - <% base_url = cond do - @conn.assigns[:chan] -> "/#{@conn.assigns.network}/#{NolaWeb.format_chan(@conn.assigns.chan)}" - true -> "/-" - end %> -
  • -
    -
    - <%= txt %> -

    <%= Enum.count(data) %> lignes

    -
    -
    -
  • - <% end %> -
-
- -
<%= NolaWeb.LayoutView.liquid_markdown(@conn, @doc) %>
- -
-

- Fichiers système -

- -
    - <%= for {txt, data} <- @system do %> - <% base_url = cond do - @conn.assigns[:chan] -> "/#{@conn.assigns.network}/#{NolaWeb.format_chan(@conn.assigns.chan)}" - true -> "/-" - end %> -
  • -
    -
    - <%= txt %> -

    <%= Enum.count(data) %> lignes

    -
    -
    -
  • - <% end %> -
- -
diff --git a/lib/nola_web/templates/layout/app.html.eex b/lib/nola_web/templates/layout/app.html.eex deleted file mode 100644 index c774369..0000000 --- a/lib/nola_web/templates/layout/app.html.eex +++ /dev/null @@ -1,126 +0,0 @@ -
-
- -
-
-

- <%= if n = @conn.assigns[:network] do %><%= n %> › <% end %> - <%= if c = @conn.assigns[:chan] do %><%= c %> › <% end %> - <%= for({name, href} <- Enum.uniq(@conn.assigns[:breadcrumbs]||[]), do: [link(name, to: href), raw(" › ")]) %> - <%= @conn.assigns[:title] %> -

-
-
-
- -
-
- -
- <%= @inner_content %> -
- -
-
-
diff --git a/lib/nola_web/templates/layout/root.html.leex b/lib/nola_web/templates/layout/root.html.leex deleted file mode 100644 index 6a48506..0000000 --- a/lib/nola_web/templates/layout/root.html.leex +++ /dev/null @@ -1,18 +0,0 @@ - - - - <%= page_title(@conn) %> - - - - - - <%= Map.get(assigns, :title, "") %> - "> - <%= csrf_meta_tag() %> - - - - <%= @inner_content %> - - diff --git a/lib/nola_web/templates/network/index.html.eex b/lib/nola_web/templates/network/index.html.eex deleted file mode 100644 index fc024dd..0000000 --- a/lib/nola_web/templates/network/index.html.eex +++ /dev/null @@ -1 +0,0 @@ -pouet diff --git a/lib/nola_web/templates/open_id/error.html.eex b/lib/nola_web/templates/open_id/error.html.eex deleted file mode 100644 index d1b35b9..0000000 --- a/lib/nola_web/templates/open_id/error.html.eex +++ /dev/null @@ -1,3 +0,0 @@ -

OpenID authentication error

- -

<%= @error %>

diff --git a/lib/nola_web/templates/page/api.html.eex b/lib/nola_web/templates/page/api.html.eex deleted file mode 100644 index 03dfa6b..0000000 --- a/lib/nola_web/templates/page/api.html.eex +++ /dev/null @@ -1,35 +0,0 @@ -

sys.115ans.net/api

- -

Icecast Status

- -

GET /api/icecast.json

- -

- Content-Type: application/json -

- -

-{
-  "np": String,
-  "genre": null | String,
-  "live": false | true
-}
-
- -

GET /api/icecast.sse

-

- Content-Type: text/event-stream -

- -

- Stream of: -

- -
    -
  • icecast events (same format as /api/icecast.json)
  • -
  • ping events (to keep-alive connection. You can safely ignore them)
  • -
-

- On client connection, the server sends the latest icecast status known. -

- diff --git a/lib/nola_web/templates/page/index.html.eex b/lib/nola_web/templates/page/index.html.eex deleted file mode 100644 index 1b8519a..0000000 --- a/lib/nola_web/templates/page/index.html.eex +++ /dev/null @@ -1 +0,0 @@ -

vOv

diff --git a/lib/nola_web/templates/page/irc.html.eex b/lib/nola_web/templates/page/irc.html.eex deleted file mode 100644 index f6598ee..0000000 --- a/lib/nola_web/templates/page/irc.html.eex +++ /dev/null @@ -1,19 +0,0 @@ -

bot `115ans

- -

Si vous cherchez l'IRC c'est par là.

- - - -
- <%= for help <- @bot_helps do %> -
<%= help |> Earmark.as_html! |> raw() %>
- <% end %> -
- diff --git a/lib/nola_web/templates/page/user.html.eex b/lib/nola_web/templates/page/user.html.eex deleted file mode 100644 index de9f718..0000000 --- a/lib/nola_web/templates/page/user.html.eex +++ /dev/null @@ -1,43 +0,0 @@ -
-
    -
  • <%= link("Help", to: "/-") %>
  • - <%= unless List.keyfind(@metas, "identity-id", 0) do %> -
  • <%= link("Connect with random.sh", to: Routes.open_id_path(@conn, :login)) %>
  • - <% end %> -
- -

channels

-
    - <%= for {net, channel} <- @memberships do %> -
  • - <% url = NolaWeb.Router.Helpers.irc_path(NolaWeb.Endpoint, :index, net, NolaWeb.format_chan(channel)) %> - <%= link([net, ": ", content_tag(:strong, channel)], to: url) %> -
  • - <% end %> -
- -

connections

-
    - <%= for user <- @users do %> -
  • - <%= user.network %>: <%= user.nick %>!<%= user.username %>@<%= user.host %> <%= user.realname %>
    - <%= Enum.join(Enum.intersperse(Enum.map(user.privileges, fn({c, _}) -> c end), ", ")) %> -
  • - <% end %> -
- -

account

-
    -
  • account-id: <%= @conn.assigns.account.id %>
  • - <%= for {k, v} <- @metas do %> -
  • <%= k %>: <%= to_string(v) %>
  • - <% end %> -
- -irc auths: -
    - <%= for {net, {predicate, v}} <- @predicates do %> -
  • <%= net %>: <%= to_string(predicate) %>, <%= v %>
  • - <% end %> -
-
diff --git a/lib/nola_web/templates/page/widget.html.eex b/lib/nola_web/templates/page/widget.html.eex deleted file mode 100644 index 65853b3..0000000 --- a/lib/nola_web/templates/page/widget.html.eex +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - -"> - - - - -
"> -
-
-
<%= @icecast.genre %>
-
<%= @icecast.np %>
-
-
- - diff --git a/lib/nola_web/views/alcoolog_view.ex b/lib/nola_web/views/alcoolog_view.ex deleted file mode 100644 index ad52472..0000000 --- a/lib/nola_web/views/alcoolog_view.ex +++ /dev/null @@ -1,6 +0,0 @@ -defmodule NolaWeb.AlcoologView do - use NolaWeb, :view - require Integer - -end - diff --git a/lib/nola_web/views/error_helpers.ex b/lib/nola_web/views/error_helpers.ex deleted file mode 100644 index 25214bd..0000000 --- a/lib/nola_web/views/error_helpers.ex +++ /dev/null @@ -1,40 +0,0 @@ -defmodule NolaWeb.ErrorHelpers do - @moduledoc """ - Conveniences for translating and building error messages. - """ - - use Phoenix.HTML - - @doc """ - Generates tag for inlined form input errors. - """ - def error_tag(form, field) do - Enum.map(Keyword.get_values(form.errors, field), fn (error) -> - content_tag :span, translate_error(error), class: "help-block" - end) - end - - @doc """ - Translates an error message using gettext. - """ - def translate_error({msg, opts}) do - # Because error messages were defined within Ecto, we must - # call the Gettext module passing our Gettext backend. We - # also use the "errors" domain as translations are placed - # in the errors.po file. - # Ecto will pass the :count keyword if the error message is - # meant to be pluralized. - # On your own code and templates, depending on whether you - # need the message to be pluralized or not, this could be - # written simply as: - # - # dngettext "errors", "1 file", "%{count} files", count - # dgettext "errors", "is invalid" - # - if count = opts[:count] do - Gettext.dngettext(NolaWeb.Gettext, "errors", msg, msg, count, opts) - else - Gettext.dgettext(NolaWeb.Gettext, "errors", msg, opts) - end - end -end diff --git a/lib/nola_web/views/error_view.ex b/lib/nola_web/views/error_view.ex deleted file mode 100644 index 5cad939..0000000 --- a/lib/nola_web/views/error_view.ex +++ /dev/null @@ -1,17 +0,0 @@ -defmodule NolaWeb.ErrorView do - use NolaWeb, :view - - def render("404.html", _assigns) do - "Page not found" - end - - def render("500.html", _assigns) do - "Internal server error" - end - - # In case no render clause matches or no - # template is found, let's render it as 500 - def template_not_found(_template, assigns) do - render "500.html", assigns - end -end diff --git a/lib/nola_web/views/irc_view.ex b/lib/nola_web/views/irc_view.ex deleted file mode 100644 index 331d91f..0000000 --- a/lib/nola_web/views/irc_view.ex +++ /dev/null @@ -1,3 +0,0 @@ -defmodule NolaWeb.IrcView do - use NolaWeb, :view -end diff --git a/lib/nola_web/views/layout_view.ex b/lib/nola_web/views/layout_view.ex deleted file mode 100644 index 2bffc6f..0000000 --- a/lib/nola_web/views/layout_view.ex +++ /dev/null @@ -1,81 +0,0 @@ -defmodule NolaWeb.LayoutView do - use NolaWeb, :view - - def liquid_markdown(conn, text) do - context_path = cond do - conn.assigns[:chan] -> "/#{conn.assigns[:network]}/#{NolaWeb.format_chan(conn.assigns[:chan])}" - conn.assigns[:network] -> "/#{conn.assigns[:network]}/-" - true -> "/-" - end - - {:ok, ast} = Liquex.parse(text) - context = Liquex.Context.new(%{ - "context_path" => context_path - }) - {content, _} = Liquex.render(ast, context) - content - |> to_string() - |> Earmark.as_html!() - |> raw() - end - - def page_title(conn) do - target = cond do - conn.assigns[:chan] -> - "#{conn.assigns.chan} @ #{conn.assigns.network}" - conn.assigns[:network] -> conn.assigns.network - true -> Keyword.get(Nola.name()) - end - - breadcrumb_title = Enum.map(Map.get(conn.assigns, :breadcrumbs)||[], fn({title, _href}) -> title end) - - title = [conn.assigns[:title], breadcrumb_title, target] - |> List.flatten() - |> Enum.uniq() - |> Enum.filter(fn(x) -> x end) - |> Enum.intersperse(" / ") - |> Enum.join() - - content_tag(:title, title) - end - - def format_time(date, with_relative \\ true) do - alias Timex.Format.DateTime.Formatters - alias Timex.Timezone - date = if is_integer(date) do - date - |> DateTime.from_unix!(:millisecond) - |> DateTime.shift_zone!("Europe/Paris", Tzdata.TimeZoneDatabase) - else - date - |> DateTime.shift_zone!("Europe/Paris", Tzdata.TimeZoneDatabase) - end - - now = DateTime.now!("Europe/Paris", Tzdata.TimeZoneDatabase) - - now_week = Timex.iso_week(now) - date_week = Timex.iso_week(date) - - {y, w} = now_week - now_last_week = {y, w-1} - now_last_roll = 7-Timex.days_to_beginning_of_week(now) - - date_date = DateTime.to_date(date) - now_date = DateTime.to_date(date) - - format = cond do - date.year != now.year -> "{D}/{M}/{YYYY} {h24}:{m}" - date_date == now_date -> "{h24}:{m}" - (now_week == date_week) || (date_week == now_last_week && (Date.day_of_week(date) >= now_last_roll)) -> "{WDfull} {h24}:{m}" - (now.year == date.year && now.month == date.month) -> "{WDfull} {D} {h24}:{m}" - true -> "{WDfull} {D} {M} {h24}:{m}" - end - - {:ok, relative} = Formatters.Relative.relative_to(date, Timex.now("Europe/Paris"), "{relative}", "fr") - {:ok, full} = Formatters.Default.lformat(date, "{WDfull} {D} {YYYY} {h24}:{m}", "fr") #"{h24}:{m} {WDfull} {D}", "fr") - {:ok, detail} = Formatters.Default.lformat(date, format, "fr") #"{h24}:{m} {WDfull} {D}", "fr") - - content_tag(:time, if(with_relative, do: relative, else: detail), [title: full]) - end - -end diff --git a/lib/nola_web/views/network_view.ex b/lib/nola_web/views/network_view.ex deleted file mode 100644 index 7a24db1..0000000 --- a/lib/nola_web/views/network_view.ex +++ /dev/null @@ -1,4 +0,0 @@ -defmodule NolaWeb.NetworkView do - use NolaWeb, :view - -end diff --git a/lib/nola_web/views/open_id_view.ex b/lib/nola_web/views/open_id_view.ex deleted file mode 100644 index bd8089b..0000000 --- a/lib/nola_web/views/open_id_view.ex +++ /dev/null @@ -1,4 +0,0 @@ -defmodule NolaWeb.OpenIdView do - use NolaWeb, :view - -end diff --git a/lib/nola_web/views/page_view.ex b/lib/nola_web/views/page_view.ex deleted file mode 100644 index 1bfaadd..0000000 --- a/lib/nola_web/views/page_view.ex +++ /dev/null @@ -1,3 +0,0 @@ -defmodule NolaWeb.PageView do - use NolaWeb, :view -end diff --git a/lib/nola_web/web.ex b/lib/nola_web/web.ex deleted file mode 100644 index 906e961..0000000 --- a/lib/nola_web/web.ex +++ /dev/null @@ -1,99 +0,0 @@ -defmodule NolaWeb do - @moduledoc """ - The entrypoint for defining your web interface, such - as controllers, views, channels and so on. - - This can be used in your application as: - - use NolaWeb, :controller - use NolaWeb, :view - - The definitions below will be executed for every view, - controller, etc, so keep them short and clean, focused - on imports, uses and aliases. - - Do NOT define functions inside the quoted expressions - below. Instead, define any helper function in modules - and import those modules here. - """ - - def format_chan("##") do - "♯♯" - end - - def format_chan("#") do - "♯" - end - - def format_chan("#"<>chan) do - chan - end - - def format_chan(chan = "!"<>_), do: chan - - def reformat_chan("♯") do - "#" - end - def reformat_chan("♯♯") do - "##" - end - def reformat_chan(chan = "!"<>_), do: chan - - def reformat_chan(chan) do - "#"<>chan - end - - def controller do - quote do - use Phoenix.Controller, namespace: NolaWeb - import Plug.Conn - import NolaWeb.Router.Helpers - import NolaWeb.Gettext - alias NolaWeb.Router.Helpers, as: Routes - end - end - - def view do - quote do - use Phoenix.View, root: "lib/nola_web/templates", - namespace: NolaWeb - - # Import convenience functions from controllers - import Phoenix.Controller, only: [get_flash: 2, view_module: 1] - - # Use all HTML functionality (forms, tags, etc) - use Phoenix.HTML - - import NolaWeb.Router.Helpers - import NolaWeb.ErrorHelpers - import NolaWeb.Gettext - - import Phoenix.LiveView.Helpers - - alias NolaWeb.Router.Helpers, as: Routes - end - end - - def router do - quote do - use Phoenix.Router - import Plug.Conn - import Phoenix.Controller - import Phoenix.LiveView.Router - end - end - - def channel do - quote do - use Phoenix.Channel - import NolaWeb.Gettext - end - end - - @doc """ - When used, dispatch to the appropriate controller/view/etc. - """ - defmacro __using__(which) when is_atom(which) do - apply(__MODULE__, which, []) - end -end -- cgit v1.2.3