Skip to content

Commit

Permalink
Refactor OEmbed controller
Browse files Browse the repository at this point in the history
  • Loading branch information
ku1ik committed May 18, 2024
1 parent c7ca669 commit cf7aeda
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions lib/asciinema_web/controllers/oembed_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,8 @@ defmodule AsciinemaWeb.OembedController do
{:ok, id} <- extract_id(path),
{:ok, asciicast} <- Recordings.fetch_asciicast(id),
:ok <- authorize(asciicast) do
mw = if params["maxwidth"], do: String.to_integer(params["maxwidth"])
mh = if params["maxheight"], do: String.to_integer(params["maxheight"])

format =
case params["format"] || get_format(conn) do
"xml" -> "xml"
_ -> "json"
end
{mw, mh} = get_size(params)
format = get_embed_format(conn)

render(
conn,
Expand Down Expand Up @@ -52,4 +46,18 @@ defmodule AsciinemaWeb.OembedController do
:ok
end
end

defp get_size(params) do
mw = if params["maxwidth"], do: String.to_integer(params["maxwidth"])
mh = if params["maxheight"], do: String.to_integer(params["maxheight"])

{mw, mh}
end

defp get_embed_format(conn) do
case conn.params["format"] || get_format(conn) do
"xml" -> "xml"
_ -> "json"
end
end
end

0 comments on commit cf7aeda

Please sign in to comment.