Skip to content

Commit 1666c5f

Browse files
committed
feat: add refresh param to OG image controller
1 parent 61c2578 commit 1666c5f

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

lib/algora_web/controllers/og_image_controller.ex

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ defmodule AlgoraWeb.OGImageController do
1414
end
1515
end
1616

17-
def generate(conn, %{"path" => path}) do
17+
def generate(conn, %{"path" => path} = params) do
1818
object_path = Path.join(["og"] ++ path ++ ["og.png"])
1919
url = Path.join(Algora.S3.bucket_url(), object_path)
2020

2121
case :get |> Finch.build(url) |> Finch.request(Algora.Finch) do
2222
{:ok, %Finch.Response{status: status, body: body, headers: headers}} when status in 200..299 ->
23-
if should_regenerate?(path, headers) do
23+
if should_regenerate?(params, headers) do
2424
case take_and_upload_screenshot(path) do
2525
{:ok, body} ->
2626
conn
@@ -52,7 +52,9 @@ defmodule AlgoraWeb.OGImageController do
5252
end
5353
end
5454

55-
defp should_regenerate?(path, headers) do
55+
defp should_regenerate?(params, _headers) when is_map_key(params, "refresh"), do: true
56+
57+
defp should_regenerate?(%{"path" => path}, headers) do
5658
case List.keyfind(headers, "last-modified", 0) do
5759
{_, last_modified} ->
5860
case DateTime.from_iso8601(convert_to_iso8601(last_modified)) do

0 commit comments

Comments
 (0)