Skip to content

Commit fba06e4

Browse files
committed
feat: add OG Image redirect functionality
- Introduced `OGRedirectController` to handle legacy OG image redirects based on organization handle and asset type. - Added a new route in the router for redirecting requests to the appropriate paths for OG images. - Implemented error handling for unknown assets, returning a 404 status with an error message.
1 parent 831ff19 commit fba06e4

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
defmodule AlgoraWeb.API.OGRedirectController do
2+
use AlgoraWeb, :controller
3+
4+
def redirect_to_org_path(conn, %{"org_handle" => org_handle, "asset" => asset} = params) do
5+
target_path =
6+
case {asset, params["status"]} do
7+
{"leaderboard.png", _} ->
8+
"/og/org/#{org_handle}/leaderboard"
9+
10+
{"bounties.png", status} when not is_nil(status) ->
11+
"/og/org/#{org_handle}/bounties?status=#{status}"
12+
13+
{"bounties.png", _} ->
14+
"/og/org/#{org_handle}/bounties"
15+
16+
_ ->
17+
nil
18+
end
19+
20+
if is_nil(target_path) do
21+
conn
22+
|> put_status(404)
23+
|> json(%{error: "Unknown asset: #{asset}"})
24+
|> halt()
25+
else
26+
conn
27+
|> redirect(to: target_path)
28+
|> halt()
29+
end
30+
end
31+
end

lib/algora_web/router.ex

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ defmodule AlgoraWeb.Router do
172172
get "/trpc/bounty.list", BountyController, :index
173173
post "/trpc/bounty.list", BountyController, :index
174174

175+
# Legacy OG Image redirects
176+
get "/og/:org_handle/:asset", OGRedirectController, :redirect_to_org_path
177+
175178
# Shields.io badges
176179
get "/shields/:org_handle/bounties", ShieldsController, :bounties
177180
end

0 commit comments

Comments
 (0)