fixed form

This commit is contained in:
2024-06-02 15:23:32 +02:00
parent 31c126a394
commit 6f088f86a1
2 changed files with 46 additions and 6 deletions

View File

@ -1,9 +1,46 @@
defmodule SomethingErlangWeb.PageController do
use SomethingErlangWeb, :controller
def home(conn, _params) do
def home(conn, params) do
# The home page is often custom made,
# so skip the default app layout.
render(conn, :home, layout: false)
conn = assign(conn, :params, params)
render(conn, :home)
end
def to_forum_path(conn, %{"forum_path" => path} = _params) do
with {:ok, thread, page} <- resolve_url(path) do
redirect(conn, to: ~p"/thread/#{thread}?page=#{page}")
else
_ ->
put_flash(conn, :error, "Could not resolve URL")
render(conn, :home)
end
end
def to_forum_path(conn, _params) do
render(conn, :home)
end
defp resolve_url(url) do
threadid =
case Regex.run(~r{threadid=(\d+)}, url) do
[_, threadid] -> {:ok, threadid}
nil -> {:error, :nothreadid}
end
page =
case Regex.run(~r{pagenumber=(\d+)}, url) do
[_, page] -> {:ok, page}
nil -> {:ok, 1}
end
with {:ok, threadid} <- threadid,
{:ok, page} <- page do
{:ok, threadid, page}
else
_ ->
{:error, :cantparseurl}
end
end
end