From c869d17986093efab876a800b4f7b90bdac4c634 Mon Sep 17 00:00:00 2001 From: Jordan Bracco Date: Thu, 26 Jun 2025 17:40:23 +0200 Subject: link: reddit: use proxy in handler, rewrite to old reddit otherwise --- lib/plugins/link/quirks.ex | 6 ++++++ lib/plugins/link/reddit.ex | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/plugins/link/quirks.ex b/lib/plugins/link/quirks.ex index af259a2..5acfdac 100644 --- a/lib/plugins/link/quirks.ex +++ b/lib/plugins/link/quirks.ex @@ -3,6 +3,12 @@ defmodule Nola.Plugins.Link.Quirks do # %URI{uri | host: "vxtwitter.com"} # end + # reddit: new reddit don't have titles for pages we don't handle in the reddit module + # fallback to old. which has nice titles + def uri(%URI{host: reddit} = uri) when reddit in ["www.reddit.com", "reddit.com"] do + %URI{uri | host: "old.reddit.com"} + end + def uri(url) do url end diff --git a/lib/plugins/link/reddit.ex b/lib/plugins/link/reddit.ex index bd38084..2a6527d 100644 --- a/lib/plugins/link/reddit.ex +++ b/lib/plugins/link/reddit.ex @@ -38,7 +38,9 @@ defmodule Nola.Plugins.Link.Reddit do def expand(_, %{mode: :sub, sub: sub}, _opts) do url = "https://api.reddit.com/r/#{sub}/about" - case HTTPoison.get(url) do + case HTTPoison.get(url, [], + proxy: Keyword.get(Application.get_env(:nola, __MODULE__, []), :proxy, nil) + ) do {:ok, %HTTPoison.Response{status_code: 200, body: body}} -> sr = Jason.decode!(body) @@ -84,7 +86,9 @@ defmodule Nola.Plugins.Link.Reddit do end def expand(_uri, %{mode: :post, path: path, sub: sub, post_id: post_id}, _opts) do - case HTTPoison.get("https://api.reddit.com#{path}?sr_detail=true") do + case HTTPoison.get("https://api.reddit.com#{path}?sr_detail=true", [], + proxy: Keyword.get(Application.get_env(:nola, __MODULE__, []), :proxy, nil) + ) do {:ok, %HTTPoison.Response{status_code: 200, body: body}} -> json = Jason.decode!(body) -- cgit v1.2.3