Expose maximum picture sizes

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-04-12 10:13:11 +02:00
parent fb614cf877
commit 0210b677c5
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
7 changed files with 39 additions and 4 deletions

View file

@ -25,9 +25,9 @@ config :mobilizon, :instance,
allow_relay: true, allow_relay: true,
federating: true, federating: true,
remote_limit: 100_000, remote_limit: 100_000,
upload_limit: 10_000_000, upload_limit: 10_485_760,
avatar_upload_limit: 2_000_000, avatar_upload_limit: 2_097_152,
banner_upload_limit: 4_000_000, banner_upload_limit: 4_194_304,
remove_orphan_uploads: true, remove_orphan_uploads: true,
orphan_upload_grace_period_hours: 48, orphan_upload_grace_period_hours: 48,
remove_unconfirmed_users: true, remove_unconfirmed_users: true,

View file

@ -75,6 +75,11 @@ export const CONFIG = gql`
label label
} }
} }
uploadLimits {
default
avatar
banner
}
} }
} }
`; `;

View file

@ -89,4 +89,9 @@ export interface IConfig {
ldap: boolean; ldap: boolean;
oauthProviders: IOAuthProvider[]; oauthProviders: IOAuthProvider[];
}; };
uploadLimits: {
default: number;
avatar: number;
banner: number;
};
} }

View file

@ -102,6 +102,12 @@ export const configMock = {
}, },
], ],
slogan: null, slogan: null,
uploadLimits: {
__typename: "UploadLimits",
default: 10_000_000,
avatar: 2_000_000,
banner: 4_000_000,
},
}, },
}, },
}; };

View file

@ -134,6 +134,11 @@ defmodule Mobilizon.GraphQL.Resolvers.Config do
auth: %{ auth: %{
ldap: Config.ldap_enabled?(), ldap: Config.ldap_enabled?(),
oauth_providers: Config.oauth_consumer_strategies() oauth_providers: Config.oauth_consumer_strategies()
},
upload_limits: %{
default: Config.get([:instance, :upload_limit]),
avatar: Config.get([:instance, :avatar_upload_limit]),
banner: Config.get([:instance, :banner_upload_limit])
} }
} }
end end

View file

@ -33,6 +33,8 @@ defmodule Mobilizon.GraphQL.Schema.ConfigType do
description: "The instance's enabled resource providers" description: "The instance's enabled resource providers"
) )
field(:upload_limits, :upload_limits, description: "The configuration for upload limits")
field(:timezones, list_of(:string), description: "The instance's available timezones") field(:timezones, list_of(:string), description: "The instance's available timezones")
field(:features, :features, description: "The instance's features") field(:features, :features, description: "The instance's features")
field(:version, :string, description: "The instance's version") field(:version, :string, description: "The instance's version")
@ -283,6 +285,15 @@ defmodule Mobilizon.GraphQL.Schema.ConfigType do
field(:label, :string, description: "The label for the auth provider") field(:label, :string, description: "The label for the auth provider")
end end
@desc """
An upload limits configuration
"""
object :upload_limits do
field(:default, :integer, description: "The default limitation, in bytes")
field(:avatar, :integer, description: "The avatar limitation, in bytes")
field(:banner, :integer, description: "The banner limitation, in bytes")
end
object :config_queries do object :config_queries do
@desc "Get the instance config" @desc "Get the instance config"
field :config, :config do field :config, :config do

View file

@ -62,9 +62,12 @@ defmodule Mobilizon.Web.Endpoint do
plug(Plug.RequestId) plug(Plug.RequestId)
plug(Plug.Logger) plug(Plug.Logger)
upload_limit =
Keyword.get(Application.get_env(:mobilizon, :instance, []), :upload_limit, 10_485_760)
plug( plug(
Plug.Parsers, Plug.Parsers,
parsers: [:urlencoded, {:multipart, length: 10_000_000}, :json, Absinthe.Plug.Parser], parsers: [:urlencoded, {:multipart, length: upload_limit}, :json, Absinthe.Plug.Parser],
pass: ["*/*"], pass: ["*/*"],
json_decoder: Jason json_decoder: Jason
) )