Skip to content

Commit

Permalink
Merge pull request #12 from dtcaciuc/explorer-default-page
Browse files Browse the repository at this point in the history
explorer: Add default page config; add missing rewrite base to htaccess.
  • Loading branch information
dtcaciuc authored Feb 27, 2025
2 parents 9b288cb + 0d4e9f6 commit 43577d9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ for /f "delims=" %%i in ('path\to\scoreboard\bin\today.bat') do set EVENT_DATE=%
set EXPLORER_REMOTE_HTTP_BASE_PATH=/results/%EVENT_DATE%
```


## Customizing explorer colors

Explorer can be configured to use a custom color scheme to match the club website
Expand Down Expand Up @@ -178,6 +177,8 @@ The following environment variables need to be manually set:
Additionally, you can optionally set the following:

* `EXPLORER_COLORS` (path, optional) - Path to a CSV file with the custom explorer color palette.
* `EXPLORER_DEFAULT_PAGE` (string, optional) - The page explorer redirects to from its root path
(one of `event`, `pax`, `raw`, `runs`, `groups`, or `cones`, defaults to `event`)
* `ANNOUNCE_FONT_SIZE` (float, optional) - /announce endpoint font size.
* `TV_FONT_SIZE` (float, optional) - /tv endpoint font size.
* `TV_REFRESH_INTERVAL` (integer, optional) - Sets how long /tv displays a page of
Expand Down
1 change: 1 addition & 0 deletions config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ if config_env() != :test do
root: System.get_env("EXPLORER_REMOTE_FTP_BASE_DIR", System.get_env("LIVE_FTP_PATH", "/"))
],
explorer_remote_http_base_path: System.get_env("EXPLORER_REMOTE_HTTP_BASE_PATH", "/"),
explorer_default_page: parse_explorer_page!(System.get_env("EXPLORER_DEFAULT_PAGE", "event")),
explorer_colors: explorer_colors,
mj_dir: System.get_env("MJ_DIR", "c:/mjtiming"),
mj_debounce_interval: String.to_integer(System.get_env("MJ_DEBOUNCE_INTERVAL", "1000")),
Expand Down
3 changes: 2 additions & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ config :conecerto_scoreboard, Conecerto.Scoreboard,
watcher: nil,
uploader: nil,
event_date: "2023_01_01",
explorer_colors: %{}
explorer_colors: %{},
explorer_default_page: "event"

# Print only warnings and errors during test
config :logger, level: :warning
Expand Down
8 changes: 8 additions & 0 deletions lib/conecerto_scoreboard/config_utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ defmodule Conecerto.Scoreboard.ConfigUtils do
end
end

def parse_explorer_page!(s) do
if Enum.member?(~w(event pax raw groups runs cones), s) do
s
else
raise "#{s} is not a valid explorer page"
end
end

def generate_secret_key_base() do
for _ <- 1..64, into: "" do
<<Enum.random(~c"0123456789abcdef")>>
Expand Down
19 changes: 14 additions & 5 deletions lib/conecerto_scoreboard/uploader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ defmodule Conecerto.Scoreboard.Uploader do

@endpoint Conecerto.ScoreboardWeb.Endpoint

@htaccess ~s(
@htaccess_template ~s(
RewriteEngine On
RewriteBase <%= base_path %>
# Index redirects to event page
RewriteRule "^$" event [R=302,L]
RewriteRule "^$" <%= default_page %> [R=302,L]
# Deny Phoenix live reload stuff that doesn't exist
RewriteRule "^phoenix/live_reload/frame$" event [R=404,L]
RewriteRule "^phoenix/live_reload/frame$" <%= default_page %> [R=404,L]
# Serve gzip compressed files.
RewriteCond "%{HTTP:Accept-Encoding}" "gzip"
Expand All @@ -36,7 +38,8 @@ RewriteRule "\.html.gz$" "-" [T=text/html,E=no-gzip:1]
def start_link(_) do
args = %{
client_args: Scoreboard.config(:explorer_remote_ftp),
base_path: Scoreboard.config(:explorer_remote_http_base_path)
base_path: Scoreboard.config(:explorer_remote_http_base_path),
default_page: Scoreboard.config(:explorer_default_page)
}

GenServer.start_link(__MODULE__, args)
Expand All @@ -55,9 +58,15 @@ RewriteRule "\.html.gz$" "-" [T=text/html,E=no-gzip:1]

@impl true
def handle_continue(:upload_assets, state) do
htaccess =
EEx.eval_string(@htaccess_template,
base_path: state.base_path,
default_page: state.default_page
)

with {:ok, client} <- FTP.open(state.client_args),
:ok <- FTP.mkdir(client, "/"),
:ok <- FTP.send_bin(client, @htaccess, "/.htaccess"),
:ok <- FTP.send_bin(client, htaccess, "/.htaccess"),
:ok <- send_static(client, "/favicon.ico"),
:ok <- FTP.mkdir(client, "assets"),
:ok <- send_static(client, "/assets/app.css"),
Expand Down

0 comments on commit 43577d9

Please sign in to comment.