     end
   end
 
+  defp validate_id(%Plug.Conn{query_params: %{"id" => id}} = conn, _params) do
+    case Sites.is_valid_id?(id) do
+      {:ok, _} ->
+        conn
+
+      {:error, _} ->
+        render_error(conn, gettext("Invalid id."))
+    end
+  end
+
   defp render_error(conn, error_message) do
     conn
     |> put_status(400)

  end

  def status(conn, %{"id" => id}) do
    case Sites.is_valid_id?(id) do
      {:error, _} -> handle_status(nil, id, conn)
      {:ok, _} -> Sites.get_site(id) |> handle_status(id, conn)
    end
  end

  defp handle_status(nil, _id, conn) do
    redirect(conn, to: Routes.page_path(conn, :index, conn.assigns.locale))
  end

  defp handle_status(site, id, conn) do
    case site.status do
      "queue" ->
        render(conn, "status.html", id: id, site: site, page_title: gettext("Status"))

      "processing" ->
        render(conn, "status.html", id: id, site: site, page_title: gettext("Status"))

      "failed" ->
        redirect(conn,
          to: Routes.site_path(conn, :results, conn.assigns.locale, url: site.input_url)
        )

      "done" ->
        redirect(conn,
          to: Routes.site_path(conn, :results, conn.assigns.locale, url: site.input_url)
        )


  defp handle_results({id, site}, conn, _url) do
    case site.status do
      x when x in ["queue", "processing"] ->
        redirect(conn,
          to: Routes.site_path(conn, :status, conn.assigns.locale, id: id, site: site)
        )
