2019-09-02 14:29:19 +03:00
|
|
|
defmodule PlausibleWeb.Api.InternalController do
|
|
|
|
use PlausibleWeb, :controller
|
|
|
|
use Plausible.Repo
|
2020-05-22 12:33:17 +03:00
|
|
|
alias Plausible.Stats.Clickhouse, as: Stats
|
2019-09-02 14:29:19 +03:00
|
|
|
|
|
|
|
def domain_status(conn, %{"domain" => domain}) do
|
2020-05-22 12:33:17 +03:00
|
|
|
if Stats.has_pageviews?(%Plausible.Site{domain: domain}) do
|
2019-09-02 14:29:19 +03:00
|
|
|
json(conn, "READY")
|
|
|
|
else
|
|
|
|
json(conn, "WAITING")
|
|
|
|
end
|
|
|
|
end
|
2020-08-13 13:45:18 +03:00
|
|
|
|
|
|
|
def sites(conn, _) do
|
2021-03-03 12:36:19 +03:00
|
|
|
if conn.assigns[:current_user] do
|
|
|
|
user = Repo.preload(conn.assigns[:current_user], :sites)
|
|
|
|
json(conn, Enum.map(user.sites, & &1.domain))
|
|
|
|
else
|
|
|
|
conn
|
|
|
|
|> put_status(401)
|
|
|
|
|> json(%{error: "You need to be logged in to request a list of sites"})
|
|
|
|
end
|
2020-08-13 13:45:18 +03:00
|
|
|
end
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|