31 lines
739 B
Elixir
31 lines
739 B
Elixir
|
|
defmodule ZoeyscomputerWeb.GistPreviewController do
|
||
|
|
use ZoeyscomputerWeb, :controller
|
||
|
|
|
||
|
|
require Logger
|
||
|
|
alias Zoeyscomputer.Gists
|
||
|
|
|
||
|
|
def show(conn, %{"id" => id}) do
|
||
|
|
gist = Gists.get_gist!(id)
|
||
|
|
|
||
|
|
{:ok, webp} = ZoeyscomputerWeb.GistLive.OgImage.get_webp(gist)
|
||
|
|
|
||
|
|
conn
|
||
|
|
|> put_resp_content_type("image/webp")
|
||
|
|
|> put_resp_header("cache-control", "public, max-age=300")
|
||
|
|
|> send_resp(200, webp)
|
||
|
|
|> halt()
|
||
|
|
end
|
||
|
|
|
||
|
|
def raw(conn, %{"id" => id}) do
|
||
|
|
gist = Gists.get_gist!(id)
|
||
|
|
|
||
|
|
webp = ZoeyscomputerWeb.GistLive.OgImage.generate_preview(gist)
|
||
|
|
|
||
|
|
conn
|
||
|
|
|> put_resp_content_type("image/svg+xml")
|
||
|
|
|> put_resp_header("cache-control", "public, max-age=300")
|
||
|
|
|> send_resp(200, webp)
|
||
|
|
|> halt()
|
||
|
|
end
|
||
|
|
end
|