Skip to content

Commit

Permalink
Fix variant roll changing when fetching assets (#704)
Browse files Browse the repository at this point in the history
  • Loading branch information
APB9785 authored Dec 12, 2024
1 parent c760ca4 commit 61a0723
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion lib/beacon/plug.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,32 @@ defmodule Beacon.Plug do
"""
@behaviour Plug

@private_routes [
"__beacon_check__",
"__beacon_assets__",
"__beacon_media__"
]

@impl Plug
def init(_opts), do: []

@impl Plug
def call(conn, _opts), do: Plug.Conn.put_session(conn, :beacon_variant_roll, Enum.random(1..100))
def call(conn, _opts) do
if Enum.any?(@private_routes, &(&1 in conn.path_info)) do
conn
else
put_roll(conn)
end
end

defp put_roll(conn) do
path_list = conn.path_params["path"]

with %{private: %{phoenix_live_view: {_, _, %{extra: %{session: %{"beacon_site" => site}}}}}} <- conn,
{_, _} <- Beacon.RouterServer.lookup_path(site, path_list, 1) do
Plug.Conn.put_session(conn, "beacon_variant_roll", Enum.random(1..100))
else
_ -> conn
end
end
end

0 comments on commit 61a0723

Please sign in to comment.