make some changes
This commit is contained in:
parent
76ac2d568a
commit
811df6423e
1 changed files with 1 additions and 28 deletions
|
|
@ -1,8 +1,6 @@
|
||||||
defmodule ZoeyscomputerWeb.Router do
|
defmodule ZoeyscomputerWeb.Router do
|
||||||
require Logger
|
require Logger
|
||||||
alias ExAws.S3
|
alias ExAws.S3
|
||||||
alias Zoeyscomputer.Images
|
|
||||||
alias ZoeyscomputerWeb.DiscordPlug
|
|
||||||
use ZoeyscomputerWeb, :router
|
use ZoeyscomputerWeb, :router
|
||||||
|
|
||||||
import ZoeyscomputerWeb.UserAuth
|
import ZoeyscomputerWeb.UserAuth
|
||||||
|
|
@ -14,8 +12,8 @@ defmodule ZoeyscomputerWeb.Router do
|
||||||
plug :put_root_layout, html: {ZoeyscomputerWeb.Layouts, :root}
|
plug :put_root_layout, html: {ZoeyscomputerWeb.Layouts, :root}
|
||||||
plug :protect_from_forgery
|
plug :protect_from_forgery
|
||||||
plug :put_secure_browser_headers
|
plug :put_secure_browser_headers
|
||||||
plug :handle_discord
|
|
||||||
plug :fetch_current_user
|
plug :fetch_current_user
|
||||||
|
plug ZoeyscomputerWeb.DiscordHandler
|
||||||
end
|
end
|
||||||
|
|
||||||
pipeline :api_authentication do
|
pipeline :api_authentication do
|
||||||
|
|
@ -133,29 +131,4 @@ defmodule ZoeyscomputerWeb.Router do
|
||||||
error
|
error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Updated plug to return ID as string for Discord requests
|
|
||||||
def handle_discord(conn, _opts) do
|
|
||||||
Logger.info("user agent: #{get_req_header(conn, "user-agent")}")
|
|
||||||
|
|
||||||
is_discord =
|
|
||||||
case get_req_header(conn, "user-agent") do
|
|
||||||
["Mozilla/5.0 (compatible; Discordbot/" <> _rest | _] -> true
|
|
||||||
_ -> false
|
|
||||||
end
|
|
||||||
|
|
||||||
if is_discord do
|
|
||||||
# Extract the ID from the path
|
|
||||||
id = List.last(conn.path_info)
|
|
||||||
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()
|
|
||||||
else
|
|
||||||
conn
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue