add discord_handler
This commit is contained in:
parent
811df6423e
commit
6ae835dbb3
1 changed files with 24 additions and 0 deletions
24
lib/zoeyscomputer_web/plugs/discord_handler.ex
Normal file
24
lib/zoeyscomputer_web/plugs/discord_handler.ex
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
defmodule ZoeyscomputerWeb.DiscordHandler do
|
||||
import Plug.Conn
|
||||
|
||||
def init(opts), do: opts
|
||||
|
||||
def call(%{path_info: ["images", _id]} = conn, _opts) do
|
||||
case get_req_header(conn, "user-agent") do
|
||||
["Mozilla/5.0 (compatible; Discordbot/" <> _rest] -> handle_discord(conn)
|
||||
_ -> conn
|
||||
end
|
||||
end
|
||||
|
||||
def call(conn, _opts), do: conn
|
||||
|
||||
defp handle_discord(%{path_info: ["images", id]} = conn) do
|
||||
url = "https://s3.zoeys.computer/imgs/uploads/#{id}.png"
|
||||
|
||||
conn
|
||||
|> put_resp_header("location", url)
|
||||
|> put_resp_content_type("text/plain")
|
||||
|> send_resp(302, "Redirecting to image")
|
||||
|> halt()
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue