diff --git a/.credo.exs b/.credo.exs index 9965c2f..68af380 100644 --- a/.credo.exs +++ b/.credo.exs @@ -82,8 +82,7 @@ # You can customize the priority of any check # Priority values are: `low, normal, high, higher` # - {Credo.Check.Design.AliasUsage, - [priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 0]}, + {Credo.Check.Design.AliasUsage, [priority: :low, if_nested_deeper_than: 2, if_called_more_often_than: 0]}, # You can also customize the exit_status of each check. # If you don't want TODO comments to cause `mix credo` to fail, just # set this value to 0 (zero). diff --git a/.formatter.exs b/.formatter.exs index 3c78c0b..b1c74c3 100644 --- a/.formatter.exs +++ b/.formatter.exs @@ -1,6 +1,6 @@ [ import_deps: [:ecto, :ecto_sql, :phoenix, :stream_data], subdirectories: ["priv/*/migrations"], - plugins: [Phoenix.LiveView.HTMLFormatter,Styler], + plugins: [Phoenix.LiveView.HTMLFormatter, Styler], inputs: ["*.{heex,ex,exs}", "{config,lib,test}/**/*.{heex,ex,exs}", "priv/*/seeds.exs"] ] diff --git a/config/config.exs b/config/config.exs index a677b8f..58c5e1d 100644 --- a/config/config.exs +++ b/config/config.exs @@ -33,8 +33,7 @@ config :aprs, Aprs.Mailer, adapter: Swoosh.Adapters.Local config :esbuild, version: "0.14.41", default: [ - args: - ~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*), + args: ~w(js/app.js --bundle --target=es2017 --outdir=../priv/static/assets --external:/fonts/* --external:/images/*), cd: Path.expand("../assets", __DIR__), env: %{"NODE_PATH" => Path.expand("../deps", __DIR__)} ] @@ -62,7 +61,7 @@ config :phoenix, :json_library, Jason config :aprs, ecto_repos: [Aprs.Repo], aprs_is_server: System.get_env("APRS_SERVER", "dallas.aprs2.net"), - aprs_is_port: 14580, + aprs_is_port: 14_580, aprs_is_default_filter: System.get_env("APRS_FILTER"), aprs_is_login_id: System.get_env("APRS_CALLSIGN"), aprs_is_password: System.get_env("APRS_PASSCODE"), diff --git a/config/runtime.exs b/config/runtime.exs index 2c6ed13..9da49bd 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -66,7 +66,7 @@ if config_env() == :prod do config :aprs, ecto_repos: [Aprs.Repo], aprs_is_server: System.get_env("APRS_SERVER", "dallas.aprs2.net"), - aprs_is_port: 14580, + aprs_is_port: 14_580, aprs_is_default_filter: System.get_env("APRS_FILTER"), aprs_is_login_id: System.get_env("APRS_CALLSIGN"), aprs_is_password: System.get_env("APRS_PASSCODE") diff --git a/lib/aprs/accounts.ex b/lib/aprs/accounts.ex index 643cefe..f192352 100644 --- a/lib/aprs/accounts.ex +++ b/lib/aprs/accounts.ex @@ -4,9 +4,11 @@ defmodule Aprs.Accounts do """ import Ecto.Query, warn: false - alias Aprs.Repo - alias Aprs.Accounts.{User, UserToken, UserNotifier} + alias Aprs.Accounts.User + alias Aprs.Accounts.UserNotifier + alias Aprs.Accounts.UserToken + alias Aprs.Repo ## Database getters @@ -38,8 +40,7 @@ defmodule Aprs.Accounts do nil """ - def get_user_by_email_and_password(email, password) - when is_binary(email) and is_binary(password) do + def get_user_by_email_and_password(email, password) when is_binary(email) and is_binary(password) do user = Repo.get_by(User, email: email) if User.valid_password?(user, password), do: user end diff --git a/lib/aprs/accounts/user.ex b/lib/aprs/accounts/user.ex index 351d62c..f392740 100644 --- a/lib/aprs/accounts/user.ex +++ b/lib/aprs/accounts/user.ex @@ -1,5 +1,7 @@ defmodule Aprs.Accounts.User do + @moduledoc false use Ecto.Schema + import Ecto.Changeset schema "users" do @@ -122,7 +124,7 @@ defmodule Aprs.Accounts.User do Confirms the account by setting `confirmed_at`. """ def confirm_changeset(user) do - now = NaiveDateTime.utc_now() |> NaiveDateTime.truncate(:second) + now = NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second) change(user, confirmed_at: now) end diff --git a/lib/aprs/accounts/user_notifier.ex b/lib/aprs/accounts/user_notifier.ex index 9b7be9e..6116c9d 100644 --- a/lib/aprs/accounts/user_notifier.ex +++ b/lib/aprs/accounts/user_notifier.ex @@ -1,4 +1,5 @@ defmodule Aprs.Accounts.UserNotifier do + @moduledoc false import Swoosh.Email alias Aprs.Mailer diff --git a/lib/aprs/accounts/user_token.ex b/lib/aprs/accounts/user_token.ex index 12c888d..42f22f1 100644 --- a/lib/aprs/accounts/user_token.ex +++ b/lib/aprs/accounts/user_token.ex @@ -1,6 +1,9 @@ defmodule Aprs.Accounts.UserToken do + @moduledoc false use Ecto.Schema + import Ecto.Query + alias Aprs.Accounts.UserToken @hash_algorithm :sha256 diff --git a/lib/aprs/archiver.ex b/lib/aprs/archiver.ex index fc970dd..6dedd17 100644 --- a/lib/aprs/archiver.ex +++ b/lib/aprs/archiver.ex @@ -1,11 +1,13 @@ defmodule Aprs.Archiver do + @moduledoc false use GenServer + + alias AprsWeb.Endpoint + require Jason require Logger # alias Aprs.{Packet, Repo} - alias AprsWeb.Endpoint - @topic "call" # API diff --git a/lib/aprs/convert.ex b/lib/aprs/convert.ex index 47054b4..e90dc37 100644 --- a/lib/aprs/convert.ex +++ b/lib/aprs/convert.ex @@ -1,4 +1,5 @@ defmodule Aprs.Convert do + @moduledoc false def wind(speed, :ultimeter, :mph), do: speed * 0.0621371192 def temp(value, :ultimeter, :f), do: value * 0.1 diff --git a/lib/aprs/data_extended.ex b/lib/aprs/data_extended.ex index f9a9798..7f32bbc 100644 --- a/lib/aprs/data_extended.ex +++ b/lib/aprs/data_extended.ex @@ -1,6 +1,9 @@ defmodule Aprs.DataExtended do + @moduledoc false use Ecto.Schema + import Ecto.Changeset + alias Aprs.DataExtended embedded_schema do diff --git a/lib/aprs/is/is.ex b/lib/aprs/is/is.ex index bca3c1b..76ace59 100644 --- a/lib/aprs/is/is.ex +++ b/lib/aprs/is/is.ex @@ -1,5 +1,7 @@ defmodule Aprs.Is do + @moduledoc false use GenServer + require Logger @aprs_timeout 30 * 1000 @@ -14,7 +16,7 @@ defmodule Aprs.Is do Process.flag(:trap_exit, true) # Get startup parameters - server = Application.get_env(:aprs, :aprs_is_server, 'rotate.aprs2.net') + server = Application.get_env(:aprs, :aprs_is_server, ~c"rotate.aprs2.net") port = Application.get_env(:aprs, :aprs_is_port, 14_580) default_filter = Application.get_env(:aprs, :aprs_is_default_filter, "r/33/-96/100") aprs_user_id = Application.get_env(:aprs, :aprs_is_login_id, "w5isp") @@ -40,8 +42,9 @@ defmodule Aprs.Is do # end with {:ok, socket} <- connect_to_aprs_is(server, port), - :ok <- send_login_string(socket, aprs_user_id, aprs_passcode, default_filter), - timer <- create_timer(@aprs_timeout) do + :ok <- send_login_string(socket, aprs_user_id, aprs_passcode, default_filter) do + timer = create_timer(@aprs_timeout) + {:ok, %{ server: server, diff --git a/lib/aprs/is/is_supervisor.ex b/lib/aprs/is/is_supervisor.ex index 60c7a7c..9cca041 100644 --- a/lib/aprs/is/is_supervisor.ex +++ b/lib/aprs/is/is_supervisor.ex @@ -1,4 +1,5 @@ defmodule Aprs.Is.IsSupervisor do + @moduledoc false use Supervisor def start_link(opts) do diff --git a/lib/aprs/mailer.ex b/lib/aprs/mailer.ex index 579acb7..31ac5f0 100644 --- a/lib/aprs/mailer.ex +++ b/lib/aprs/mailer.ex @@ -1,3 +1,4 @@ defmodule Aprs.Mailer do + @moduledoc false use Swoosh.Mailer, otp_app: :aprs end diff --git a/lib/aprs/packet.ex b/lib/aprs/packet.ex index 3e1f190..a4c2241 100644 --- a/lib/aprs/packet.ex +++ b/lib/aprs/packet.ex @@ -1,6 +1,9 @@ defmodule Aprs.Packet do + @moduledoc false use Aprs.Schema + import Ecto.Changeset + alias Aprs.DataExtended schema "packets" do diff --git a/lib/aprs/presence.ex b/lib/aprs/presence.ex index 4a21696..680071d 100644 --- a/lib/aprs/presence.ex +++ b/lib/aprs/presence.ex @@ -1,3 +1,4 @@ defmodule Aprs.Presence do + @moduledoc false use Phoenix.Presence, otp_app: :aprs, pubsub_server: Aprs.PubSub end diff --git a/lib/aprs/schema.ex b/lib/aprs/schema.ex index 31b35b5..9f26e92 100644 --- a/lib/aprs/schema.ex +++ b/lib/aprs/schema.ex @@ -1,7 +1,9 @@ defmodule Aprs.Schema do + @moduledoc false defmacro __using__(_) do quote do use Ecto.Schema + @primary_key {:id, :binary_id, autogenerate: true} @foreign_key_type :binary_id end diff --git a/lib/aprs_web.ex b/lib/aprs_web.ex index 3b935cc..c82cb13 100644 --- a/lib/aprs_web.ex +++ b/lib/aprs_web.ex @@ -24,9 +24,9 @@ defmodule AprsWeb do use Phoenix.Router, helpers: false # Import common connection and controller functions to use in pipelines - import Plug.Conn import Phoenix.Controller import Phoenix.LiveView.Router + import Plug.Conn end end @@ -43,8 +43,8 @@ defmodule AprsWeb do formats: [:html, :json], layouts: [html: AprsWeb.Layouts] - import Plug.Conn import AprsWeb.Gettext + import Plug.Conn unquote(verified_routes()) end @@ -83,10 +83,10 @@ defmodule AprsWeb do defp html_helpers do quote do # HTML escaping functionality - import Phoenix.HTML # Core UI components and translation import AprsWeb.CoreComponents import AprsWeb.Gettext + import Phoenix.HTML # Shortcut for generating JS commands alias Phoenix.LiveView.JS diff --git a/lib/aprs_web/components/core_components.ex b/lib/aprs_web/components/core_components.ex index b8f21a8..df73f27 100644 --- a/lib/aprs_web/components/core_components.ex +++ b/lib/aprs_web/components/core_components.ex @@ -11,9 +11,10 @@ defmodule AprsWeb.CoreComponents do """ use Phoenix.Component - alias Phoenix.LiveView.JS import AprsWeb.Gettext + alias Phoenix.LiveView.JS + @doc """ Renders a modal. @@ -359,11 +360,9 @@ defmodule AprsWeb.CoreComponents do """ end - defp input_border([] = _errors), - do: "border-zinc-300 focus:border-zinc-400 focus:ring-zinc-800/5" + defp input_border([] = _errors), do: "border-zinc-300 focus:border-zinc-400 focus:ring-zinc-800/5" - defp input_border([_ | _] = _errors), - do: "border-rose-400 focus:border-rose-400 focus:ring-rose-400/10" + defp input_border([_ | _] = _errors), do: "border-rose-400 focus:border-rose-400 focus:ring-rose-400/10" @doc """ Renders a label. @@ -543,8 +542,7 @@ defmodule AprsWeb.CoreComponents do JS.show(js, to: selector, transition: - {"transition-all transform ease-out duration-300", - "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95", + {"transition-all transform ease-out duration-300", "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95", "opacity-100 translate-y-0 sm:scale-100"} ) end @@ -554,8 +552,7 @@ defmodule AprsWeb.CoreComponents do to: selector, time: 200, transition: - {"transition-all transform ease-in duration-200", - "opacity-100 translate-y-0 sm:scale-100", + {"transition-all transform ease-in duration-200", "opacity-100 translate-y-0 sm:scale-100", "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"} ) end diff --git a/lib/aprs_web/components/layouts.ex b/lib/aprs_web/components/layouts.ex index 61765fb..294e433 100644 --- a/lib/aprs_web/components/layouts.ex +++ b/lib/aprs_web/components/layouts.ex @@ -1,4 +1,5 @@ defmodule AprsWeb.Layouts do + @moduledoc false use AprsWeb, :html embed_templates "layouts/*" diff --git a/lib/aprs_web/live/packets_live/index.ex b/lib/aprs_web/live/packets_live/index.ex index 2ea5b5d..17c1512 100644 --- a/lib/aprs_web/live/packets_live/index.ex +++ b/lib/aprs_web/live/packets_live/index.ex @@ -1,5 +1,7 @@ defmodule AprsWeb.PacketsLive.Index do + @moduledoc false use AprsWeb, :live_view + alias AprsWeb.Endpoint @impl true diff --git a/lib/aprs_web/live/user_confirmation_instructions_live.ex b/lib/aprs_web/live/user_confirmation_instructions_live.ex index 1bc0118..bb44f66 100644 --- a/lib/aprs_web/live/user_confirmation_instructions_live.ex +++ b/lib/aprs_web/live/user_confirmation_instructions_live.ex @@ -1,4 +1,5 @@ defmodule AprsWeb.UserConfirmationInstructionsLive do + @moduledoc false use AprsWeb, :live_view alias Aprs.Accounts @@ -16,8 +17,7 @@ defmodule AprsWeb.UserConfirmationInstructionsLive do
<.link href={~p"/users/register"}>Register - | - <.link href={~p"/users/log_in"}>Log in + | <.link href={~p"/users/log_in"}>Log in
""" end diff --git a/lib/aprs_web/live/user_confirmation_live.ex b/lib/aprs_web/live/user_confirmation_live.ex index 01e85d8..86247fe 100644 --- a/lib/aprs_web/live/user_confirmation_live.ex +++ b/lib/aprs_web/live/user_confirmation_live.ex @@ -1,4 +1,5 @@ defmodule AprsWeb.UserConfirmationLive do + @moduledoc false use AprsWeb, :live_view alias Aprs.Accounts @@ -17,8 +18,7 @@ defmodule AprsWeb.UserConfirmationLive do<.link href={~p"/users/register"}>Register - | - <.link href={~p"/users/log_in"}>Log in + | <.link href={~p"/users/log_in"}>Log in
""" diff --git a/lib/aprs_web/live/user_forgot_password_live.ex b/lib/aprs_web/live/user_forgot_password_live.ex index f28a061..48fe0cd 100644 --- a/lib/aprs_web/live/user_forgot_password_live.ex +++ b/lib/aprs_web/live/user_forgot_password_live.ex @@ -1,4 +1,5 @@ defmodule AprsWeb.UserForgotPasswordLive do + @moduledoc false use AprsWeb, :live_view alias Aprs.Accounts @@ -21,8 +22,7 @@ defmodule AprsWeb.UserForgotPasswordLive do<.link href={~p"/users/register"}>Register - | - <.link href={~p"/users/log_in"}>Log in + | <.link href={~p"/users/log_in"}>Log in
""" diff --git a/lib/aprs_web/live/user_login_live.ex b/lib/aprs_web/live/user_login_live.ex index a2e6e0b..dee5bb0 100644 --- a/lib/aprs_web/live/user_login_live.ex +++ b/lib/aprs_web/live/user_login_live.ex @@ -1,4 +1,5 @@ defmodule AprsWeb.UserLoginLive do + @moduledoc false use AprsWeb, :live_view def render(assigns) do diff --git a/lib/aprs_web/live/user_registration_live.ex b/lib/aprs_web/live/user_registration_live.ex index dc85e05..b8d84c9 100644 --- a/lib/aprs_web/live/user_registration_live.ex +++ b/lib/aprs_web/live/user_registration_live.ex @@ -1,4 +1,5 @@ defmodule AprsWeb.UserRegistrationLive do + @moduledoc false use AprsWeb, :live_view alias Aprs.Accounts diff --git a/lib/aprs_web/live/user_reset_password_live.ex b/lib/aprs_web/live/user_reset_password_live.ex index 74a385f..c782cd0 100644 --- a/lib/aprs_web/live/user_reset_password_live.ex +++ b/lib/aprs_web/live/user_reset_password_live.ex @@ -1,4 +1,5 @@ defmodule AprsWeb.UserResetPasswordLive do + @moduledoc false use AprsWeb, :live_view alias Aprs.Accounts @@ -33,8 +34,7 @@ defmodule AprsWeb.UserResetPasswordLive do<.link href={~p"/users/register"}>Register - | - <.link href={~p"/users/log_in"}>Log in + | <.link href={~p"/users/log_in"}>Log in
""" diff --git a/lib/aprs_web/live/user_settings_live.ex b/lib/aprs_web/live/user_settings_live.ex index 3e0c89f..120de75 100644 --- a/lib/aprs_web/live/user_settings_live.ex +++ b/lib/aprs_web/live/user_settings_live.ex @@ -1,4 +1,5 @@ defmodule AprsWeb.UserSettingsLive do + @moduledoc false use AprsWeb, :live_view alias Aprs.Accounts diff --git a/lib/aprs_web/telemetry.ex b/lib/aprs_web/telemetry.ex index fae8dd2..4c3ff7b 100644 --- a/lib/aprs_web/telemetry.ex +++ b/lib/aprs_web/telemetry.ex @@ -1,5 +1,7 @@ defmodule AprsWeb.Telemetry do + @moduledoc false use Supervisor + import Telemetry.Metrics def start_link(arg) do @@ -70,8 +72,7 @@ defmodule AprsWeb.Telemetry do ), summary("aprs.repo.query.idle_time", unit: {:native, :millisecond}, - description: - "The time the connection spent waiting before being checked out for the query" + description: "The time the connection spent waiting before being checked out for the query" ), # VM Metrics diff --git a/lib/aprs_web/user_auth.ex b/lib/aprs_web/user_auth.ex index 3b1e993..75afd35 100644 --- a/lib/aprs_web/user_auth.ex +++ b/lib/aprs_web/user_auth.ex @@ -1,8 +1,9 @@ defmodule AprsWeb.UserAuth do + @moduledoc false use AprsWeb, :verified_routes - import Plug.Conn import Phoenix.Controller + import Plug.Conn alias Aprs.Accounts diff --git a/lib/parser.ex b/lib/parser.ex index 86d6ab2..b89252e 100644 --- a/lib/parser.ex +++ b/lib/parser.ex @@ -3,44 +3,46 @@ defmodule Parser do Main parsing library """ # import Bitwise - alias Aprs.{Convert, Packet} - alias Parser.Types.{MicE, Position} + alias Aprs.Convert + alias Aprs.Packet + alias Parser.Types.MicE + alias Parser.Types.Position + require Logger def parse(message) do - try do - [sender, path, data] = String.split(message, [">", ":"], parts: 3) + [sender, path, data] = String.split(message, [">", ":"], parts: 3) - with [base_callsign, ssid] <- parse_callsign(sender), - data_type <- parse_datatype(String.first(data)), - data <- String.trim(data), - [destination, path] <- String.split(path, ",", parts: 2), - data_extended <- parse_data(data_type, destination, data) do - {:ok, - %Packet{ - # TODO: temporary for liveview - id: Ecto.UUID.generate(), - sender: sender, - path: path, - destination: destination, - information_field: data, - data_type: data_type, - base_callsign: base_callsign, - ssid: ssid, - data_extended: data_extended - }} - else - true -> - {:error, "PARSE ERROR"} - end - rescue - _ -> - # Logger.debug("PARSE ERROR: " <> message) - {:ok, file} = File.open("./badpackets.txt", [:append]) - IO.binwrite(file, message <> "\n\n") - File.close(file) - {:error, :invalid_packet} + with [base_callsign, ssid] <- parse_callsign(sender), + data_type = parse_datatype(String.first(data)), + data = String.trim(data), + [destination, path] <- String.split(path, ",", parts: 2) do + data_extended = parse_data(data_type, destination, data) + + {:ok, + %Packet{ + # TODO: temporary for liveview + id: Ecto.UUID.generate(), + sender: sender, + path: path, + destination: destination, + information_field: data, + data_type: data_type, + base_callsign: base_callsign, + ssid: ssid, + data_extended: data_extended + }} + else + true -> + {:error, "PARSE ERROR"} end + rescue + _ -> + # Logger.debug("PARSE ERROR: " <> message) + {:ok, file} = File.open("./badpackets.txt", [:append]) + IO.binwrite(file, message <> "\n\n") + File.close(file) + {:error, :invalid_packet} end def parse_callsign(callsign) do @@ -80,11 +82,9 @@ defmodule Parser do def parse_data(:mic_e_old, destination, data), do: parse_mic_e(destination, data) def parse_data(:position, _destination, data), do: parse_position_without_timestamp(false, data) - def parse_data(:position_with_message, _destination, data), - do: parse_position_without_timestamp(true, data) + def parse_data(:position_with_message, _destination, data), do: parse_position_without_timestamp(true, data) - def parse_data(:timestamped_position, _destination, data), - do: parse_position_with_timestamp(false, data) + def parse_data(:timestamped_position, _destination, data), do: parse_position_with_timestamp(false, data) def parse_data( :timestamped_position_with_message, @@ -94,14 +94,9 @@ defmodule Parser do parse_position_with_datetime_and_weather(true, date_time_position, weather_report) end - def parse_data(:timestamped_position_with_message, _destination, data), - do: parse_position_with_timestamp(true, data) + def parse_data(:timestamped_position_with_message, _destination, data), do: parse_position_with_timestamp(true, data) - def parse_data( - :message, - _destination, - <<":", addressee::binary-size(9), ":", message_text::binary>> - ) do + def parse_data(:message, _destination, <<":", addressee::binary-size(9), ":", message_text::binary>>) do # Aprs messages can have an optional message number tacked onto the end # for the purposes of acknowledging message receipt. # The sender tacks the message number onto the end of the message, @@ -129,13 +124,9 @@ defmodule Parser do def parse_data(_type, _destination, _data), do: nil - def parse_position_with_datetime_and_weather( - aprs_messaging?, - date_time_position_data, - weather_report - ) do - <