endpoint: Use custom Multipart module for dynamic configuration
This commit is contained in:
parent
9e69adf76f
commit
3a67b8f287
@ -101,13 +101,10 @@ defmodule Pleroma.Web.Endpoint do
|
|||||||
plug(Plug.Logger, log: :debug)
|
plug(Plug.Logger, log: :debug)
|
||||||
|
|
||||||
plug(Plug.Parsers,
|
plug(Plug.Parsers,
|
||||||
parsers: [
|
parsers: [:urlencoded, Pleroma.Web.Multipart, :json],
|
||||||
:urlencoded,
|
|
||||||
{:multipart, length: {Config, :get, [[:instance, :upload_limit]]}},
|
|
||||||
:json
|
|
||||||
],
|
|
||||||
pass: ["*/*"],
|
pass: ["*/*"],
|
||||||
json_decoder: Jason,
|
json_decoder: Jason,
|
||||||
|
# Note: this is compile-time only, won't work for database-config
|
||||||
length: Config.get([:instance, :upload_limit]),
|
length: Config.get([:instance, :upload_limit]),
|
||||||
body_reader: {Pleroma.Web.Plugs.DigestPlug, :read_body, []}
|
body_reader: {Pleroma.Web.Plugs.DigestPlug, :read_body, []}
|
||||||
)
|
)
|
||||||
|
22
lib/pleroma/web/multipart.ex
Normal file
22
lib/pleroma/web/multipart.ex
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user