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 and leandrocp committed Dec 14, 2024
1 parent 95033ab commit 980f301
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 980f301

Please sign in to comment.