Add support for custom modules

This commit is contained in:
Egor Kislitsyn 2019-12-05 20:18:25 +07:00
parent 7722e5a67a
commit 48ae3c4347
4 changed files with 28 additions and 0 deletions

View File

@ -45,6 +45,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Mix task to list all users (`mix pleroma.user list`) - Mix task to list all users (`mix pleroma.user list`)
- Support for `X-Forwarded-For` and similar HTTP headers which used by reverse proxies to pass a real user IP address to the backend. Must not be enabled unless your instance is behind at least one reverse proxy (such as Nginx, Apache HTTPD or Varnish Cache). - Support for `X-Forwarded-For` and similar HTTP headers which used by reverse proxies to pass a real user IP address to the backend. Must not be enabled unless your instance is behind at least one reverse proxy (such as Nginx, Apache HTTPD or Varnish Cache).
- MRF: New module which handles incoming posts based on their age. By default, all incoming posts that are older than 2 days will be unlisted and not shown to their followers. - MRF: New module which handles incoming posts based on their age. By default, all incoming posts that are older than 2 days will be unlisted and not shown to their followers.
- Support for custom Elixir modules (such as MRF policies)
<details> <details>
<summary>API Changes</summary> <summary>API Changes</summary>

View File

@ -249,6 +249,7 @@ config :pleroma, :instance,
quarantined_instances: [], quarantined_instances: [],
managed_config: true, managed_config: true,
static_dir: "instance/static/", static_dir: "instance/static/",
custom_modules_dir: "instance/modules/",
allowed_post_formats: [ allowed_post_formats: [
"text/plain", "text/plain",
"text/html", "text/html",

View File

@ -68,6 +68,8 @@ You shouldn't edit the base config directly to avoid breakages and merge conflic
* `account_field_name_length`: An account field name maximum length (default: `512`). * `account_field_name_length`: An account field name maximum length (default: `512`).
* `account_field_value_length`: An account field value maximum length (default: `2048`). * `account_field_value_length`: An account field value maximum length (default: `2048`).
* `external_user_synchronization`: Enabling following/followers counters synchronization for external users. * `external_user_synchronization`: Enabling following/followers counters synchronization for external users.
* `custom_modules_dir`: A path to custom Elixir modules (such as MRF policies).
!!! danger !!! danger
This is a Work In Progress, not usable just yet This is a Work In Progress, not usable just yet

View File

@ -32,6 +32,7 @@ defmodule Pleroma.Application do
def start(_type, _args) do def start(_type, _args) do
Pleroma.Config.DeprecationWarnings.warn() Pleroma.Config.DeprecationWarnings.warn()
setup_instrumenters() setup_instrumenters()
load_custom_modules()
# Define workers and child supervisors to be supervised # Define workers and child supervisors to be supervised
children = children =
@ -67,6 +68,29 @@ defmodule Pleroma.Application do
Supervisor.start_link(children, opts) Supervisor.start_link(children, opts)
end end
def load_custom_modules() do
dir = Pleroma.Config.get([:instance, :custom_modules_dir])
if dir && File.exists?(dir) do
dir
|> File.ls!()
|> Enum.map(&Path.join(dir, &1))
|> Kernel.ParallelCompiler.compile()
|> case do
{:error, _errors, _warnings} ->
raise "Invalid custom modules"
{:ok, modules, _warnings} ->
Enum.each(modules, fn mod ->
name = mod |> Atom.to_string() |> String.trim_leading("Elixir.")
IO.puts("Custom module loaded: #{name}")
end)
:ok
end
end
end
defp setup_instrumenters do defp setup_instrumenters do
require Prometheus.Registry require Prometheus.Registry