feat: Add a way to disable watching files

This commit is contained in:
Daniel Kempkens 2023-08-14 22:46:19 +02:00
parent 69c50a4204
commit fdbf5b82e3
Signed by: daniel
SSH key fingerprint: SHA256:Ks/MyhQYcPRQiwMKLAKquWCdCPe3JXlb1WttgnAoSeM
5 changed files with 21 additions and 10 deletions

View file

@ -8,7 +8,7 @@ config :bdfr_browser, BdfrBrowser.Repo,
migration_foreign_key: [column: :id, type: :string]
config :logger,
backends: [],
backends: [:console],
level: :info,
handle_otp_reports: false,
handle_sasl_reports: false

View file

@ -1,5 +1 @@
import Config
config :logger,
backends: [:console],
level: :info

View file

@ -3,6 +3,7 @@ import Config
config :bdfr_browser,
base_directory: System.get_env("BDFR_BROWSER_BASE_DIRECTORY", "/nonexistant"),
chat_directory: System.get_env("BDFR_BROWSER_CHAT_DIRECTORY", "/nonexistant"),
watch_directories: System.get_env("BDFR_BROWSER_WATCH_DIRECTORIES", "true"),
http_ip: to_charlist(System.get_env("BDFR_BROWSER_HTTP_IP", "127.0.0.1")),
http_port: String.to_integer(System.get_env("BDFR_BROWSER_HTTP_PORT", "4040"))

View file

@ -80,7 +80,13 @@ defmodule BdfrBrowser.Importer do
end
def background_import_changes do
GenServer.cast(__MODULE__, :background_import_changes)
watch_directories = Application.fetch_env!(:bdfr_browser, :watch_directories)
if watch_directories == "true" do
GenServer.cast(__MODULE__, :background_import_changes)
else
background_import()
end
end
# Callbacks
@ -94,10 +100,18 @@ defmodule BdfrBrowser.Importer do
def handle_continue(:setup_fs, state) do
base_directory = Application.fetch_env!(:bdfr_browser, :base_directory)
chat_directory = Application.fetch_env!(:bdfr_browser, :chat_directory)
watch_directories = Application.fetch_env!(:bdfr_browser, :watch_directories)
{:ok, pid} = FileSystem.start_link(dirs: [base_directory, chat_directory])
:ok = FileSystem.subscribe(pid)
{:noreply, %State{state | fs_pid: pid}}
fs_pid =
if watch_directories == "true" do
{:ok, pid} = FileSystem.start_link(dirs: [base_directory, chat_directory])
:ok = FileSystem.subscribe(pid)
pid
else
nil
end
{:noreply, %State{state | fs_pid: fs_pid}}
end
@impl true

View file

@ -2,7 +2,7 @@
<div class="row text-center">
<div class="d-grid gap-2 col-12 mx-auto">
<%= for chat <- chats do %>
<%= for chat when chat.num_messages > 5 <- chats do %>
<div class="card">
<div class="card-body">
<h5 class="card-title"><a href="/chats/<%= URI.encode(chat.id, &URI.char_unreserved?/1) %>"><%= Enum.join(chat.accounts, ", ") %></a></h5>