Skip to content

Commit 403a3cb

Browse files
committed
feat: enhance screenshot functionality and improve route handling
- Updated generate_image function in ScreenshotQueue to accept optional parameters. - Added screenshot function in Admin module to facilitate screenshot uploads. - Changed take_and_upload_screenshot function to public and improved URL construction for better path handling.
1 parent 2fcab1e commit 403a3cb

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

lib/algora/admin/admin.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ defmodule Algora.Admin do
1616

1717
require Logger
1818

19+
def screenshot(path), do: AlgoraWeb.OGImageController.take_and_upload_screenshot([path])
20+
1921
def alert(message) do
2022
email_job =
2123
Algora.Activities.SendEmail.changeset(%{

lib/algora/screenshot_queue.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ defmodule Algora.ScreenshotQueue do
1010
GenServer.start_link(__MODULE__, :ok, name: __MODULE__)
1111
end
1212

13-
def generate_image(url, opts) do
13+
def generate_image(url, opts \\ []) do
1414
GenServer.call(__MODULE__, {:generate_image, url, opts}, opts[:timeout] || @timeout)
1515
end
1616

lib/algora_web/controllers/og_image_controller.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ defmodule AlgoraWeb.OGImageController do
7171
conn |> put_status(:not_found) |> text("Not found")
7272
end
7373

74-
defp take_and_upload_screenshot(path) do
74+
def take_and_upload_screenshot(path) do
7575
dir = Path.join([System.tmp_dir!(), "og"] ++ path)
7676
File.mkdir_p!(dir)
7777
filepath = Path.join(dir, "og.png")
78-
url = url(~p"/#{path}?screenshot")
78+
url = Path.join([AlgoraWeb.Endpoint.url() | path]) <> "?screenshot"
7979

8080
case ScreenshotQueue.generate_image(url, Keyword.put(@opts, :path, filepath)) do
8181
{:ok, _path} ->

0 commit comments

Comments
 (0)