Show asciicast2gif instructions when request for .gif
parent
928a378b64
commit
b1aebceda2
@ -0,0 +1,28 @@
|
||||
defmodule Asciinema.TrailingFormat do
|
||||
@known_extensions ["json", "png", "gif"]
|
||||
|
||||
def init(opts), do: opts
|
||||
|
||||
def call(conn, _opts) do
|
||||
case conn.path_info do
|
||||
[] ->
|
||||
conn
|
||||
path_info ->
|
||||
%{conn | path_info: rewrite_path_info(path_info)}
|
||||
end
|
||||
end
|
||||
|
||||
defp rewrite_path_info(path_info) do
|
||||
path_info
|
||||
|> List.last
|
||||
|> String.split(".")
|
||||
|> Enum.reverse
|
||||
|> case do
|
||||
[format | fragments] when format in @known_extensions ->
|
||||
id = fragments |> Enum.reverse |> Enum.join(".")
|
||||
path_info |> List.replace_at(-1, id) |> List.insert_at(-1, format)
|
||||
_ ->
|
||||
path_info
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,12 @@
|
||||
defmodule Asciinema.AsciicastAnimationController do
|
||||
use Asciinema.Web, :controller
|
||||
alias Asciinema.{Repo, Asciicast}
|
||||
|
||||
def show(conn, %{"id" => id}) do
|
||||
asciicast = Repo.one!(Asciicast.by_id_or_secret_token(id))
|
||||
|
||||
conn
|
||||
|> put_layout("simple.html")
|
||||
|> render("show.html", asciicast: asciicast)
|
||||
end
|
||||
end
|
@ -0,0 +1,25 @@
|
||||
defmodule Asciinema.Asciicast do
|
||||
use Asciinema.Web, :model
|
||||
|
||||
schema "asciicasts" do
|
||||
field :version, :integer
|
||||
field :file, :string
|
||||
field :stdout_data, :string
|
||||
field :stdout_timing, :string
|
||||
field :private, :boolean
|
||||
field :secret_token, :string
|
||||
end
|
||||
|
||||
def by_id_or_secret_token(thing) do
|
||||
if String.length(thing) == 25 do
|
||||
from a in __MODULE__, where: a.secret_token == ^thing
|
||||
else
|
||||
case Integer.parse(thing) do
|
||||
{id, ""} ->
|
||||
from a in __MODULE__, where: a.private == false and a.id == ^id
|
||||
:error ->
|
||||
from a in __MODULE__, where: a.id == -1 # TODO fixme
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,18 @@
|
||||
.simple-layout
|
||||
margin-top: 30px
|
||||
margin-left: 24px
|
||||
margin-right: 24px
|
||||
|
||||
p
|
||||
font-size: 20px
|
||||
|
||||
pre
|
||||
font-size: 16px
|
||||
overflow: auto
|
||||
white-space: pre
|
||||
|
||||
p, pre
|
||||
margin-bottom: 24px
|
||||
|
||||
h1
|
||||
margin-bottom: 40px
|
@ -0,0 +1,14 @@
|
||||
<h1>Looking for GIF?</h1>
|
||||
|
||||
<p> While we cannot automatically generate GIF from this asciicast (the process
|
||||
is very resource intensive), you can use <a
|
||||
href="https://github.com/asciinema/asciicast2gif">asciicast2gif</a> to do it
|
||||
yourself. Once you have it installed run the following command in your
|
||||
terminal: </p>
|
||||
|
||||
<pre><code>asciicast2gif <%= asciicast_file_url(@conn, @asciicast) %> demo.gif</code> </pre>
|
||||
|
||||
<p> If you have <a href="https://www.docker.com/">Docker</a> installed then just
|
||||
run this command: </p>
|
||||
|
||||
<pre><code>docker run --rm -v $PWD:/data asciinema/asciicast2gif <%= asciicast_file_url(@conn, @asciicast) %> demo.gif</code></pre>
|
@ -0,0 +1,23 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title><%= page_title @conn %></title>
|
||||
<link rel="stylesheet" href="<%= static_path(@conn, "/css/app.css") %>">
|
||||
<link rel="shortcut icon" href="<%= static_path(@conn, "/images/favicon.png") %>">
|
||||
<!-- google analytics -->
|
||||
<!-- content for head (twitter, open graph tags) -->
|
||||
</head>
|
||||
|
||||
<body class="simple-layout">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<%= render @view_module, @view_template, assigns %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,7 @@
|
||||
defmodule Asciinema.AsciicastAnimationView do
|
||||
use Asciinema.Web, :view
|
||||
|
||||
def asciicast_file_url(conn, asciicast) do
|
||||
"#{asciicast_url(conn, :show, asciicast)}.json" # TODO: use route helper
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue