redirect somethingawful urls

This commit is contained in:
2022-08-08 15:58:25 +02:00
parent e7da164b3f
commit e8eaa2d77a
3 changed files with 17 additions and 0 deletions

View File

@ -4,4 +4,15 @@ defmodule SomethingErlangWeb.PageController do
def index(conn, _params) do
render(conn, "index.html")
end
def to_forum_path(conn, %{"to" => redir_params} = _params) do
%{"forum_path" => path} = redir_params
with [_, thread] <- Regex.run(~r{threadid=(\d+)}, path),
[_, page] <- Regex.run(~r{pagenumber=(\d+)}, path) do
redirect(conn,
to: Routes.thread_show_path(conn, :show, thread, page: page))
end
put_flash(conn, :error, "Could not resolve URL")
render(conn, "index.html")
end
end