diff options
author | Haelwenn (lanodan) Monnier <contact@hacktivis.me> | 2023-06-27 02:08:49 +0200 |
---|---|---|
committer | Haelwenn (lanodan) Monnier <contact@hacktivis.me> | 2023-06-27 10:41:25 +0200 |
commit | 3a67b8f28728d3071c9a64d9b8c07ab91919676f (patch) | |
tree | f988242cc8ad957480cbcff3f7a4e158815f6c83 | |
parent | 9e69adf76fcd8c13581dcd1abc68520f3f0e25d8 (diff) | |
download | pleroma-3a67b8f28728d3071c9a64d9b8c07ab91919676f.tar.gz pleroma-3a67b8f28728d3071c9a64d9b8c07ab91919676f.zip |
endpoint: Use custom Multipart module for dynamic configuration
-rw-r--r-- | lib/pleroma/web/endpoint.ex | 7 | ||||
-rw-r--r-- | lib/pleroma/web/multipart.ex | 22 |
2 files changed, 24 insertions, 5 deletions
diff --git a/lib/pleroma/web/endpoint.ex b/lib/pleroma/web/endpoint.ex index d8d40cceb..574f3ab63 100644 --- a/lib/pleroma/web/endpoint.ex +++ b/lib/pleroma/web/endpoint.ex @@ -101,13 +101,10 @@ defmodule Pleroma.Web.Endpoint do plug(Plug.Logger, log: :debug) plug(Plug.Parsers, - parsers: [ - :urlencoded, - {:multipart, length: {Config, :get, [[:instance, :upload_limit]]}}, - :json - ], + parsers: [:urlencoded, Pleroma.Web.Multipart, :json], pass: ["*/*"], json_decoder: Jason, + # Note: this is compile-time only, won't work for database-config length: Config.get([:instance, :upload_limit]), body_reader: {Pleroma.Web.Plugs.DigestPlug, :read_body, []} ) diff --git a/lib/pleroma/web/multipart.ex b/lib/pleroma/web/multipart.ex new file mode 100644 index 000000000..e24bb14c2 --- /dev/null +++ b/lib/pleroma/web/multipart.ex @@ -0,0 +1,22 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2023 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +# <https://hexdocs.pm/plug/Plug.Parsers.MULTIPART.html#module-dynamic-configuration> +defmodule Pleroma.Web.Multipart do + @multipart Plug.Parsers.MULTIPART + + def init(opts) do + opts + end + + def parse(conn, "multipart", subtype, headers, opts) do + length = Pleroma.Config.get([:instance, :upload_limit]) + opts = @multipart.init([length: length] ++ opts) + @multipart.parse(conn, "multipart", subtype, headers, opts) + end + + def parse(conn, _type, _subtype, _headers, _opts) do + {:next, conn} + end +end |