Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix geo lookup CU-86c0p0yb9 #31

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions lib/plausible_web/controllers/api/external_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,11 @@ defmodule PlausibleWeb.Api.ExternalController do
ip = PlausibleWeb.RemoteIp.get(conn)

case :locus.lookup(:geolocation, ip) do
{:ok, result} -> get_location_details(result)
_ -> get_location_details(%{})
{:ok, result} ->
get_location_details(result)

_ ->
get_location_details(nil)
end
end

Expand All @@ -467,7 +470,7 @@ defmodule PlausibleWeb.Api.ExternalController do
}
end

defp get_country_code(%{}), do: ""
defp get_country_code(nil), do: ""

defp get_country_code(geo_data) do
geo_data
Expand All @@ -476,7 +479,7 @@ defmodule PlausibleWeb.Api.ExternalController do
|> ignore_unknown_country()
end

defp get_city_geoname_id(%{}), do: ""
defp get_city_geoname_id(nil), do: ""

defp get_city_geoname_id(geo_data) do
city =
Expand All @@ -487,7 +490,7 @@ defmodule PlausibleWeb.Api.ExternalController do
Map.get(@city_overrides, city, city)
end

defp get_subdivision_code(%{}, _), do: ""
defp get_subdivision_code(nil, _), do: ""

defp get_subdivision_code(geo_data, n) do
subdivisions = Map.get(geo_data, "subdivision", [])
Expand Down
Loading