redirect somethingawful urls
This commit is contained in:
@ -4,4 +4,15 @@ defmodule SomethingErlangWeb.PageController do
|
|||||||
def index(conn, _params) do
|
def index(conn, _params) do
|
||||||
render(conn, "index.html")
|
render(conn, "index.html")
|
||||||
end
|
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
|
end
|
||||||
|
@ -21,6 +21,7 @@ defmodule SomethingErlangWeb.Router do
|
|||||||
pipe_through :browser
|
pipe_through :browser
|
||||||
|
|
||||||
get "/", PageController, :index
|
get "/", PageController, :index
|
||||||
|
post "/", PageController, :to_forum_path
|
||||||
end
|
end
|
||||||
|
|
||||||
scope "/thread", SomethingErlangWeb do
|
scope "/thread", SomethingErlangWeb do
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
<%= form_for @conn,
|
||||||
|
Routes.page_path(@conn, :to_forum_path), [as: :to], fn f -> %>
|
||||||
|
Something Awful URL: <%= url_input f, :forum_path %>
|
||||||
|
<%= submit "Redirect", class: "btn btn-sm" %>
|
||||||
|
<% end %>
|
||||||
|
Reference in New Issue
Block a user