-
-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement identicon-based avatars, make it default
- Loading branch information
Showing
11 changed files
with
55 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
defmodule AsciinemaWeb.AvatarController do | ||
use AsciinemaWeb, :new_controller | ||
alias Asciinema.Accounts | ||
|
||
@one_day 24 * 60 * 60 | ||
|
||
def show(conn, %{"id" => id}) do | ||
with {:ok, user} <- Accounts.fetch_user(id) do | ||
conn | ||
|> put_resp_header("cache-control", "public, max-age=#{@one_day}") | ||
|> render("show.svg", user: user) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
defmodule AsciinemaWeb.AvatarSVG do | ||
def show(%{user: user}) do | ||
email = user.email || "#{user.id}@asciinema" | ||
|
||
{:safe, IdenticonSvg.generate(email, 6, :basic)} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
defmodule Asciinema.AvatarControllerTest do | ||
use AsciinemaWeb.ConnCase | ||
import Asciinema.Factory | ||
|
||
test "image response", %{conn: conn} do | ||
user = insert(:user) | ||
|
||
conn = get(conn, ~p"/u/#{user}/avatar") | ||
|
||
assert response(conn, 200) | ||
assert List.first(get_resp_header(conn, "content-type")) =~ ~r|image/.+| | ||
end | ||
end |