2022-05-23 15:57:15 +02:00
|
|
|
defmodule SomethingErlangWeb.PageController do
|
|
|
|
use SomethingErlangWeb, :controller
|
|
|
|
|
|
|
|
def index(conn, _params) do
|
|
|
|
render(conn, "index.html")
|
|
|
|
end
|
2022-08-08 15:58:25 +02:00
|
|
|
|
|
|
|
def to_forum_path(conn, %{"to" => redir_params} = _params) do
|
|
|
|
%{"forum_path" => path} = redir_params
|
2022-11-07 13:49:31 +01:00
|
|
|
|
2023-01-18 10:56:30 +01:00
|
|
|
{redirect_good, thread, page} =
|
|
|
|
case {
|
|
|
|
Regex.run(~r{threadid=(\d+)}, path),
|
|
|
|
Regex.run(~r{pagenumber=(\d+)}, path)
|
|
|
|
} do
|
|
|
|
{[_, thread], nil} -> {:ok, thread, 1}
|
|
|
|
{[_, thread], [_, page]} -> {:ok, thread, page}
|
|
|
|
_ -> {:error, nil, nil}
|
|
|
|
end
|
|
|
|
|
|
|
|
if redirect_good == :ok do
|
2022-08-08 15:58:25 +02:00
|
|
|
redirect(conn,
|
2022-11-07 13:49:31 +01:00
|
|
|
to: Routes.thread_show_path(conn, :show, thread, page: page)
|
|
|
|
)
|
2023-01-18 10:56:30 +01:00
|
|
|
else
|
|
|
|
put_flash(conn, :error, "Could not resolve URL")
|
|
|
|
render(conn, "index.html")
|
2022-08-08 15:58:25 +02:00
|
|
|
end
|
|
|
|
end
|
2022-05-23 15:57:15 +02:00
|
|
|
end
|