-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master'
- Loading branch information
Showing
31 changed files
with
333 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"> | ||
<ShortName>Derpibooru</ShortName> | ||
<Description>Derpibooru image search</Description> | ||
<InputEncoding>UTF-8</InputEncoding> | ||
<Image width="16" height="16" type="image/x-icon">https://derpibooru.org/favicon.ico</Image> | ||
<Image width="64" height="64" type="image/svg+xml">https://derpibooru.org/favicon.svg</Image> | ||
<Url type="text/html" method="get" template="https://derpibooru.org/search"> | ||
<Param name="q" value="{searchTerms}"/> | ||
</Url> | ||
</OpenSearchDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
defmodule Philomena.Mailer do | ||
use Bamboo.Mailer, otp_app: :philomena | ||
use Swoosh.Mailer, otp_app: :philomena | ||
|
||
@spec deliver_later(Swoosh.Email.t()) :: {:ok, Swoosh.Email.t()} | ||
def deliver_later(mail) do | ||
Task.Supervisor.start_child(Philomena.AsyncEmailSupervisor, fn -> deliver(mail) end) | ||
{:ok, mail} | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
defmodule PhilomenaProxy.Camo do | ||
@moduledoc """ | ||
Image proxying utilities. | ||
""" | ||
|
||
@doc """ | ||
Convert a potentially untrusted external image URL into a trusted one | ||
loaded through a gocamo proxy (specified by the environment). | ||
Configuration is read from environment variables at runtime by Philomena. | ||
config :philomena, | ||
camo_host: System.get_env("CAMO_HOST"), | ||
camo_key: System.get_env("CAMO_KEY"), | ||
## Example | ||
iex> PhilomenaProxy.Camo.image_url("https://example.org/img/view/2024/1/1/1.png") | ||
"https://example.net/L5MqSmYq1ZEqiBGGvsvSDpILyJI/aHR0cHM6Ly9leGFtcGxlLm9yZy9pbWcvdmlldy8yMDI0LzEvMS8xLnBuZwo" | ||
""" | ||
@spec image_url(String.t()) :: String.t() | ||
def image_url(input), do: Philomena.Native.camo_image_url(input) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
defmodule PhilomenaProxy.Http do | ||
@moduledoc """ | ||
HTTP client implementation. | ||
This applies the Philomena User-Agent header, and optionally proxies traffic through a SOCKS5 | ||
HTTP proxy to allow the application to connect when the local network is restricted. | ||
If a proxy host is not specified in the configuration, then a proxy is not used and external | ||
traffic is originated from the same network as application. | ||
Proxy options are read from environment variables at runtime by Philomena. | ||
config :philomena, | ||
proxy_host: System.get_env("PROXY_HOST"), | ||
""" | ||
|
||
@type url :: String.t() | ||
@type header_list :: [{String.t(), String.t()}] | ||
@type body :: binary() | ||
|
||
@type client_options :: keyword() | ||
|
||
@doc ~S""" | ||
Perform a HTTP GET request. | ||
## Example | ||
iex> PhilomenaProxy.Http.get("http://example.com", [{"authorization", "Bearer #{token}"}]) | ||
{:ok, %Tesla.Env{...}} | ||
iex> PhilomenaProxy.Http.get("http://nonexistent.example.com") | ||
{:error, %Mint.TransportError{reason: :nxdomain}} | ||
""" | ||
@spec get(url(), header_list(), client_options()) :: Tesla.Env.result() | ||
def get(url, headers \\ [], options \\ []) do | ||
Tesla.get(client(headers), url, opts: [adapter: adapter_opts(options)]) | ||
end | ||
|
||
@doc ~S""" | ||
Perform a HTTP HEAD request. | ||
## Example | ||
iex> PhilomenaProxy.Http.head("http://example.com", [{"authorization", "Bearer #{token}"}]) | ||
{:ok, %Tesla.Env{...}} | ||
iex> PhilomenaProxy.Http.head("http://nonexistent.example.com") | ||
{:error, %Mint.TransportError{reason: :nxdomain}} | ||
""" | ||
@spec head(url(), header_list(), client_options()) :: Tesla.Env.result() | ||
def head(url, headers \\ [], options \\ []) do | ||
Tesla.head(client(headers), url, opts: [adapter: adapter_opts(options)]) | ||
end | ||
|
||
@doc ~S""" | ||
Perform a HTTP POST request. | ||
## Example | ||
iex> PhilomenaProxy.Http.post("http://example.com", "", [{"authorization", "Bearer #{token}"}]) | ||
{:ok, %Tesla.Env{...}} | ||
iex> PhilomenaProxy.Http.post("http://nonexistent.example.com", "") | ||
{:error, %Mint.TransportError{reason: :nxdomain}} | ||
""" | ||
@spec post(url(), body(), header_list(), client_options()) :: Tesla.Env.result() | ||
def post(url, body, headers \\ [], options \\ []) do | ||
Tesla.post(client(headers), url, body, opts: [adapter: adapter_opts(options)]) | ||
end | ||
|
||
defp adapter_opts(opts) do | ||
opts = Keyword.merge(opts, max_body: 125_000_000, inet6: true) | ||
|
||
case Application.get_env(:philomena, :proxy_host) do | ||
nil -> | ||
opts | ||
|
||
url -> | ||
Keyword.merge(opts, proxy: proxy_opts(URI.parse(url))) | ||
end | ||
end | ||
|
||
defp proxy_opts(%{host: host, port: port, scheme: "https"}), | ||
do: {:https, host, port, [transport_opts: [inet6: true]]} | ||
|
||
defp proxy_opts(%{host: host, port: port, scheme: "http"}), | ||
do: {:http, host, port, [transport_opts: [inet6: true]]} | ||
|
||
defp client(headers) do | ||
Tesla.client( | ||
[ | ||
{Tesla.Middleware.FollowRedirects, max_redirects: 1}, | ||
{Tesla.Middleware.Headers, | ||
[ | ||
{"User-Agent", | ||
"Mozilla/5.0 (X11; Philomena; Linux x86_64; rv:86.0) Gecko/20100101 Firefox/86.0"} | ||
| headers | ||
]} | ||
], | ||
Tesla.Adapter.Mint | ||
) | ||
end | ||
end |
Oops, something went wrong.