diff --git a/.gitignore b/.gitignore index 9bbfb9f..fa31119 100644 --- a/.gitignore +++ b/.gitignore @@ -40,3 +40,4 @@ erl_crash.dump /xref_graph.dot /xref_graph.png /scripts +priv/dev_config.yml diff --git a/flake.lock b/flake.lock index 87006d9..a98634f 100644 --- a/flake.lock +++ b/flake.lock @@ -21,11 +21,11 @@ "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1690933134, - "narHash": "sha256-ab989mN63fQZBFrkk4Q8bYxQCktuHmBIBqUG1jl6/FQ=", + "lastModified": 1693611461, + "narHash": "sha256-aPODl8vAgGQ0ZYFIRisxYG5MOGSkIczvu2Cd8Gb9+1Y=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "59cf3f1447cfc75087e7273b04b31e689a8599fb", + "rev": "7f53fdb7bdc5bb237da7fefef12d099e4fd611ca", "type": "github" }, "original": { @@ -36,11 +36,11 @@ }, "flake-root": { "locked": { - "lastModified": 1680964220, - "narHash": "sha256-dIdTYcf+KW9a4pKHsEbddvLVSfR1yiAJynzg2x0nfWg=", + "lastModified": 1692742795, + "narHash": "sha256-f+Y0YhVCIJ06LemO+3Xx00lIcqQxSKJHXT/yk1RTKxw=", "owner": "srid", "repo": "flake-root", - "rev": "f1c0b93d05bdbea6c011136ba1a135c80c5b326c", + "rev": "d9a70d9c7a5fd7f3258ccf48da9335e9b47c3937", "type": "github" }, "original": { @@ -74,11 +74,11 @@ ] }, "locked": { - "lastModified": 1660459072, - "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "lastModified": 1694102001, + "narHash": "sha256-vky6VPK1n1od6vXbqzOXnekrQpTL4hbPAwUhT5J9c9E=", "owner": "hercules-ci", "repo": "gitignore.nix", - "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "rev": "9e21c80adf67ebcb077d75bd5e7d724d21eeafd6", "type": "github" }, "original": { @@ -89,11 +89,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1691853136, - "narHash": "sha256-wTzDsRV4HN8A2Sl0SVQY0q8ILs90CD43Ha//7gNZE+E=", + "lastModified": 1696009558, + "narHash": "sha256-/1nNL8lCF0gn38XaFyu2ufpWcBFwCDZyYUxdZkM6GxU=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "f0451844bbdf545f696f029d1448de4906c7f753", + "rev": "c182df2e68bd97deb32c7e4765adfbbbcaf75b60", "type": "github" }, "original": { @@ -106,11 +106,11 @@ "nixpkgs-lib": { "locked": { "dir": "lib", - "lastModified": 1690881714, - "narHash": "sha256-h/nXluEqdiQHs1oSgkOOWF+j8gcJMWhwnZ9PFabN6q0=", + "lastModified": 1693471703, + "narHash": "sha256-0l03ZBL8P1P6z8MaSDS/MvuU8E75rVxe5eE1N6gxeTo=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "9e1960bc196baf6881340d53dccb203a951745a2", + "rev": "3e52e76b70d5508f3cec70b882a29199f4d1ee85", "type": "github" }, "original": { @@ -150,11 +150,11 @@ "nixpkgs-stable": "nixpkgs-stable" }, "locked": { - "lastModified": 1691747570, - "narHash": "sha256-J3fnIwJtHVQ0tK2JMBv4oAmII+1mCdXdpeCxtIsrL2A=", + "lastModified": 1696158581, + "narHash": "sha256-h0vY4E7Lx95lpYQbG2w4QH4yG5wCYOvPJzK93wVQbT0=", "owner": "cachix", "repo": "pre-commit-hooks.nix", - "rev": "c5ac3aa3324bd8aebe8622a3fc92eeb3975d317a", + "rev": "033453f85064ccac434dfd957f95d8457901ecd6", "type": "github" }, "original": { @@ -165,11 +165,11 @@ }, "process-compose-flake": { "locked": { - "lastModified": 1691182187, - "narHash": "sha256-dmHKgFXstdfX7nfnpbzR5H4DWGdWo610zsW9BCtI2WQ=", + "lastModified": 1695992918, + "narHash": "sha256-5tHNbk0ldLUjAqKRZog/3asiVvkD51VGK9TvwzUBs38=", "owner": "Platonic-Systems", "repo": "process-compose-flake", - "rev": "bacdaf54ffe3a2c1734fd973a95e6b39b1560c2e", + "rev": "1ebecb83f15736f5d4ae3feb01a8391977dd71da", "type": "github" }, "original": { @@ -211,11 +211,11 @@ ] }, "locked": { - "lastModified": 1691833704, - "narHash": "sha256-ASGhgGduEgcD3gQZhGr8xtmZ3PlVY+m2HuPnIZDbu78=", + "lastModified": 1695822946, + "narHash": "sha256-IQU3fYo0H+oGlqX5YrgZU3VRhbt2Oqe6KmslQKUO4II=", "owner": "numtide", "repo": "treefmt-nix", - "rev": "19dee4bf6001849006a63f3435247316b0488e99", + "rev": "720bd006d855b08e60664e4683ccddb7a9ff614a", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 6de6099..88ca1ab 100644 --- a/flake.nix +++ b/flake.nix @@ -56,6 +56,8 @@ mixRelease = beamPackagesPrev.mixRelease.override { inherit erlang elixir; }; }; + mix2nix = pkgs.mix2nix.override { inherit elixir erlang; }; + postgres = pkgs.postgresql_15; inherit (pkgs.stdenv) isDarwin; @@ -109,7 +111,7 @@ ]); packages = [ - pkgs.mix2nix + mix2nix self'.packages.bdfr-browser-dev ]; @@ -141,7 +143,7 @@ settings = { environment = { BDFR_BROWSER_BASE_DIRECTORY = "/Volumes/MediaScraper/Reddit"; - BDFR_BROWSER_CONFIG_FILE = "./priv/config.yml"; + BDFR_BROWSER_CONFIG_FILE = "./priv/dev_config.yml"; BDFR_BROWSER_REPO_USER = db-user; BDFR_BROWSER_REPO_HOST = db-host; RELEASE_DISTRIBUTION = "none"; diff --git a/lib/bdfr_browser/http/plug.ex b/lib/bdfr_browser/http/plug.ex index 4eeeb7e..5342721 100644 --- a/lib/bdfr_browser/http/plug.ex +++ b/lib/bdfr_browser/http/plug.ex @@ -8,9 +8,11 @@ defmodule BdfrBrowser.HTTP.Plug do get "/" do config_file = Application.fetch_env!(:bdfr_browser, :config_file) - hidden_subreddits = config_file["hidden_subreddits"] + archived_subreddits = Enum.sort(config_file["archived_subreddits"]) + archived_users = Enum.sort(config_file["archived_users"]) + saved_searches = Enum.sort(config_file["saved_searches"]) - tpl_args = [subreddits: Subreddit.names_without(hidden_subreddits) |> Repo.all()] + tpl_args = [subreddits: archived_subreddits, users: archived_users, searches: saved_searches] content = render_template("index", tpl_args) conn @@ -18,6 +20,15 @@ defmodule BdfrBrowser.HTTP.Plug do |> send_resp(200, content) end + get "/all/subreddits" do + tpl_args = [subreddits: Subreddit.names() |> Repo.all()] + content = render_template("all_subreddits", tpl_args) + + conn + |> put_resp_header("content-type", "text/html; charset=utf-8") + |> send_resp(200, content) + end + get "/r/:subreddit" do subreddit_record = Repo.get_by(Subreddit, name: subreddit) @@ -180,6 +191,13 @@ defmodule BdfrBrowser.HTTP.Plug do send_resp(conn, 200, "IMPORTING CHANGES") end + post "/_reload" do + config_file = YamlElixir.read_from_file!(System.fetch_env!("BDFR_BROWSER_CONFIG_FILE")) + :ok = Application.put_env(:bdfr_browser, :config_file, config_file) + + send_resp(conn, 200, "RELOAD") + end + post "/_cleanup" do _ = Importer.cleanup_messages() send_resp(conn, 200, "CLEANED UP") diff --git a/mix.lock b/mix.lock index 32bdaa3..0807f6b 100644 --- a/mix.lock +++ b/mix.lock @@ -4,17 +4,17 @@ "cowlib": {:hex, :cowlib, "2.12.1", "a9fa9a625f1d2025fe6b462cb865881329b5caff8f1854d1cbc9f9533f00e1e1", [:make, :rebar3], [], "hexpm", "163b73f6367a7341b33c794c4e88e7dbfe6498ac42dcd69ef44c5bc5507c8db0"}, "db_connection": {:hex, :db_connection, "2.5.0", "bb6d4f30d35ded97b29fe80d8bd6f928a1912ca1ff110831edcd238a1973652c", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c92d5ba26cd69ead1ff7582dbb860adeedfff39774105a4f1c92cbb654b55aa2"}, "decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"}, - "earmark": {:hex, :earmark, "1.4.39", "acdb2f02c536471029dbcc509fbd6b94b89f40ad7729fb3f68f4b6944843f01d", [:mix], [{:earmark_parser, "~> 1.4.33", [hex: :earmark_parser, repo: "hexpm", optional: false]}], "hexpm", "156c9d8ec3cbeccdbf26216d8247bdeeacc8c76b4d9eee7554be2f1b623ea440"}, + "earmark": {:hex, :earmark, "1.4.46", "8c7287bd3137e99d26ae4643e5b7ef2129a260e3dcf41f251750cb4563c8fb81", [:mix], [], "hexpm", "798d86db3d79964e759ddc0c077d5eb254968ed426399fbf5a62de2b5ff8910a"}, "earmark_parser": {:hex, :earmark_parser, "1.4.33", "3c3fd9673bb5dcc9edc28dd90f50c87ce506d1f71b70e3de69aa8154bc695d44", [:mix], [], "hexpm", "2d526833729b59b9fdb85785078697c72ac5e5066350663e5be6a1182da61b8f"}, "ecto": {:hex, :ecto, "3.10.3", "eb2ae2eecd210b4eb8bece1217b297ad4ff824b4384c0e3fdd28aaf96edd6135", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "44bec74e2364d491d70f7e42cd0d690922659d329f6465e89feb8a34e8cd3433"}, "ecto_sql": {:hex, :ecto_sql, "3.10.2", "6b98b46534b5c2f8b8b5f03f126e75e2a73c64f3c071149d32987a5378b0fdbd", [:mix], [{:db_connection, "~> 2.4.1 or ~> 2.5", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.10.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.6.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.16.0 or ~> 0.17.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1 or ~> 2.2", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "68c018debca57cb9235e3889affdaec7a10616a4e3a80c99fa1d01fdafaa9007"}, "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, "jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"}, "mime": {:hex, :mime, "2.0.5", "dc34c8efd439abe6ae0343edbb8556f4d63f178594894720607772a041b04b02", [:mix], [], "hexpm", "da0d64a365c45bc9935cc5c8a7fc5e49a0e0f9932a761c55d6c52b142780a05c"}, - "plug": {:hex, :plug, "1.14.2", "cff7d4ec45b4ae176a227acd94a7ab536d9b37b942c8e8fa6dfc0fff98ff4d80", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "842fc50187e13cf4ac3b253d47d9474ed6c296a8732752835ce4a86acdf68d13"}, + "plug": {:hex, :plug, "1.15.0", "f40df58e1277fc7189f260daf788d628f03ae3053ce7ac1ca63eaf0423238714", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "e434478d1015d968cf98ae2073e78bd63c4a06a94fe328c2df45fcd01df8ae30"}, "plug_cowboy": {:hex, :plug_cowboy, "2.6.1", "9a3bbfceeb65eff5f39dab529e5cd79137ac36e913c02067dba3963a26efe9b2", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "de36e1a21f451a18b790f37765db198075c25875c64834bcc82d90b309eb6613"}, "plug_crypto": {:hex, :plug_crypto, "1.2.5", "918772575e48e81e455818229bf719d4ab4181fcbf7f85b68a35620f78d89ced", [:mix], [], "hexpm", "26549a1d6345e2172eb1c233866756ae44a9609bd33ee6f99147ab3fd87fd842"}, - "postgrex": {:hex, :postgrex, "0.17.2", "a3ec9e3239d9b33f1e5841565c4eb200055c52cc0757a22b63ca2d529bbe764c", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "80a918a9e9531d39f7bd70621422f3ebc93c01618c645f2d91306f50041ed90c"}, + "postgrex": {:hex, :postgrex, "0.17.3", "c92cda8de2033a7585dae8c61b1d420a1a1322421df84da9a82a6764580c503d", [:mix], [{:db_connection, "~> 2.1", [hex: :db_connection, repo: "hexpm", optional: false]}, {:decimal, "~> 1.5 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:table, "~> 0.1.0", [hex: :table, repo: "hexpm", optional: true]}], "hexpm", "946cf46935a4fdca7a81448be76ba3503cff082df42c6ec1ff16a4bdfbfb098d"}, "ranch": {:hex, :ranch, "1.8.0", "8c7a100a139fd57f17327b6413e4167ac559fbc04ca7448e9be9057311597a1d", [:make, :rebar3], [], "hexpm", "49fbcfd3682fab1f5d109351b61257676da1a2fdbe295904176d5e521a2ddfe5"}, "telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"}, "typed_struct": {:hex, :typed_struct, "0.3.0", "939789e3c1dca39d7170c87f729127469d1315dcf99fee8e152bb774b17e7ff7", [:mix], [], "hexpm", "c50bd5c3a61fe4e198a8504f939be3d3c85903b382bde4865579bc23111d1b6d"}, diff --git a/mix.nix b/mix.nix index 9499e29..45ba2cf 100644 --- a/mix.nix +++ b/mix.nix @@ -75,15 +75,15 @@ let earmark = buildMix rec { name = "earmark"; - version = "1.4.39"; + version = "1.4.46"; src = fetchHex { pkg = "${name}"; version = "${version}"; - sha256 = "0h547ri1nbxyaisyx7jddg3wib7fpm3q4v914szwvv6bqf79sv0m"; + sha256 = "02liz1gjppk2bazryf96sj79cm5jbryhf36wkmslx5kr7pdqd3br"; }; - beamDeps = [ earmark_parser ]; + beamDeps = [ ]; }; earmark_parser = buildMix rec { @@ -166,12 +166,12 @@ let plug = buildMix rec { name = "plug"; - version = "1.14.2"; + version = "1.15.0"; src = fetchHex { pkg = "${name}"; version = "${version}"; - sha256 = "04wdyv6nma74bj1m49vkm2bc5mjf8zclfg957fng8g71hw0wabw4"; + sha256 = "0c5fz0fx1z25vz12iqsgm434lg6nigkp685fk37nin8m226lfd74"; }; beamDeps = [ mime plug_crypto telemetry ]; @@ -205,12 +205,12 @@ let postgrex = buildMix rec { name = "postgrex"; - version = "0.17.2"; + version = "0.17.3"; src = fetchHex { pkg = "${name}"; version = "${version}"; - sha256 = "036r3q250vrhj4nmyr4cc40krjgbyci18qkhppvkj7akx6liiac0"; + sha256 = "1389zgxvv90nzz0nwb7l5l4gyg2hldmyg2s4h5xcmzd46mlz8v4l"; }; beamDeps = [ db_connection decimal jason ]; diff --git a/priv/config.yml b/priv/config.yml index 9762b5c..c90fd95 100644 --- a/priv/config.yml +++ b/priv/config.yml @@ -1,4 +1,7 @@ --- -hidden_subreddits: - - foo - - bar +archived_subreddits: + - AskReddit + - NonCredibleDefense + +archived_users: + - spez diff --git a/priv/templates/http/all_subreddits.eex b/priv/templates/http/all_subreddits.eex new file mode 100644 index 0000000..9c8daa7 --- /dev/null +++ b/priv/templates/http/all_subreddits.eex @@ -0,0 +1,18 @@ + + +

All Subreddits

+ +
+
+ <%= for subreddit <- subreddits do %> + <%= subreddit %> + <% end %> +
+
+ +
diff --git a/priv/templates/http/chat.eex b/priv/templates/http/chat.eex index a5925f1..1155ef9 100644 --- a/priv/templates/http/chat.eex +++ b/priv/templates/http/chat.eex @@ -1,4 +1,12 @@ -

Chats

+ + +

Chat

<%= for message <- messages do %>
+ + +

Chats

diff --git a/priv/templates/http/index.eex b/priv/templates/http/index.eex index 4893d24..03d642a 100644 --- a/priv/templates/http/index.eex +++ b/priv/templates/http/index.eex @@ -3,6 +3,7 @@ @@ -24,7 +25,7 @@
- <%= for subreddit <- subreddits, not String.starts_with?(subreddit, "u_") do %> + <%= for subreddit <- subreddits do %> <%= subreddit %> <% end %>
@@ -36,9 +37,21 @@
- <%= for user <- subreddits, String.starts_with?(user, "u_") do %> - " role="button"> - <%= String.replace_leading(user, "u_", "") %> + <%= for user <- users do %> + <%= user %> + <% end %> +
+
+ +
+ +

Saved Searches

+ +
+
+ <%= for search <- searches do %> + search}) %>" role="button"> + <%= search %> <% end %>
diff --git a/priv/templates/http/post.eex b/priv/templates/http/post.eex index 9b7909c..92a275b 100644 --- a/priv/templates/http/post.eex +++ b/priv/templates/http/post.eex @@ -1,3 +1,12 @@ + +

<%= post.title %>

diff --git a/priv/templates/http/search.eex b/priv/templates/http/search.eex index e4f91e3..ee0c98b 100644 --- a/priv/templates/http/search.eex +++ b/priv/templates/http/search.eex @@ -1,3 +1,10 @@ +

+

Search: <%= search %>