forked from AkkomaGang/akkoma
Compare commits
2 commits
develop
...
translatio
Author | SHA1 | Date | |
---|---|---|---|
|
bf8973abcd | ||
|
ae0fda3412 |
201 changed files with 1931 additions and 3084 deletions
9
.gitattributes
vendored
9
.gitattributes
vendored
|
@ -1,4 +1,11 @@
|
||||||
*.ex diff=elixir
|
*.ex diff=elixir
|
||||||
*.exs diff=elixir
|
*.exs diff=elixir
|
||||||
|
|
||||||
*.css diff=css
|
# Most of js/css files included in the repo are minified bundles,
|
||||||
|
# and we don't want to search/diff those as text files.
|
||||||
|
*.js binary
|
||||||
|
*.js.map binary
|
||||||
|
*.css binary
|
||||||
|
|
||||||
|
priv/static/instance/static.css diff=css
|
||||||
|
priv/static/static-fe/static-fe.css diff=css
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
name: "Bug report"
|
name: "Bug report"
|
||||||
about: "Something isn't working as expected"
|
about: "Something isn't working as expected"
|
||||||
title: "[bug] "
|
title: "[bug] "
|
||||||
labels:
|
|
||||||
- bug
|
|
||||||
body:
|
body:
|
||||||
- type: markdown
|
- type: markdown
|
||||||
attributes:
|
attributes:
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
name: "Feature request"
|
name: "Feature request"
|
||||||
about: "I'd like something to be added to Akkoma"
|
about: "I'd like something to be added to Akkoma"
|
||||||
title: "[feat] "
|
title: "[feat] "
|
||||||
labels:
|
|
||||||
- "feature request"
|
|
||||||
|
|
||||||
body:
|
body:
|
||||||
- type: markdown
|
- type: markdown
|
||||||
attributes:
|
attributes:
|
||||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -76,4 +76,3 @@ docs/site
|
||||||
|
|
||||||
# docker stuff
|
# docker stuff
|
||||||
docker-db
|
docker-db
|
||||||
*.iml
|
|
||||||
|
|
35
CHANGELOG.md
35
CHANGELOG.md
|
@ -6,41 +6,6 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
|
|
||||||
## Unreleased
|
## Unreleased
|
||||||
|
|
||||||
### Added
|
|
||||||
- Prometheus metrics exporting from `/api/v1/akkoma/metrics`
|
|
||||||
- Ability to alter http pool size
|
|
||||||
- Translation of statuses via ArgosTranslate
|
|
||||||
- Argon2 password hashing
|
|
||||||
- Ability to "verify" links in profile fields via rel=me
|
|
||||||
- Mix tasks to dump/load config to/from json for bulk editing
|
|
||||||
- Followed hashtag list at /api/v1/followed\_tags, API parity with mastodon
|
|
||||||
|
|
||||||
### Removed
|
|
||||||
- Non-finch HTTP adapters
|
|
||||||
- Legacy redirect from /api/pleroma/admin to /api/v1/pleroma/admin
|
|
||||||
- Legacy redirects from /api/pleroma to /api/v1/pleroma
|
|
||||||
- :crypt dependency
|
|
||||||
|
|
||||||
### Changed
|
|
||||||
- Return HTTP error 413 when uploading an avatar or banner that's above the configured upload limit instead of a 500.
|
|
||||||
- Non-admin users now cannot register `admin` scope tokens (not security-critical, they didn't work before, but you _could_ create them)
|
|
||||||
- Admin scopes will be dropped on create
|
|
||||||
- Rich media will now backoff for 20 minutes after a failure
|
|
||||||
- Quote posts are now considered as part of the same thread as the post they are quoting
|
|
||||||
- Simplified HTTP signature processing
|
|
||||||
- Rich media will now hard-exit after 5 seconds, to prevent timeline hangs
|
|
||||||
- HTTP Content Security Policy is now far more strict to prevent any potential XSS/CSS leakages
|
|
||||||
|
|
||||||
### Fixed
|
|
||||||
- /api/v1/accounts/lookup will now respect restrict\_unauthenticated
|
|
||||||
- Unknown atoms in the config DB will no longer crash akkoma on boot
|
|
||||||
|
|
||||||
### Upgrade notes
|
|
||||||
- Ensure `config :tesla, :adapter` is either unset, or set to `{Tesla.Adapter.Finch, name: MyFinch}` in your .exs config
|
|
||||||
- Pleroma-FE will need to be updated to handle the new /api/v1/pleroma endpoints for custom emoji
|
|
||||||
|
|
||||||
## 2022.12
|
|
||||||
|
|
||||||
## Added
|
## Added
|
||||||
- Config: HTTP timeout options, :pool\_timeout and :receive\_timeout
|
- Config: HTTP timeout options, :pool\_timeout and :receive\_timeout
|
||||||
- Added statistic gathering about instances which do/don't have signed fetches when they request from us
|
- Added statistic gathering about instances which do/don't have signed fetches when they request from us
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
FROM hexpm/elixir:1.13.4-erlang-24.3.4.5-alpine-3.15.6
|
FROM hexpm/elixir:1.13.4-erlang-24.3.4.5-alpine-3.15.6
|
||||||
|
|
||||||
ENV MIX_ENV=prod
|
ENV MIX_ENV=prod
|
||||||
ENV ERL_EPMD_ADDRESS=127.0.0.1
|
|
||||||
|
|
||||||
ARG HOME=/opt/akkoma
|
ARG HOME=/opt/akkoma
|
||||||
|
|
||||||
|
|
|
@ -163,6 +163,11 @@
|
||||||
format: "$metadata[$level] $message",
|
format: "$metadata[$level] $message",
|
||||||
metadata: [:request_id]
|
metadata: [:request_id]
|
||||||
|
|
||||||
|
config :quack,
|
||||||
|
level: :warn,
|
||||||
|
meta: [:all],
|
||||||
|
webhook_url: "https://hooks.slack.com/services/YOUR-KEY-HERE"
|
||||||
|
|
||||||
config :mime, :types, %{
|
config :mime, :types, %{
|
||||||
"application/xml" => ["xml"],
|
"application/xml" => ["xml"],
|
||||||
"application/xrd+xml" => ["xrd+xml"],
|
"application/xrd+xml" => ["xrd+xml"],
|
||||||
|
@ -179,7 +184,6 @@
|
||||||
receive_timeout: :timer.seconds(15),
|
receive_timeout: :timer.seconds(15),
|
||||||
proxy_url: nil,
|
proxy_url: nil,
|
||||||
user_agent: :default,
|
user_agent: :default,
|
||||||
pool_size: 50,
|
|
||||||
adapter: []
|
adapter: []
|
||||||
|
|
||||||
config :pleroma, :instance,
|
config :pleroma, :instance,
|
||||||
|
@ -260,8 +264,7 @@
|
||||||
profile_directory: true,
|
profile_directory: true,
|
||||||
privileged_staff: false,
|
privileged_staff: false,
|
||||||
local_bubble: [],
|
local_bubble: [],
|
||||||
max_frontend_settings_json_chars: 100_000,
|
max_frontend_settings_json_chars: 100_000
|
||||||
export_prometheus_metrics: true
|
|
||||||
|
|
||||||
config :pleroma, :welcome,
|
config :pleroma, :welcome,
|
||||||
direct_message: [
|
direct_message: [
|
||||||
|
@ -426,7 +429,7 @@
|
||||||
Pleroma.Web.RichMedia.Parsers.TwitterCard,
|
Pleroma.Web.RichMedia.Parsers.TwitterCard,
|
||||||
Pleroma.Web.RichMedia.Parsers.OEmbed
|
Pleroma.Web.RichMedia.Parsers.OEmbed
|
||||||
],
|
],
|
||||||
failure_backoff: :timer.minutes(20),
|
failure_backoff: 60_000,
|
||||||
ttl_setters: [Pleroma.Web.RichMedia.Parser.TTL.AwsSignedUrl]
|
ttl_setters: [Pleroma.Web.RichMedia.Parser.TTL.AwsSignedUrl]
|
||||||
|
|
||||||
config :pleroma, :media_proxy,
|
config :pleroma, :media_proxy,
|
||||||
|
@ -652,10 +655,6 @@
|
||||||
|
|
||||||
config :pleroma, Pleroma.Emails.Mailer, adapter: Swoosh.Adapters.Sendmail, enabled: false
|
config :pleroma, Pleroma.Emails.Mailer, adapter: Swoosh.Adapters.Sendmail, enabled: false
|
||||||
|
|
||||||
config :swoosh,
|
|
||||||
api_client: Swoosh.ApiClient.Finch,
|
|
||||||
finch_name: MyFinch
|
|
||||||
|
|
||||||
config :pleroma, Pleroma.Emails.UserEmail,
|
config :pleroma, Pleroma.Emails.UserEmail,
|
||||||
logo: nil,
|
logo: nil,
|
||||||
styling: %{
|
styling: %{
|
||||||
|
@ -783,6 +782,14 @@
|
||||||
"https://akkoma-updates.s3-website.fr-par.scw.cloud/frontend/${ref}/admin-fe.zip",
|
"https://akkoma-updates.s3-website.fr-par.scw.cloud/frontend/${ref}/admin-fe.zip",
|
||||||
"ref" => "stable"
|
"ref" => "stable"
|
||||||
},
|
},
|
||||||
|
"soapbox-fe" => %{
|
||||||
|
"name" => "soapbox-fe",
|
||||||
|
"git" => "https://gitlab.com/soapbox-pub/soapbox",
|
||||||
|
"build_url" =>
|
||||||
|
"https://gitlab.com/soapbox-pub/soapbox/-/jobs/artifacts/${ref}/download?job=build-production",
|
||||||
|
"ref" => "v2.0.0",
|
||||||
|
"build_dir" => "static"
|
||||||
|
},
|
||||||
# For developers - enables a swagger frontend to view the openapi spec
|
# For developers - enables a swagger frontend to view the openapi spec
|
||||||
"swagger-ui" => %{
|
"swagger-ui" => %{
|
||||||
"name" => "swagger-ui",
|
"name" => "swagger-ui",
|
||||||
|
@ -882,11 +889,6 @@
|
||||||
url: "http://127.0.0.1:5000",
|
url: "http://127.0.0.1:5000",
|
||||||
api_key: nil
|
api_key: nil
|
||||||
|
|
||||||
config :pleroma, :argos_translate,
|
|
||||||
command_argos_translate: "argos-translate",
|
|
||||||
command_argospm: "argospm",
|
|
||||||
strip_html: true
|
|
||||||
|
|
||||||
# Import environment specific config. This must remain at the bottom
|
# Import environment specific config. This must remain at the bottom
|
||||||
# of this file so it overrides the configuration defined above.
|
# of this file so it overrides the configuration defined above.
|
||||||
import_config "#{Mix.env()}.exs"
|
import_config "#{Mix.env()}.exs"
|
||||||
|
|
|
@ -964,11 +964,6 @@
|
||||||
type: {:list, :string},
|
type: {:list, :string},
|
||||||
description:
|
description:
|
||||||
"List of instances that make up your local bubble (closely-related instances). Used to populate the 'bubble' timeline (domain only)."
|
"List of instances that make up your local bubble (closely-related instances). Used to populate the 'bubble' timeline (domain only)."
|
||||||
},
|
|
||||||
%{
|
|
||||||
key: :export_prometheus_metrics,
|
|
||||||
type: :boolean,
|
|
||||||
description: "Enable prometheus metrics (at /api/v1/akkoma/metrics)"
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -1123,6 +1118,45 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
%{
|
||||||
|
group: :quack,
|
||||||
|
type: :group,
|
||||||
|
label: "Quack Logger",
|
||||||
|
description: "Quack-related settings",
|
||||||
|
children: [
|
||||||
|
%{
|
||||||
|
key: :level,
|
||||||
|
type: {:dropdown, :atom},
|
||||||
|
description: "Log level",
|
||||||
|
suggestions: [:debug, :info, :warn, :error]
|
||||||
|
},
|
||||||
|
%{
|
||||||
|
key: :meta,
|
||||||
|
type: {:list, :atom},
|
||||||
|
description: "Configure which metadata you want to report on",
|
||||||
|
suggestions: [
|
||||||
|
:application,
|
||||||
|
:module,
|
||||||
|
:file,
|
||||||
|
:function,
|
||||||
|
:line,
|
||||||
|
:pid,
|
||||||
|
:crash_reason,
|
||||||
|
:initial_call,
|
||||||
|
:registered_name,
|
||||||
|
:all,
|
||||||
|
:none
|
||||||
|
]
|
||||||
|
},
|
||||||
|
%{
|
||||||
|
key: :webhook_url,
|
||||||
|
label: "Webhook URL",
|
||||||
|
type: :string,
|
||||||
|
description: "Configure the Slack incoming webhook",
|
||||||
|
suggestions: ["https://hooks.slack.com/services/YOUR-KEY-HERE"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
%{
|
%{
|
||||||
group: :pleroma,
|
group: :pleroma,
|
||||||
key: :frontend_configurations,
|
key: :frontend_configurations,
|
||||||
|
@ -2661,12 +2695,6 @@
|
||||||
"What user agent to use. Must be a string or an atom `:default`. Default value is `:default`.",
|
"What user agent to use. Must be a string or an atom `:default`. Default value is `:default`.",
|
||||||
suggestions: ["Pleroma", :default]
|
suggestions: ["Pleroma", :default]
|
||||||
},
|
},
|
||||||
%{
|
|
||||||
key: :pool_size,
|
|
||||||
type: :integer,
|
|
||||||
description: "Number of concurrent outbound HTTP requests to allow. Default 50.",
|
|
||||||
suggestions: [50]
|
|
||||||
},
|
|
||||||
%{
|
%{
|
||||||
key: :adapter,
|
key: :adapter,
|
||||||
type: :keyword,
|
type: :keyword,
|
||||||
|
@ -3442,32 +3470,5 @@
|
||||||
suggestion: [nil]
|
suggestion: [nil]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
|
||||||
%{
|
|
||||||
group: :pleroma,
|
|
||||||
key: :argos_translate,
|
|
||||||
type: :group,
|
|
||||||
description: "ArgosTranslate Settings.",
|
|
||||||
children: [
|
|
||||||
%{
|
|
||||||
key: :command_argos_translate,
|
|
||||||
type: :string,
|
|
||||||
description:
|
|
||||||
"command for `argos-translate`. Can be the command if it's in your PATH, or the full path to the file.",
|
|
||||||
suggestion: ["argos-translate"]
|
|
||||||
},
|
|
||||||
%{
|
|
||||||
key: :command_argospm,
|
|
||||||
type: :string,
|
|
||||||
description:
|
|
||||||
"command for `argospm`. Can be the command if it's in your PATH, or the full path to the file.",
|
|
||||||
suggestion: ["argospm"]
|
|
||||||
},
|
|
||||||
%{
|
|
||||||
key: :strip_html,
|
|
||||||
type: :boolean,
|
|
||||||
description: "Strip html from the post before translating it."
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
MIX_ENV=prod
|
MIX_ENV=prod
|
||||||
ERL_EPMD_ADDRESS=127.0.0.1
|
|
||||||
DB_NAME=akkoma
|
DB_NAME=akkoma
|
||||||
DB_USER=akkoma
|
DB_USER=akkoma
|
||||||
DB_PASS=akkoma
|
DB_PASS=akkoma
|
||||||
|
|
|
@ -155,51 +155,3 @@ This forcibly removes all saved values in the database.
|
||||||
```sh
|
```sh
|
||||||
mix pleroma.config [--force] reset
|
mix pleroma.config [--force] reset
|
||||||
```
|
```
|
||||||
|
|
||||||
## Dumping specific configuration values to JSON
|
|
||||||
|
|
||||||
If you want to bulk-modify configuration values (for example, for MRF modifications),
|
|
||||||
it may be easier to dump the values to JSON and then modify them in a text editor.
|
|
||||||
|
|
||||||
=== "OTP"
|
|
||||||
|
|
||||||
```sh
|
|
||||||
./bin/pleroma_ctl config dump_to_file group key path
|
|
||||||
# For example, to dump the MRF simple configuration:
|
|
||||||
./bin/pleroma_ctl config dump_to_file pleroma mrf_simple /tmp/mrf_simple.json
|
|
||||||
```
|
|
||||||
|
|
||||||
=== "From Source"
|
|
||||||
|
|
||||||
```sh
|
|
||||||
mix pleroma.config dump_to_file group key path
|
|
||||||
# For example, to dump the MRF simple configuration:
|
|
||||||
mix pleroma.config dump_to_file pleroma mrf_simple /tmp/mrf_simple.json
|
|
||||||
```
|
|
||||||
|
|
||||||
## Loading specific configuration values from JSON
|
|
||||||
|
|
||||||
**Note:** This will overwrite any existing value in the database, and can
|
|
||||||
cause crashes if you do not have exactly the correct formatting.
|
|
||||||
|
|
||||||
Once you have modified the JSON file, you can load it back into the database.
|
|
||||||
|
|
||||||
=== "OTP"
|
|
||||||
|
|
||||||
```sh
|
|
||||||
./bin/pleroma_ctl config load_from_file path
|
|
||||||
# For example, to load the MRF simple configuration:
|
|
||||||
./bin/pleroma_ctl config load_from_file /tmp/mrf_simple.json
|
|
||||||
```
|
|
||||||
|
|
||||||
=== "From Source"
|
|
||||||
|
|
||||||
```sh
|
|
||||||
mix pleroma.config load_from_file path
|
|
||||||
# For example, to load the MRF simple configuration:
|
|
||||||
mix pleroma.config load_from_file /tmp/mrf_simple.json
|
|
||||||
```
|
|
||||||
|
|
||||||
**NOTE** an instance reboot is needed for many changes to take effect,
|
|
||||||
you may want to visit `/api/v1/pleroma/admin/restart` on your instance
|
|
||||||
to soft-restart the instance.
|
|
||||||
|
|
|
@ -21,23 +21,24 @@ Currently, known `<frontend>` values are:
|
||||||
- [admin-fe](https://akkoma.dev/AkkomaGang/admin-fe)
|
- [admin-fe](https://akkoma.dev/AkkomaGang/admin-fe)
|
||||||
- [mastodon-fe](https://akkoma.dev/AkkomaGang/masto-fe)
|
- [mastodon-fe](https://akkoma.dev/AkkomaGang/masto-fe)
|
||||||
- [pleroma-fe](https://akkoma.dev/AkkomaGang/pleroma-fe)
|
- [pleroma-fe](https://akkoma.dev/AkkomaGang/pleroma-fe)
|
||||||
|
- [soapbox-fe](https://gitlab.com/soapbox-pub/soapbox-fe)
|
||||||
|
|
||||||
You can still install frontends that are not configured, see below.
|
You can still install frontends that are not configured, see below.
|
||||||
|
|
||||||
## Example installations for a known frontend (Stable-Version)
|
## Example installations for a known frontend
|
||||||
|
|
||||||
For a frontend configured under the `available` key, it's enough to install it by name.
|
For a frontend configured under the `available` key, it's enough to install it by name.
|
||||||
|
|
||||||
=== "OTP"
|
=== "OTP"
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
./bin/pleroma_ctl frontend install pleroma-fe --ref stable
|
./bin/pleroma_ctl frontend install pleroma-fe
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "From Source"
|
=== "From Source"
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
mix pleroma.frontend install pleroma-fe --ref stable
|
mix pleroma.frontend install pleroma-fe
|
||||||
```
|
```
|
||||||
|
|
||||||
This will download the latest build for the pre-configured `ref` and install it. It can then be configured as the one of the served frontends in the config file (see `primary` or `admin`).
|
This will download the latest build for the pre-configured `ref` and install it. It can then be configured as the one of the served frontends in the config file (see `primary` or `admin`).
|
||||||
|
|
|
@ -11,11 +11,11 @@ If you want to generate a restrictive `robots.txt`, you can run the following mi
|
||||||
=== "OTP"
|
=== "OTP"
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
./bin/pleroma_ctl robotstxt disallow_all
|
./bin/pleroma_ctl robots_txt disallow_all
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "From Source"
|
=== "From Source"
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
mix pleroma.robotstxt disallow_all
|
mix pleroma.robots_txt disallow_all
|
||||||
```
|
```
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
# Monitoring Akkoma
|
|
||||||
|
|
||||||
If you run akkoma, you may be inclined to collect metrics to ensure your instance is running smoothly,
|
|
||||||
and that there's nothing quietly failing in the background.
|
|
||||||
|
|
||||||
To facilitate this, akkoma exposes prometheus metrics to be scraped.
|
|
||||||
|
|
||||||
## Prometheus
|
|
||||||
|
|
||||||
See: [export\_prometheus\_metrics](../../configuration/cheatsheet#instance)
|
|
||||||
|
|
||||||
To scrape prometheus metrics, we need an oauth2 token with the `admin:metrics` scope.
|
|
||||||
|
|
||||||
consider using [constanze](https://akkoma.dev/AkkomaGang/constanze) to make this easier -
|
|
||||||
|
|
||||||
```bash
|
|
||||||
constanze token --client-app --scopes "admin:metrics" --client-name "Prometheus"
|
|
||||||
```
|
|
||||||
|
|
||||||
or see `scripts/create_metrics_app.sh` in the source tree for the process to get this token.
|
|
||||||
|
|
||||||
Once you have your token of the form `Bearer $ACCESS_TOKEN`, you can use that in your prometheus config:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
- job_name: akkoma
|
|
||||||
scheme: https
|
|
||||||
authorization:
|
|
||||||
credentials: $ACCESS_TOKEN # this should have the bearer prefix removed
|
|
||||||
metrics_path: /api/v1/akkoma/metrics
|
|
||||||
static_configs:
|
|
||||||
- targets:
|
|
||||||
- example.com
|
|
||||||
```
|
|
|
@ -1,36 +1,17 @@
|
||||||
# Updating your instance
|
# Updating your instance
|
||||||
|
|
||||||
You should **always check the [release notes/changelog](https://akkoma.dev/AkkomaGang/akkoma/src/branch/stable/CHANGELOG.md)** in case there are config deprecations, special update steps, etc.
|
You should **always check the [release notes/changelog](https://akkoma.dev/AkkomaGang/akkoma/src/branch/develop/CHANGELOG.md)** in case there are config deprecations, special update steps, etc.
|
||||||
|
|
||||||
Besides that, doing the following is generally enough:
|
Besides that, doing the following is generally enough:
|
||||||
## Switch to the akkoma user
|
|
||||||
```sh
|
|
||||||
# Using sudo
|
|
||||||
sudo -su akkoma
|
|
||||||
|
|
||||||
# Using doas
|
|
||||||
doas -su akkoma
|
|
||||||
|
|
||||||
# Using su
|
|
||||||
su -s "$SHELL" akkoma
|
|
||||||
```
|
|
||||||
|
|
||||||
## For OTP installations
|
## For OTP installations
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
# Download latest stable release
|
# Download the new release
|
||||||
./bin/pleroma_ctl update --branch stable
|
su akkoma -s $SHELL -lc "./bin/pleroma_ctl update"
|
||||||
|
|
||||||
# Stop akkoma
|
# Migrate the database, you are advised to stop the instance before doing that
|
||||||
./bin/pleroma stop # or using the system service manager (e.g. systemctl stop akkoma)
|
su akkoma -s $SHELL -lc "./bin/pleroma_ctl migrate"
|
||||||
|
|
||||||
# Run database migrations
|
|
||||||
./bin/pleroma_ctl migrate
|
|
||||||
|
|
||||||
# Update frontend(s). See Frontend Configuration doc for more information.
|
|
||||||
./bin/pleroma_ctl frontend install pleroma-fe --ref stable
|
|
||||||
|
|
||||||
# Start akkoma
|
|
||||||
./bin/pleroma daemon # or using the system service manager (e.g. systemctl start akkoma)
|
|
||||||
```
|
```
|
||||||
|
|
||||||
If you selected an alternate flavour on installation,
|
If you selected an alternate flavour on installation,
|
||||||
|
@ -38,30 +19,13 @@ you _may_ need to specify `--flavour`, in the same way as
|
||||||
[when installing](../../installation/otp_en#detecting-flavour).
|
[when installing](../../installation/otp_en#detecting-flavour).
|
||||||
|
|
||||||
## For from source installations (using git)
|
## For from source installations (using git)
|
||||||
Run as the `akkoma` user:
|
|
||||||
|
|
||||||
```sh
|
1. Go to the working directory of Akkoma (default is `/opt/akkoma`)
|
||||||
# fetch changes
|
2. Run `git pull` [^1]. This pulls the latest changes from upstream.
|
||||||
git fetch
|
3. Run `mix deps.get` [^1]. This pulls in any new dependencies.
|
||||||
# check out the latest tag
|
4. Stop the Akkoma service.
|
||||||
git checkout $(git tag -l | grep -v 'rc[0-9]*$' | sort -V | tail -n 1)
|
5. Run `mix ecto.migrate` [^1] [^2]. This task performs database migrations, if there were any.
|
||||||
|
6. Start the Akkoma service.
|
||||||
|
|
||||||
# Run with production configuration
|
[^1]: Depending on which install guide you followed (for example on Debian/Ubuntu), you want to run `git` and `mix` tasks as `akkoma` user by adding `sudo -Hu akkoma` before the command.
|
||||||
export MIX_ENV=prod
|
[^2]: Prefix with `MIX_ENV=prod` to run it using the production config file.
|
||||||
|
|
||||||
# Download and compile dependencies
|
|
||||||
mix deps.get
|
|
||||||
mix compile
|
|
||||||
|
|
||||||
# Stop akkoma (replace with your system service manager's equivalent if different)
|
|
||||||
sudo systemctl stop akkoma
|
|
||||||
|
|
||||||
# Run database migrations
|
|
||||||
mix ecto.migrate
|
|
||||||
|
|
||||||
# Update Pleroma-FE frontend to latest stable. For other Frontends see Frontend Configration doc for more information.
|
|
||||||
mix pleroma.frontend install pleroma-fe --ref stable
|
|
||||||
|
|
||||||
# Start akkoma (replace with your system service manager's equivalent if different)
|
|
||||||
sudo systemctl start akkoma
|
|
||||||
```
|
|
||||||
|
|
|
@ -62,7 +62,6 @@ To add configuration to your config file, you can copy it from the base config.
|
||||||
* `password_reset_token_validity`: The time after which reset tokens aren't accepted anymore, in seconds (default: one day).
|
* `password_reset_token_validity`: The time after which reset tokens aren't accepted anymore, in seconds (default: one day).
|
||||||
* `local_bubble`: Array of domains representing instances closely related to yours. Used to populate the `bubble` timeline. e.g `["example.com"]`, (default: `[]`)
|
* `local_bubble`: Array of domains representing instances closely related to yours. Used to populate the `bubble` timeline. e.g `["example.com"]`, (default: `[]`)
|
||||||
* `languages`: List of Language Codes used by the instance. This is used to try and set a default language from the frontend. It will try and find the first match between the languages set here and the user's browser languages. It will default to the first language in this setting if there is no match.. (default `["en"]`)
|
* `languages`: List of Language Codes used by the instance. This is used to try and set a default language from the frontend. It will try and find the first match between the languages set here and the user's browser languages. It will default to the first language in this setting if there is no match.. (default `["en"]`)
|
||||||
* `export_prometheus_metrics`: Enable prometheus metrics, served at `/api/v1/akkoma/metrics`, requiring the `admin:metrics` oauth scope.
|
|
||||||
|
|
||||||
## :database
|
## :database
|
||||||
* `improved_hashtag_timeline`: Setting to force toggle / force disable improved hashtags timeline. `:enabled` forces hashtags to be fetched from `hashtags` table for hashtags timeline. `:disabled` forces object-embedded hashtags to be used (slower). Keep it `:auto` for automatic behaviour (it is auto-set to `:enabled` [unless overridden] when HashtagsTableMigrator completes).
|
* `improved_hashtag_timeline`: Setting to force toggle / force disable improved hashtags timeline. `:enabled` forces hashtags to be fetched from `hashtags` table for hashtags timeline. `:disabled` forces object-embedded hashtags to be used (slower). Keep it `:auto` for automatic behaviour (it is auto-set to `:enabled` [unless overridden] when HashtagsTableMigrator completes).
|
||||||
|
@ -529,6 +528,54 @@ Available caches:
|
||||||
* `user_agent`: what user agent should we use? (default: `:default`), must be string or `:default`
|
* `user_agent`: what user agent should we use? (default: `:default`), must be string or `:default`
|
||||||
* `adapter`: array of adapter options
|
* `adapter`: array of adapter options
|
||||||
|
|
||||||
|
### :hackney_pools
|
||||||
|
|
||||||
|
Advanced. Tweaks Hackney (http client) connections pools.
|
||||||
|
|
||||||
|
There's three pools used:
|
||||||
|
|
||||||
|
* `:federation` for the federation jobs.
|
||||||
|
You may want this pool max_connections to be at least equal to the number of federator jobs + retry queue jobs.
|
||||||
|
* `:media` for rich media, media proxy
|
||||||
|
* `:upload` for uploaded media (if using a remote uploader and `proxy_remote: true`)
|
||||||
|
|
||||||
|
For each pool, the options are:
|
||||||
|
|
||||||
|
* `max_connections` - how much connections a pool can hold
|
||||||
|
* `timeout` - retention duration for connections
|
||||||
|
|
||||||
|
|
||||||
|
### :connections_pool
|
||||||
|
|
||||||
|
*For `gun` adapter*
|
||||||
|
|
||||||
|
Settings for HTTP connection pool.
|
||||||
|
|
||||||
|
* `:connection_acquisition_wait` - Timeout to acquire a connection from pool.The total max time is this value multiplied by the number of retries.
|
||||||
|
* `connection_acquisition_retries` - Number of attempts to acquire the connection from the pool if it is overloaded. Each attempt is timed `:connection_acquisition_wait` apart.
|
||||||
|
* `:max_connections` - Maximum number of connections in the pool.
|
||||||
|
* `:connect_timeout` - Timeout to connect to the host.
|
||||||
|
* `:reclaim_multiplier` - Multiplied by `:max_connections` this will be the maximum number of idle connections that will be reclaimed in case the pool is overloaded.
|
||||||
|
|
||||||
|
### :pools
|
||||||
|
|
||||||
|
*For `gun` adapter*
|
||||||
|
|
||||||
|
Settings for request pools. These pools are limited on top of `:connections_pool`.
|
||||||
|
|
||||||
|
There are four pools used:
|
||||||
|
|
||||||
|
* `:federation` for the federation jobs. You may want this pool's max_connections to be at least equal to the number of federator jobs + retry queue jobs.
|
||||||
|
* `:media` - for rich media, media proxy.
|
||||||
|
* `:upload` - for proxying media when a remote uploader is used and `proxy_remote: true`.
|
||||||
|
* `:default` - for other requests.
|
||||||
|
|
||||||
|
For each pool, the options are:
|
||||||
|
|
||||||
|
* `:size` - limit to how much requests can be concurrently executed.
|
||||||
|
* `:recv_timeout` - timeout while `gun` will wait for response
|
||||||
|
* `:max_waiting` - limit to how much requests can be waiting for others to finish, after this is reached, subsequent requests will be dropped.
|
||||||
|
|
||||||
## Captcha
|
## Captcha
|
||||||
|
|
||||||
### Pleroma.Captcha
|
### Pleroma.Captcha
|
||||||
|
@ -786,8 +833,17 @@ config :logger, :ex_syslogger,
|
||||||
level: :info,
|
level: :info,
|
||||||
ident: "pleroma",
|
ident: "pleroma",
|
||||||
format: "$metadata[$level] $message"
|
format: "$metadata[$level] $message"
|
||||||
|
|
||||||
|
config :quack,
|
||||||
|
level: :warn,
|
||||||
|
meta: [:all],
|
||||||
|
webhook_url: "https://hooks.slack.com/services/YOUR-API-KEY-HERE"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
See the [Quack Github](https://github.com/azohra/quack) for more details
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Database options
|
## Database options
|
||||||
|
|
||||||
### RUM indexing for full text search
|
### RUM indexing for full text search
|
||||||
|
@ -1119,7 +1175,7 @@ Each job has these settings:
|
||||||
### Translation Settings
|
### Translation Settings
|
||||||
|
|
||||||
Settings to automatically translate statuses for end users. Currently supported
|
Settings to automatically translate statuses for end users. Currently supported
|
||||||
translation services are DeepL and LibreTranslate. The supported command line tool is [Argos Translate](https://github.com/argosopentech/argos-translate).
|
translation services are DeepL and LibreTranslate.
|
||||||
|
|
||||||
Translations are available at `/api/v1/statuses/:id/translations/:language`, where
|
Translations are available at `/api/v1/statuses/:id/translations/:language`, where
|
||||||
`language` is the target language code (e.g `en`)
|
`language` is the target language code (e.g `en`)
|
||||||
|
@ -1128,7 +1184,7 @@ Translations are available at `/api/v1/statuses/:id/translations/:language`, whe
|
||||||
|
|
||||||
- `:enabled` - enables translation
|
- `:enabled` - enables translation
|
||||||
- `:module` - Sets module to be used
|
- `:module` - Sets module to be used
|
||||||
- Either `Pleroma.Akkoma.Translators.DeepL`, `Pleroma.Akkoma.Translators.LibreTranslate`, or `Pleroma.Akkoma.Translators.ArgosTranslate`
|
- Either `Pleroma.Akkoma.Translators.DeepL` or `Pleroma.Akkoma.Translators.LibreTranslate`
|
||||||
|
|
||||||
### `:deepl`
|
### `:deepl`
|
||||||
|
|
||||||
|
@ -1140,9 +1196,3 @@ Translations are available at `/api/v1/statuses/:id/translations/:language`, whe
|
||||||
|
|
||||||
- `:url` - URL of LibreTranslate instance
|
- `:url` - URL of LibreTranslate instance
|
||||||
- `:api_key` - API key for LibreTranslate
|
- `:api_key` - API key for LibreTranslate
|
||||||
|
|
||||||
### `:argos_translate`
|
|
||||||
|
|
||||||
- `:command_argos_translate` - command for `argos-translate`. Can be the command if it's in your PATH, or the full path to the file (default: `argos-translate`).
|
|
||||||
- `:command_argospm` - command for `argospm`. Can be the command if it's in your PATH, or the full path to the file (default: `argospm`).
|
|
||||||
- `:strip_html` - Strip html from the post before translating it (default: `true`).
|
|
||||||
|
|
|
@ -67,29 +67,3 @@ Priority of tags assigns in emoji.txt and custom.txt:
|
||||||
Priority for globs:
|
Priority for globs:
|
||||||
|
|
||||||
`special group setting in config.exs > default setting in config.exs`
|
`special group setting in config.exs > default setting in config.exs`
|
||||||
|
|
||||||
## Stealing emoji
|
|
||||||
|
|
||||||
Managing your emoji can be hard work, and you just want to have the cool emoji your friends use? As usual, crime comes to the rescue!
|
|
||||||
|
|
||||||
You can use the `Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy` [Message Rewrite Facility](../configuration/cheatsheet.md#mrf) to automatically add to your instance emoji that messages from specific servers contain. Note that this happens on message processing, so the emoji will be added only after your instance receives some interaction containing emoji _after_ configuring this.
|
|
||||||
|
|
||||||
To activate this you have to [configure](../configuration/cheatsheet.md#mrf_steal_emoji) it in your configuration file. For example if you wanted to steal any emoji that is not related to cinnamon and not larger than about 10K from `coolemoji.space` and `spiceenthusiasts.biz`, you would add the following:
|
|
||||||
```elixir
|
|
||||||
config :pleroma, :mrf,
|
|
||||||
policies: [
|
|
||||||
Pleroma.Web.ActivityPub.MRF.StealEmojiPolicy
|
|
||||||
]
|
|
||||||
|
|
||||||
config :pleroma, :mrf_steal_emoji,
|
|
||||||
hosts: [
|
|
||||||
"coolemoji.space",
|
|
||||||
"spiceenthusiasts.biz"
|
|
||||||
],
|
|
||||||
rejected_shortcodes: [
|
|
||||||
".*cinnamon.*"
|
|
||||||
],
|
|
||||||
size_limit: 10000
|
|
||||||
```
|
|
||||||
|
|
||||||
Note that this may not obey emoji licensing restrictions. It's extremely unlikely that anyone will care, but keep this in mind for when Nintendo starts their own instance.
|
|
||||||
|
|
|
@ -1056,13 +1056,14 @@ Most of the settings will be applied in `runtime`, this means that you don't nee
|
||||||
|
|
||||||
Example of setting without keyword in value:
|
Example of setting without keyword in value:
|
||||||
```elixir
|
```elixir
|
||||||
config :tesla, :adapter, {Tesla.Adapter.Finch, name: MyFinch}
|
config :tesla, :adapter, Tesla.Adapter.Hackney
|
||||||
```
|
```
|
||||||
|
|
||||||
List of settings which support only full update by key:
|
List of settings which support only full update by key:
|
||||||
```elixir
|
```elixir
|
||||||
@full_key_update [
|
@full_key_update [
|
||||||
{:pleroma, :ecto_repos},
|
{:pleroma, :ecto_repos},
|
||||||
|
{:quack, :meta},
|
||||||
{:mime, :types},
|
{:mime, :types},
|
||||||
{:cors_plug, [:max_age, :methods, :expose, :headers]},
|
{:cors_plug, [:max_age, :methods, :expose, :headers]},
|
||||||
{:auto_linker, :opts},
|
{:auto_linker, :opts},
|
||||||
|
@ -1082,6 +1083,22 @@ List of settings which support only full update by subkey:
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
*Settings without explicit key must be sended in separate config object params.*
|
||||||
|
```elixir
|
||||||
|
config :quack,
|
||||||
|
level: :debug,
|
||||||
|
meta: [:all],
|
||||||
|
...
|
||||||
|
```
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"configs": [
|
||||||
|
{"group": ":quack", "key": ":level", "value": ":debug"},
|
||||||
|
{"group": ":quack", "key": ":meta", "value": [":all"]},
|
||||||
|
...
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
- Request:
|
- Request:
|
||||||
|
|
||||||
```json
|
```json
|
||||||
|
|
|
@ -84,12 +84,12 @@ doas adduser -S -s /bin/false -h /opt/akkoma -H -G akkoma akkoma
|
||||||
|
|
||||||
**Note**: To execute a single command as the Akkoma system user, use `doas -u akkoma command`. You can also switch to a shell by using `doas -su akkoma`. If you don’t have and want `doas` on your system, you can use `su` as root user (UID 0) for a single command by using `su -l akkoma -s $SHELL -c 'command'` and `su -l akkoma -s $SHELL` for starting a shell.
|
**Note**: To execute a single command as the Akkoma system user, use `doas -u akkoma command`. You can also switch to a shell by using `doas -su akkoma`. If you don’t have and want `doas` on your system, you can use `su` as root user (UID 0) for a single command by using `su -l akkoma -s $SHELL -c 'command'` and `su -l akkoma -s $SHELL` for starting a shell.
|
||||||
|
|
||||||
* Git clone the AkkomaBE repository from stable-branch and make the Akkoma user the owner of the directory:
|
* Git clone the AkkomaBE repository and make the Akkoma user the owner of the directory:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
doas mkdir -p /opt/akkoma
|
doas mkdir -p /opt/akkoma
|
||||||
doas chown -R akkoma:akkoma /opt/akkoma
|
doas chown -R akkoma:akkoma /opt/akkoma
|
||||||
doas -u akkoma git clone https://akkoma.dev/AkkomaGang/akkoma.git -b stable /opt/akkoma
|
doas -u akkoma git clone https://akkoma.dev/AkkomaGang/akkoma.git /opt/akkoma
|
||||||
```
|
```
|
||||||
|
|
||||||
* Change to the new directory:
|
* Change to the new directory:
|
||||||
|
@ -109,7 +109,7 @@ doas -u akkoma mix deps.get
|
||||||
* This may take some time, because parts of akkoma get compiled first.
|
* This may take some time, because parts of akkoma get compiled first.
|
||||||
* After that it will ask you a few questions about your instance and generates a configuration file in `config/generated_config.exs`.
|
* After that it will ask you a few questions about your instance and generates a configuration file in `config/generated_config.exs`.
|
||||||
|
|
||||||
* Check the configuration and if all looks right, rename it, so Akkoma will load it (`prod.secret.exs` for productive instances):
|
* Check the configuration and if all looks right, rename it, so Akkoma will load it (`prod.secret.exs` for productive instance, `dev.secret.exs` for development instances):
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
doas -u akkoma mv config/{generated_config.exs,prod.secret.exs}
|
doas -u akkoma mv config/{generated_config.exs,prod.secret.exs}
|
||||||
|
|
|
@ -75,12 +75,12 @@ sudo useradd -r -s /bin/false -m -d /var/lib/akkoma -U akkoma
|
||||||
|
|
||||||
**Note**: To execute a single command as the Akkoma system user, use `sudo -Hu akkoma command`. You can also switch to a shell by using `sudo -Hu akkoma $SHELL`. If you don’t have and want `sudo` on your system, you can use `su` as root user (UID 0) for a single command by using `su -l akkoma -s $SHELL -c 'command'` and `su -l akkoma -s $SHELL` for starting a shell.
|
**Note**: To execute a single command as the Akkoma system user, use `sudo -Hu akkoma command`. You can also switch to a shell by using `sudo -Hu akkoma $SHELL`. If you don’t have and want `sudo` on your system, you can use `su` as root user (UID 0) for a single command by using `su -l akkoma -s $SHELL -c 'command'` and `su -l akkoma -s $SHELL` for starting a shell.
|
||||||
|
|
||||||
* Git clone the AkkomaBE repository from stable-branch and make the Akkoma user the owner of the directory:
|
* Git clone the AkkomaBE repository and make the Akkoma user the owner of the directory:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
sudo mkdir -p /opt/akkoma
|
sudo mkdir -p /opt/akkoma
|
||||||
sudo chown -R akkoma:akkoma /opt/akkoma
|
sudo chown -R akkoma:akkoma /opt/akkoma
|
||||||
sudo -Hu akkoma git clone https://akkoma.dev/AkkomaGang/akkoma.git -b stable /opt/akkoma
|
sudo -Hu akkoma git clone https://akkoma.dev/AkkomaGang/akkoma.git /opt/akkoma
|
||||||
```
|
```
|
||||||
|
|
||||||
* Change to the new directory:
|
* Change to the new directory:
|
||||||
|
@ -100,7 +100,7 @@ sudo -Hu akkoma mix deps.get
|
||||||
* This may take some time, because parts of akkoma get compiled first.
|
* This may take some time, because parts of akkoma get compiled first.
|
||||||
* After that it will ask you a few questions about your instance and generates a configuration file in `config/generated_config.exs`.
|
* After that it will ask you a few questions about your instance and generates a configuration file in `config/generated_config.exs`.
|
||||||
|
|
||||||
* Check the configuration and if all looks right, rename it, so Akkoma will load it (`prod.secret.exs` for productive instances):
|
* Check the configuration and if all looks right, rename it, so Akkoma will load it (`prod.secret.exs` for productive instance, `dev.secret.exs` for development instances):
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
sudo -Hu akkoma mv config/{generated_config.exs,prod.secret.exs}
|
sudo -Hu akkoma mv config/{generated_config.exs,prod.secret.exs}
|
||||||
|
|
|
@ -49,12 +49,12 @@ sudo useradd -r -s /bin/false -m -d /var/lib/akkoma -U akkoma
|
||||||
|
|
||||||
**Note**: To execute a single command as the Akkoma system user, use `sudo -Hu akkoma command`. You can also switch to a shell by using `sudo -Hu akkoma $SHELL`. If you don’t have and want `sudo` on your system, you can use `su` as root user (UID 0) for a single command by using `su -l akkoma -s $SHELL -c 'command'` and `su -l akkoma -s $SHELL` for starting a shell.
|
**Note**: To execute a single command as the Akkoma system user, use `sudo -Hu akkoma command`. You can also switch to a shell by using `sudo -Hu akkoma $SHELL`. If you don’t have and want `sudo` on your system, you can use `su` as root user (UID 0) for a single command by using `su -l akkoma -s $SHELL -c 'command'` and `su -l akkoma -s $SHELL` for starting a shell.
|
||||||
|
|
||||||
* Git clone the AkkomaBE repository from stable-branch and make the Akkoma user the owner of the directory:
|
* Git clone the AkkomaBE repository and make the Akkoma user the owner of the directory:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
sudo mkdir -p /opt/akkoma
|
sudo mkdir -p /opt/akkoma
|
||||||
sudo chown -R akkoma:akkoma /opt/akkoma
|
sudo chown -R akkoma:akkoma /opt/akkoma
|
||||||
sudo -Hu akkoma git clone https://akkoma.dev/AkkomaGang/akkoma.git -b stable /opt/akkoma
|
sudo -Hu akkoma git clone https://akkoma.dev/AkkomaGang/akkoma.git /opt/akkoma
|
||||||
```
|
```
|
||||||
|
|
||||||
* Change to the new directory:
|
* Change to the new directory:
|
||||||
|
@ -74,7 +74,7 @@ sudo -Hu akkoma mix deps.get
|
||||||
* This may take some time, because parts of akkoma get compiled first.
|
* This may take some time, because parts of akkoma get compiled first.
|
||||||
* After that it will ask you a few questions about your instance and generates a configuration file in `config/generated_config.exs`.
|
* After that it will ask you a few questions about your instance and generates a configuration file in `config/generated_config.exs`.
|
||||||
|
|
||||||
* Check the configuration and if all looks right, rename it, so Akkoma will load it (`prod.secret.exs` for productive instances):
|
* Check the configuration and if all looks right, rename it, so Akkoma will load it (`prod.secret.exs` for productive instance, `dev.secret.exs` for development instances):
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
sudo -Hu akkoma mv config/{generated_config.exs,prod.secret.exs}
|
sudo -Hu akkoma mv config/{generated_config.exs,prod.secret.exs}
|
||||||
|
|
|
@ -30,10 +30,11 @@ sudo dnf install git gcc g++ make cmake file-devel postgresql-server postgresql-
|
||||||
|
|
||||||
* Enable and initialize Postgres:
|
* Enable and initialize Postgres:
|
||||||
```shell
|
```shell
|
||||||
|
sudo systemctl enable postgresql.service
|
||||||
sudo postgresql-setup --initdb --unit postgresql
|
sudo postgresql-setup --initdb --unit postgresql
|
||||||
# Allow password auth for postgres
|
# Allow password auth for postgres
|
||||||
sudo sed -E -i 's|(host +all +all +127.0.0.1/32 +)ident|\1md5|' /var/lib/pgsql/data/pg_hba.conf
|
sudo sed -E -i 's|(host +all +all +127.0.0.1/32 +)ident|\1md5|' /var/lib/pgsql/data/pg_hba.conf
|
||||||
sudo systemctl enable --now postgresql.service
|
sudo systemctl start postgresql.service
|
||||||
```
|
```
|
||||||
|
|
||||||
### Install Elixir and Erlang
|
### Install Elixir and Erlang
|
||||||
|
@ -58,7 +59,7 @@ sudo dnf install ffmpeg
|
||||||
* Install ImageMagick and ExifTool for image manipulation:
|
* Install ImageMagick and ExifTool for image manipulation:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
sudo dnf install ImageMagick perl-Image-ExifTool
|
sudo dnf install Imagemagick perl-Image-ExifTool
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,12 +74,12 @@ sudo useradd -r -s /bin/false -m -d /var/lib/akkoma -U akkoma
|
||||||
|
|
||||||
**Note**: To execute a single command as the Akkoma system user, use `sudo -Hu akkoma command`. You can also switch to a shell by using `sudo -Hu akkoma $SHELL`. If you don’t have and want `sudo` on your system, you can use `su` as root user (UID 0) for a single command by using `su -l akkoma -s $SHELL -c 'command'` and `su -l akkoma -s $SHELL` for starting a shell.
|
**Note**: To execute a single command as the Akkoma system user, use `sudo -Hu akkoma command`. You can also switch to a shell by using `sudo -Hu akkoma $SHELL`. If you don’t have and want `sudo` on your system, you can use `su` as root user (UID 0) for a single command by using `su -l akkoma -s $SHELL -c 'command'` and `su -l akkoma -s $SHELL` for starting a shell.
|
||||||
|
|
||||||
* Git clone the AkkomaBE repository from stable-branch and make the Akkoma user the owner of the directory:
|
* Git clone the AkkomaBE repository and make the Akkoma user the owner of the directory:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
sudo mkdir -p /opt/akkoma
|
sudo mkdir -p /opt/akkoma
|
||||||
sudo chown -R akkoma:akkoma /opt/akkoma
|
sudo chown -R akkoma:akkoma /opt/akkoma
|
||||||
sudo -Hu akkoma git clone https://akkoma.dev/AkkomaGang/akkoma.git -b stable /opt/akkoma
|
sudo -Hu akkoma git clone https://akkoma.dev/AkkomaGang/akkoma.git /opt/akkoma
|
||||||
```
|
```
|
||||||
|
|
||||||
* Change to the new directory:
|
* Change to the new directory:
|
||||||
|
@ -98,7 +99,7 @@ sudo -Hu akkoma mix deps.get
|
||||||
* This may take some time, because parts of akkoma get compiled first.
|
* This may take some time, because parts of akkoma get compiled first.
|
||||||
* After that it will ask you a few questions about your instance and generates a configuration file in `config/generated_config.exs`.
|
* After that it will ask you a few questions about your instance and generates a configuration file in `config/generated_config.exs`.
|
||||||
|
|
||||||
* Check the configuration and if all looks right, rename it, so Akkoma will load it (`prod.secret.exs` for productive instances):
|
* Check the configuration and if all looks right, rename it, so Akkoma will load it (`prod.secret.exs` for productive instance, `dev.secret.exs` for development instances):
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
sudo -Hu akkoma mv config/{generated_config.exs,prod.secret.exs}
|
sudo -Hu akkoma mv config/{generated_config.exs,prod.secret.exs}
|
||||||
|
|
|
@ -118,8 +118,8 @@ Restart PostgreSQL to apply configuration changes:
|
||||||
adduser --system --shell /bin/false --home /opt/akkoma akkoma
|
adduser --system --shell /bin/false --home /opt/akkoma akkoma
|
||||||
|
|
||||||
# Set the flavour environment variable to the string you got in Detecting flavour section.
|
# Set the flavour environment variable to the string you got in Detecting flavour section.
|
||||||
# For example if the flavour is `amd64` the command will be
|
# For example if the flavour is `amd64-musl` the command will be
|
||||||
export FLAVOUR="amd64"
|
export FLAVOUR="amd64-musl"
|
||||||
|
|
||||||
# Clone the release build into a temporary directory and unpack it
|
# Clone the release build into a temporary directory and unpack it
|
||||||
su akkoma -s $SHELL -lc "
|
su akkoma -s $SHELL -lc "
|
||||||
|
|
|
@ -37,7 +37,7 @@ sudo dnf install git gcc g++ erlang elixir erlang-os_mon erlang-eldap erlang-xme
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
cd ~
|
cd ~
|
||||||
git clone https://akkoma.dev/AkkomaGang/akkoma.git -b stable
|
git clone https://akkoma.dev/AkkomaGang/akkoma.git
|
||||||
```
|
```
|
||||||
|
|
||||||
* Change to the new directory:
|
* Change to the new directory:
|
||||||
|
|
|
@ -12,7 +12,7 @@ Release URLs will always be of the form
|
||||||
https://akkoma-updates.s3-website.fr-par.scw.cloud/{branch}/akkoma-{flavour}.zip
|
https://akkoma-updates.s3-website.fr-par.scw.cloud/{branch}/akkoma-{flavour}.zip
|
||||||
```
|
```
|
||||||
|
|
||||||
Where branch is usually `stable` and `flavour` is
|
Where branch is usually `stable` or `develop`, and `flavour` is
|
||||||
the one [that you detect on install](../otp_en/#detecting-flavour).
|
the one [that you detect on install](../otp_en/#detecting-flavour).
|
||||||
|
|
||||||
So, for an AMD64 stable install, your update URL will be
|
So, for an AMD64 stable install, your update URL will be
|
||||||
|
|
|
@ -12,21 +12,8 @@ theme:
|
||||||
- navigation.instant
|
- navigation.instant
|
||||||
- navigation.sections
|
- navigation.sections
|
||||||
palette:
|
palette:
|
||||||
- media: "(prefers-color-scheme: light)"
|
primary: 'deep purple'
|
||||||
scheme: default
|
accent: 'blue grey'
|
||||||
toggle:
|
|
||||||
icon: material/brightness-7
|
|
||||||
name: Switch to dark mode
|
|
||||||
primary: 'deep purple'
|
|
||||||
accent: 'blue grey'
|
|
||||||
|
|
||||||
- media: "(prefers-color-scheme: dark)"
|
|
||||||
scheme: slate
|
|
||||||
toggle:
|
|
||||||
icon: material/brightness-4
|
|
||||||
name: Switch to light mode
|
|
||||||
primary: 'deep purple'
|
|
||||||
accent: 'blue grey'
|
|
||||||
|
|
||||||
extra_css:
|
extra_css:
|
||||||
- css/extra.css
|
- css/extra.css
|
||||||
|
|
|
@ -4,6 +4,7 @@ After=network.target postgresql.service
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
ExecReload=/bin/kill $MAINPID
|
ExecReload=/bin/kill $MAINPID
|
||||||
|
KillMode=process
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
|
|
||||||
; Uncomment this if you're on Arch Linux
|
; Uncomment this if you're on Arch Linux
|
||||||
|
@ -14,9 +15,6 @@ User=akkoma
|
||||||
; Declares that Akkoma runs in production mode.
|
; Declares that Akkoma runs in production mode.
|
||||||
Environment="MIX_ENV=prod"
|
Environment="MIX_ENV=prod"
|
||||||
|
|
||||||
; Don't listen epmd on 0.0.0.0
|
|
||||||
Environment="ERL_EPMD_ADDRESS=127.0.0.1"
|
|
||||||
|
|
||||||
; Make sure that all paths fit your installation.
|
; Make sure that all paths fit your installation.
|
||||||
; Path to the home directory of the user running the Akkoma service.
|
; Path to the home directory of the user running the Akkoma service.
|
||||||
Environment="HOME=/var/lib/akkoma"
|
Environment="HOME=/var/lib/akkoma"
|
||||||
|
|
|
@ -12,8 +12,7 @@ environment =
|
||||||
HOME=/home/akkoma,
|
HOME=/home/akkoma,
|
||||||
USER=akkoma,
|
USER=akkoma,
|
||||||
PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/akkoma/bin:%(ENV_PATH)s",
|
PATH="/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/akkoma/bin:%(ENV_PATH)s",
|
||||||
PWD=/home/akkoma/akkoma,
|
PWD=/home/akkoma/akkoma
|
||||||
ERL_EPMD_ADDRESS=127.0.0.1
|
|
||||||
stdout_logfile=/home/akkoma/logs/stdout.log
|
stdout_logfile=/home/akkoma/logs/stdout.log
|
||||||
stdout_logfile_maxbytes=50MB
|
stdout_logfile_maxbytes=50MB
|
||||||
stdout_logfile_backups=10
|
stdout_logfile_backups=10
|
||||||
|
|
|
@ -18,8 +18,7 @@ load_rc_config ${name}
|
||||||
: ${akkoma_user:=akkoma}
|
: ${akkoma_user:=akkoma}
|
||||||
: ${akkoma_home:=$(getent passwd ${akkoma_user} | awk -F: '{print $6}')}
|
: ${akkoma_home:=$(getent passwd ${akkoma_user} | awk -F: '{print $6}')}
|
||||||
: ${akkoma_chdir:="${akkoma_home}/akkoma"}
|
: ${akkoma_chdir:="${akkoma_home}/akkoma"}
|
||||||
: ${akkoma_env:="HOME=${akkoma_home} MIX_ENV=prod ERL_EPMD_ADDRESS=127.0.0.1"}
|
: ${akkoma_env:="HOME=${akkoma_home} MIX_ENV=prod"}
|
||||||
|
|
||||||
|
|
||||||
command=/usr/local/bin/elixir
|
command=/usr/local/bin/elixir
|
||||||
command_args="--erl \"-detached\" -S /usr/local/bin/mix phx.server"
|
command_args="--erl \"-detached\" -S /usr/local/bin/mix phx.server"
|
||||||
|
|
|
@ -31,7 +31,6 @@ else
|
||||||
fi
|
fi
|
||||||
|
|
||||||
export MIX_ENV=prod
|
export MIX_ENV=prod
|
||||||
export ERL_EPMD_ADDRESS=127.0.0.1
|
|
||||||
|
|
||||||
depend() {
|
depend() {
|
||||||
need nginx postgresql
|
need nginx postgresql
|
||||||
|
|
|
@ -14,7 +14,7 @@ start_precmd="ulimit -n unlimited"
|
||||||
pidfile="/dev/null"
|
pidfile="/dev/null"
|
||||||
|
|
||||||
akkoma_chdir="${akkoma_home}/akkoma"
|
akkoma_chdir="${akkoma_home}/akkoma"
|
||||||
akkoma_env="HOME=${akkoma_home} MIX_ENV=prod ERL_EPMD_ADDRESS=127.0.0.1"
|
akkoma_env="HOME=${akkoma_home} MIX_ENV=prod"
|
||||||
|
|
||||||
check_pidfile()
|
check_pidfile()
|
||||||
{
|
{
|
||||||
|
|
|
@ -54,6 +54,8 @@ server {
|
||||||
ssl_protocols TLSv1.2 TLSv1.3;
|
ssl_protocols TLSv1.2 TLSv1.3;
|
||||||
ssl_ciphers "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
|
ssl_ciphers "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
|
||||||
ssl_prefer_server_ciphers off;
|
ssl_prefer_server_ciphers off;
|
||||||
|
# In case of an old server with an OpenSSL version of 1.0.2 or below,
|
||||||
|
# leave only prime256v1 or comment out the following line.
|
||||||
ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1;
|
ssl_ecdh_curve X25519:prime256v1:secp384r1:secp521r1;
|
||||||
ssl_stapling on;
|
ssl_stapling on;
|
||||||
ssl_stapling_verify on;
|
ssl_stapling_verify on;
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# credo:disable-for-this-file
|
|
||||||
# Pleroma: A lightweight social networking server
|
# Pleroma: A lightweight social networking server
|
||||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
|
@ -79,45 +79,6 @@ def run(["dump", group]) do
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(["dump_to_file", group, key, fname]) do
|
|
||||||
check_configdb(fn ->
|
|
||||||
start_pleroma()
|
|
||||||
|
|
||||||
group = maybe_atomize(group)
|
|
||||||
key = maybe_atomize(key)
|
|
||||||
|
|
||||||
config = ConfigDB.get_by_group_and_key(group, key)
|
|
||||||
|
|
||||||
json =
|
|
||||||
%{
|
|
||||||
group: ConfigDB.to_json_types(config.group),
|
|
||||||
key: ConfigDB.to_json_types(config.key),
|
|
||||||
value: ConfigDB.to_json_types(config.value)
|
|
||||||
}
|
|
||||||
|> Jason.encode!()
|
|
||||||
|> Jason.Formatter.pretty_print()
|
|
||||||
|
|
||||||
File.write(fname, json)
|
|
||||||
shell_info("Wrote #{group}_#{key}.json")
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
def run(["load_from_file", fname]) do
|
|
||||||
check_configdb(fn ->
|
|
||||||
start_pleroma()
|
|
||||||
|
|
||||||
json = File.read!(fname)
|
|
||||||
config = Jason.decode!(json)
|
|
||||||
group = ConfigDB.to_elixir_types(config["group"])
|
|
||||||
key = ConfigDB.to_elixir_types(config["key"])
|
|
||||||
value = ConfigDB.to_elixir_types(config["value"])
|
|
||||||
params = %{group: group, key: key, value: value}
|
|
||||||
|
|
||||||
ConfigDB.update_or_create(params)
|
|
||||||
shell_info("Loaded #{config["group"]}, #{config["key"]}")
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
def run(["groups"]) do
|
def run(["groups"]) do
|
||||||
check_configdb(fn ->
|
check_configdb(fn ->
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
|
|
@ -115,6 +115,7 @@ def run(["prune_task"]) do
|
||||||
|
|
||||||
nil
|
nil
|
||||||
|> Pleroma.Workers.Cron.PruneDatabaseWorker.perform()
|
|> Pleroma.Workers.Cron.PruneDatabaseWorker.perform()
|
||||||
|
|> IO.inspect()
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(["fix_likes_collections"]) do
|
def run(["fix_likes_collections"]) do
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# credo:disable-for-this-file
|
|
||||||
defmodule Mix.Tasks.Pleroma.Diagnostics do
|
defmodule Mix.Tasks.Pleroma.Diagnostics do
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
@ -10,13 +9,6 @@ defmodule Mix.Tasks.Pleroma.Diagnostics do
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
use Mix.Task
|
use Mix.Task
|
||||||
|
|
||||||
def run(["http", url]) do
|
|
||||||
start_pleroma()
|
|
||||||
|
|
||||||
Pleroma.HTTP.get(url)
|
|
||||||
|> IO.inspect()
|
|
||||||
end
|
|
||||||
|
|
||||||
def run(["home_timeline", nickname]) do
|
def run(["home_timeline", nickname]) do
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
user = Repo.get_by!(User, nickname: nickname)
|
user = Repo.get_by!(User, nickname: nickname)
|
||||||
|
|
|
@ -247,13 +247,9 @@ def run(["gen" | rest]) do
|
||||||
config_dir = Path.dirname(config_path)
|
config_dir = Path.dirname(config_path)
|
||||||
psql_dir = Path.dirname(psql_path)
|
psql_dir = Path.dirname(psql_path)
|
||||||
|
|
||||||
to_create =
|
[config_dir, psql_dir, static_dir, uploads_dir]
|
||||||
[config_dir, psql_dir, static_dir, uploads_dir]
|
|> Enum.reject(&File.exists?/1)
|
||||||
|> Enum.reject(&File.exists?/1)
|
|> Enum.map(&File.mkdir_p!/1)
|
||||||
|
|
||||||
for dir <- to_create do
|
|
||||||
File.mkdir_p!(dir)
|
|
||||||
end
|
|
||||||
|
|
||||||
shell_info("Writing config to #{config_path}.")
|
shell_info("Writing config to #{config_path}.")
|
||||||
|
|
||||||
|
@ -323,4 +319,6 @@ defp upload_filters(filters) when is_map(filters) do
|
||||||
|
|
||||||
enabled_filters
|
enabled_filters
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp upload_filters(_), do: []
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,11 +10,14 @@ defmodule Mix.Tasks.Pleroma.Search do
|
||||||
|
|
||||||
def run(["import", "activities" | _rest]) do
|
def run(["import", "activities" | _rest]) do
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
IO.inspect(Pleroma.Config.get([Pleroma.Search.Elasticsearch.Cluster, :indexes, :activities]))
|
||||||
|
|
||||||
Elasticsearch.Index.Bulk.upload(
|
IO.inspect(
|
||||||
Pleroma.Search.Elasticsearch.Cluster,
|
Elasticsearch.Index.Bulk.upload(
|
||||||
"activities",
|
Pleroma.Search.Elasticsearch.Cluster,
|
||||||
Pleroma.Config.get([Pleroma.Search.Elasticsearch.Cluster, :indexes, :activities])
|
"activities",
|
||||||
|
Pleroma.Config.get([Pleroma.Search.Elasticsearch.Cluster, :indexes, :activities])
|
||||||
|
)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -378,11 +378,9 @@ def run(["change_email", nickname, email]) do
|
||||||
def run(["show", nickname]) do
|
def run(["show", nickname]) do
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
|
||||||
user =
|
nickname
|
||||||
nickname
|
|> User.get_cached_by_nickname()
|
||||||
|> User.get_cached_by_nickname()
|
|> IO.inspect()
|
||||||
|
|
||||||
shell_info("#{inspect(user)}")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(["send_confirmation", nickname]) do
|
def run(["send_confirmation", nickname]) do
|
||||||
|
@ -391,6 +389,7 @@ def run(["send_confirmation", nickname]) do
|
||||||
with %User{} = user <- User.get_cached_by_nickname(nickname) do
|
with %User{} = user <- User.get_cached_by_nickname(nickname) do
|
||||||
user
|
user
|
||||||
|> Pleroma.Emails.UserEmail.account_confirmation_email()
|
|> Pleroma.Emails.UserEmail.account_confirmation_email()
|
||||||
|
|> IO.inspect()
|
||||||
|> Pleroma.Emails.Mailer.deliver!()
|
|> Pleroma.Emails.Mailer.deliver!()
|
||||||
|
|
||||||
shell_info("#{nickname}'s email sent")
|
shell_info("#{nickname}'s email sent")
|
||||||
|
@ -466,7 +465,7 @@ def run(["blocking", nickname]) do
|
||||||
|
|
||||||
with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
|
with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
|
||||||
blocks = User.following_ap_ids(user)
|
blocks = User.following_ap_ids(user)
|
||||||
IO.puts("#{inspect(blocks)}")
|
IO.inspect(blocks, limit: :infinity)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -38,11 +38,7 @@ defp add_cache_key_for(activity_id, additional_key) do
|
||||||
|
|
||||||
def invalidate_cache_for(activity_id) do
|
def invalidate_cache_for(activity_id) do
|
||||||
keys = get_cache_keys_for(activity_id)
|
keys = get_cache_keys_for(activity_id)
|
||||||
|
Enum.map(keys, &@cachex.del(:scrubber_cache, &1))
|
||||||
for key <- keys do
|
|
||||||
@cachex.del(:scrubber_cache, key)
|
|
||||||
end
|
|
||||||
|
|
||||||
@cachex.del(:scrubber_management_cache, activity_id)
|
@cachex.del(:scrubber_management_cache, activity_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,109 +0,0 @@
|
||||||
defmodule Pleroma.Akkoma.Translators.ArgosTranslate do
|
|
||||||
@behaviour Pleroma.Akkoma.Translator
|
|
||||||
|
|
||||||
alias Pleroma.Config
|
|
||||||
|
|
||||||
defp argos_translate do
|
|
||||||
Config.get([:argos_translate, :command_argos_translate])
|
|
||||||
end
|
|
||||||
|
|
||||||
defp argospm do
|
|
||||||
Config.get([:argos_translate, :command_argospm])
|
|
||||||
end
|
|
||||||
|
|
||||||
defp strip_html? do
|
|
||||||
Config.get([:argos_translate, :strip_html])
|
|
||||||
end
|
|
||||||
|
|
||||||
defp safe_languages() do
|
|
||||||
try do
|
|
||||||
System.cmd(argospm(), ["list"], stderr_to_stdout: true, parallelism: true)
|
|
||||||
rescue
|
|
||||||
_ -> {"Command #{argospm()} not found", 1}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
@impl Pleroma.Akkoma.Translator
|
|
||||||
def languages do
|
|
||||||
with {response, 0} <- safe_languages() do
|
|
||||||
langs =
|
|
||||||
response
|
|
||||||
|> String.split("\n", trim: true)
|
|
||||||
|> Enum.map(fn
|
|
||||||
"translate-" <> l -> String.split(l, "_")
|
|
||||||
end)
|
|
||||||
|
|
||||||
source_langs =
|
|
||||||
langs
|
|
||||||
|> Enum.map(fn [l, _] -> %{code: l, name: l} end)
|
|
||||||
|> Enum.uniq()
|
|
||||||
|
|
||||||
dest_langs =
|
|
||||||
langs
|
|
||||||
|> Enum.map(fn [_, l] -> %{code: l, name: l} end)
|
|
||||||
|> Enum.uniq()
|
|
||||||
|
|
||||||
{:ok, source_langs, dest_langs}
|
|
||||||
else
|
|
||||||
{response, _} -> {:error, "ArgosTranslate failed to fetch languages (#{response})"}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
defp safe_translate(string, from_language, to_language) do
|
|
||||||
try do
|
|
||||||
System.cmd(
|
|
||||||
argos_translate(),
|
|
||||||
["--from-lang", from_language, "--to-lang", to_language, string],
|
|
||||||
stderr_to_stdout: true,
|
|
||||||
parallelism: true
|
|
||||||
)
|
|
||||||
rescue
|
|
||||||
_ -> {"Command #{argos_translate()} not found", 1}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
defp clean_string(string, true) do
|
|
||||||
string
|
|
||||||
|> String.replace("<p>", "\n")
|
|
||||||
|> String.replace("</p>", "\n")
|
|
||||||
|> String.replace("<br>", "\n")
|
|
||||||
|> String.replace("<br/>", "\n")
|
|
||||||
|> String.replace("<li>", "\n")
|
|
||||||
|> Pleroma.HTML.strip_tags()
|
|
||||||
|> HtmlEntities.decode()
|
|
||||||
end
|
|
||||||
|
|
||||||
defp clean_string(string, _), do: string
|
|
||||||
|
|
||||||
defp htmlify_response(string, true) do
|
|
||||||
string
|
|
||||||
|> HtmlEntities.encode()
|
|
||||||
|> String.replace("\n", "<br/>")
|
|
||||||
end
|
|
||||||
|
|
||||||
defp htmlify_response(string, _), do: string
|
|
||||||
|
|
||||||
@impl Pleroma.Akkoma.Translator
|
|
||||||
def translate(string, nil, to_language) do
|
|
||||||
# Akkoma's Pleroma-fe expects us to detect the source language automatically.
|
|
||||||
# Argos-translate doesn't have that option (yet?)
|
|
||||||
# see <https://github.com/argosopentech/argos-translate/issues/9>
|
|
||||||
# For now we return the text unchanged, supposedly translated from the target language.
|
|
||||||
# Afterwards people get the option to overwrite the source language from a dropdown.
|
|
||||||
{:ok, to_language, string}
|
|
||||||
end
|
|
||||||
|
|
||||||
def translate(string, from_language, to_language) do
|
|
||||||
# Argos Translate doesn't properly translate HTML (yet?)
|
|
||||||
# For now we give admins the option to strip the html before translating
|
|
||||||
# Note that we have to add some html back to the response afterwards
|
|
||||||
string = clean_string(string, strip_html?())
|
|
||||||
|
|
||||||
with {translated, 0} <-
|
|
||||||
safe_translate(string, from_language, to_language) do
|
|
||||||
{:ok, from_language, translated |> htmlify_response(strip_html?())}
|
|
||||||
else
|
|
||||||
{response, _} -> {:error, "ArgosTranslate failed to translate (#{response})"}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -24,10 +24,8 @@ defmodule Pleroma.Announcement do
|
||||||
end
|
end
|
||||||
|
|
||||||
def change(struct, params \\ %{}) do
|
def change(struct, params \\ %{}) do
|
||||||
params = validate_params(struct, params)
|
|
||||||
|
|
||||||
struct
|
struct
|
||||||
|> cast(params, [:data, :starts_at, :ends_at, :rendered])
|
|> cast(validate_params(struct, params), [:data, :starts_at, :ends_at, :rendered])
|
||||||
|> validate_required([:data])
|
|> validate_required([:data])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -73,8 +73,7 @@ def start(_type, _args) do
|
||||||
Pleroma.JobQueueMonitor,
|
Pleroma.JobQueueMonitor,
|
||||||
{Majic.Pool, [name: Pleroma.MajicPool, pool_size: Config.get([:majic_pool, :size], 2)]},
|
{Majic.Pool, [name: Pleroma.MajicPool, pool_size: Config.get([:majic_pool, :size], 2)]},
|
||||||
{Oban, Config.get(Oban)},
|
{Oban, Config.get(Oban)},
|
||||||
Pleroma.Web.Endpoint,
|
Pleroma.Web.Endpoint
|
||||||
Pleroma.Web.Telemetry
|
|
||||||
] ++
|
] ++
|
||||||
elasticsearch_children() ++
|
elasticsearch_children() ++
|
||||||
task_children(@mix_env) ++
|
task_children(@mix_env) ++
|
||||||
|
@ -159,8 +158,7 @@ defp cachex_children do
|
||||||
build_cachex("banned_urls", default_ttl: :timer.hours(24 * 30), limit: 5_000),
|
build_cachex("banned_urls", default_ttl: :timer.hours(24 * 30), limit: 5_000),
|
||||||
build_cachex("translations", default_ttl: :timer.hours(24 * 30), limit: 2500),
|
build_cachex("translations", default_ttl: :timer.hours(24 * 30), limit: 2500),
|
||||||
build_cachex("instances", default_ttl: :timer.hours(24), ttl_interval: 1000, limit: 2500),
|
build_cachex("instances", default_ttl: :timer.hours(24), ttl_interval: 1000, limit: 2500),
|
||||||
build_cachex("request_signatures", default_ttl: :timer.hours(24 * 30), limit: 3000),
|
build_cachex("request_signatures", default_ttl: :timer.hours(24 * 30), limit: 3000)
|
||||||
build_cachex("rel_me", default_ttl: :timer.hours(24 * 30), limit: 300)
|
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -200,8 +198,6 @@ defp background_migrators do
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec task_children(atom()) :: [map()]
|
|
||||||
|
|
||||||
defp task_children(:test) do
|
defp task_children(:test) do
|
||||||
[
|
[
|
||||||
%{
|
%{
|
||||||
|
@ -227,7 +223,6 @@ defp task_children(_) do
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec elasticsearch_children :: [Pleroma.Search.Elasticsearch.Cluster]
|
|
||||||
def elasticsearch_children do
|
def elasticsearch_children do
|
||||||
config = Config.get([Pleroma.Search, :module])
|
config = Config.get([Pleroma.Search, :module])
|
||||||
|
|
||||||
|
@ -260,12 +255,10 @@ def limiters_setup do
|
||||||
defp http_children do
|
defp http_children do
|
||||||
proxy_url = Config.get([:http, :proxy_url])
|
proxy_url = Config.get([:http, :proxy_url])
|
||||||
proxy = Pleroma.HTTP.AdapterHelper.format_proxy(proxy_url)
|
proxy = Pleroma.HTTP.AdapterHelper.format_proxy(proxy_url)
|
||||||
pool_size = Config.get([:http, :pool_size])
|
|
||||||
|
|
||||||
config =
|
config =
|
||||||
[:http, :adapter]
|
[:http, :adapter]
|
||||||
|> Config.get([])
|
|> Config.get([])
|
||||||
|> Pleroma.HTTP.AdapterHelper.add_pool_size(pool_size)
|
|
||||||
|> Pleroma.HTTP.AdapterHelper.maybe_add_proxy_pool(proxy)
|
|> Pleroma.HTTP.AdapterHelper.maybe_add_proxy_pool(proxy)
|
||||||
|> Keyword.put(:name, MyFinch)
|
|> Keyword.put(:name, MyFinch)
|
||||||
|
|
||||||
|
|
|
@ -194,6 +194,8 @@ defp check_system_commands!(:ok) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp check_system_commands!(result), do: result
|
||||||
|
|
||||||
defp check_repo_pool_size!(:ok) do
|
defp check_repo_pool_size!(:ok) do
|
||||||
if Pleroma.Config.get([Pleroma.Repo, :pool_size], 10) != 10 and
|
if Pleroma.Config.get([Pleroma.Repo, :pool_size], 10) != 10 and
|
||||||
not Pleroma.Config.get([:dangerzone, :override_repo_pool_size], false) do
|
not Pleroma.Config.get([:dangerzone, :override_repo_pool_size], false) do
|
||||||
|
|
|
@ -181,8 +181,7 @@ def warn do
|
||||||
check_uploders_s3_public_endpoint(),
|
check_uploders_s3_public_endpoint(),
|
||||||
check_quarantined_instances_tuples(),
|
check_quarantined_instances_tuples(),
|
||||||
check_transparency_exclusions_tuples(),
|
check_transparency_exclusions_tuples(),
|
||||||
check_simple_policy_tuples(),
|
check_simple_policy_tuples()
|
||||||
check_http_adapter()
|
|
||||||
]
|
]
|
||||||
|> Enum.reduce(:ok, fn
|
|> Enum.reduce(:ok, fn
|
||||||
:ok, :ok -> :ok
|
:ok, :ok -> :ok
|
||||||
|
@ -211,32 +210,6 @@ def check_welcome_message_config do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_http_adapter do
|
|
||||||
http_adapter = Application.get_env(:tesla, :adapter)
|
|
||||||
|
|
||||||
case http_adapter do
|
|
||||||
{Tesla.Adapter.Finch, _} ->
|
|
||||||
:ok
|
|
||||||
|
|
||||||
Tesla.Mock ->
|
|
||||||
# tests do be testing
|
|
||||||
:ok
|
|
||||||
|
|
||||||
_anything_else ->
|
|
||||||
Logger.error("""
|
|
||||||
!!!CONFIG ERROR!!!
|
|
||||||
Your config is using a custom tesla adapter, this was standardised
|
|
||||||
to finch in 2022.06, and alternate adapters were removed in 2023.02.
|
|
||||||
Please ensure you either:
|
|
||||||
\n* do not have any custom value for `:tesla, :adapter`, or
|
|
||||||
\n* have `config :tesla, :adapter, {Tesla.Adapter.Finch, name: MyFinch}`
|
|
||||||
(your current value is #{inspect(http_adapter)})
|
|
||||||
""")
|
|
||||||
|
|
||||||
:error
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def check_old_mrf_config do
|
def check_old_mrf_config do
|
||||||
warning_preface = """
|
warning_preface = """
|
||||||
!!!DEPRECATION WARNING!!!
|
!!!DEPRECATION WARNING!!!
|
||||||
|
|
|
@ -25,9 +25,7 @@ defp reboot_time_subkeys,
|
||||||
do: [
|
do: [
|
||||||
{:pleroma, Pleroma.Captcha, [:seconds_valid]},
|
{:pleroma, Pleroma.Captcha, [:seconds_valid]},
|
||||||
{:pleroma, Pleroma.Upload, [:proxy_remote]},
|
{:pleroma, Pleroma.Upload, [:proxy_remote]},
|
||||||
{:pleroma, :instance, [:upload_limit]},
|
{:pleroma, :instance, [:upload_limit]}
|
||||||
{:pleroma, :http, [:pool_size]},
|
|
||||||
{:pleroma, :http, [:proxy_url]}
|
|
||||||
]
|
]
|
||||||
|
|
||||||
def start_link(restart_pleroma? \\ true) do
|
def start_link(restart_pleroma? \\ true) do
|
||||||
|
@ -42,9 +40,8 @@ def load_and_update_env(deleted_settings \\ [], restart_pleroma? \\ true) do
|
||||||
# We need to restart applications for loaded settings take effect
|
# We need to restart applications for loaded settings take effect
|
||||||
{logger, other} =
|
{logger, other} =
|
||||||
(Repo.all(ConfigDB) ++ deleted_settings)
|
(Repo.all(ConfigDB) ++ deleted_settings)
|
||||||
|> Enum.reject(&invalid_key_or_group/1)
|
|
||||||
|> Enum.map(&merge_with_default/1)
|
|> Enum.map(&merge_with_default/1)
|
||||||
|> Enum.split_with(fn {group, _, _, _} -> group == :logger end)
|
|> Enum.split_with(fn {group, _, _, _} -> group in [:logger, :quack] end)
|
||||||
|
|
||||||
logger
|
logger
|
||||||
|> Enum.sort()
|
|> Enum.sort()
|
||||||
|
@ -86,10 +83,6 @@ defp maybe_set_pleroma_last(apps) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp invalid_key_or_group(%ConfigDB{key: :invalid_atom}), do: true
|
|
||||||
defp invalid_key_or_group(%ConfigDB{group: :invalid_atom}), do: true
|
|
||||||
defp invalid_key_or_group(_), do: false
|
|
||||||
|
|
||||||
defp merge_with_default(%{group: group, key: key, value: value} = setting) do
|
defp merge_with_default(%{group: group, key: key, value: value} = setting) do
|
||||||
default =
|
default =
|
||||||
if group == :pleroma do
|
if group == :pleroma do
|
||||||
|
@ -108,6 +101,12 @@ defp merge_with_default(%{group: group, key: key, value: value} = setting) do
|
||||||
{group, key, value, merged}
|
{group, key, value, merged}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# change logger configuration in runtime, without restart
|
||||||
|
defp configure({:quack, key, _, merged}) do
|
||||||
|
Logger.configure_backend(Quack.Logger, [{key, merged}])
|
||||||
|
:ok = update_env(:quack, key, merged)
|
||||||
|
end
|
||||||
|
|
||||||
defp configure({_, :backends, _, merged}) do
|
defp configure({_, :backends, _, merged}) do
|
||||||
# removing current backends
|
# removing current backends
|
||||||
Enum.each(Application.get_env(:logger, :backends), &Logger.remove_backend/1)
|
Enum.each(Application.get_env(:logger, :backends), &Logger.remove_backend/1)
|
||||||
|
|
|
@ -163,6 +163,7 @@ defp can_be_partially_updated?(%ConfigDB{} = config), do: not only_full_update?(
|
||||||
defp only_full_update?(%ConfigDB{group: group, key: key}) do
|
defp only_full_update?(%ConfigDB{group: group, key: key}) do
|
||||||
full_key_update = [
|
full_key_update = [
|
||||||
{:pleroma, :ecto_repos},
|
{:pleroma, :ecto_repos},
|
||||||
|
{:quack, :meta},
|
||||||
{:mime, :types},
|
{:mime, :types},
|
||||||
{:cors_plug, [:max_age, :methods, :expose, :headers]},
|
{:cors_plug, [:max_age, :methods, :expose, :headers]},
|
||||||
{:swarm, :node_blacklist},
|
{:swarm, :node_blacklist},
|
||||||
|
@ -342,11 +343,7 @@ def string_to_elixir_types(":" <> atom), do: String.to_atom(atom)
|
||||||
|
|
||||||
def string_to_elixir_types(value) do
|
def string_to_elixir_types(value) do
|
||||||
if module_name?(value) do
|
if module_name?(value) do
|
||||||
try do
|
String.to_existing_atom("Elixir." <> value)
|
||||||
String.to_existing_atom("Elixir." <> value)
|
|
||||||
rescue
|
|
||||||
ArgumentError -> :invalid_atom
|
|
||||||
end
|
|
||||||
else
|
else
|
||||||
value
|
value
|
||||||
end
|
end
|
||||||
|
|
|
@ -35,6 +35,11 @@ def perform(:deliver_async, email, config), do: deliver(email, config)
|
||||||
def deliver(email, config \\ [])
|
def deliver(email, config \\ [])
|
||||||
|
|
||||||
def deliver(email, config) do
|
def deliver(email, config) do
|
||||||
|
# temporary hackney fix until hackney max_connections bug is fixed
|
||||||
|
# https://git.pleroma.social/pleroma/pleroma/-/issues/2101
|
||||||
|
email =
|
||||||
|
Swoosh.Email.put_private(email, :hackney_options, ssl_options: [versions: [:"tlsv1.2"]])
|
||||||
|
|
||||||
case enabled?() do
|
case enabled?() do
|
||||||
true -> Swoosh.Mailer.deliver(email, parse_config(config))
|
true -> Swoosh.Mailer.deliver(email, parse_config(config))
|
||||||
false -> {:error, :deliveries_disabled}
|
false -> {:error, :deliveries_disabled}
|
||||||
|
|
|
@ -209,9 +209,7 @@ def list_remote(opts) do
|
||||||
|
|
||||||
with :ok <- validate_shareable_packs_available(uri) do
|
with :ok <- validate_shareable_packs_available(uri) do
|
||||||
uri
|
uri
|
||||||
|> URI.merge(
|
|> URI.merge("/api/pleroma/emoji/packs?page=#{opts[:page]}&page_size=#{opts[:page_size]}")
|
||||||
"/api/v1/pleroma/emoji/packs?page=#{opts[:page]}&page_size=#{opts[:page_size]}"
|
|
||||||
)
|
|
||||||
|> http_get()
|
|> http_get()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -252,7 +250,7 @@ def download(name, url, as) do
|
||||||
|
|
||||||
with :ok <- validate_shareable_packs_available(uri),
|
with :ok <- validate_shareable_packs_available(uri),
|
||||||
{:ok, remote_pack} <-
|
{:ok, remote_pack} <-
|
||||||
uri |> URI.merge("/api/v1/pleroma/emoji/pack?name=#{name}") |> http_get(),
|
uri |> URI.merge("/api/pleroma/emoji/pack?name=#{name}") |> http_get(),
|
||||||
{:ok, %{sha: sha, url: url} = pack_info} <- fetch_pack_info(remote_pack, uri, name),
|
{:ok, %{sha: sha, url: url} = pack_info} <- fetch_pack_info(remote_pack, uri, name),
|
||||||
{:ok, archive} <- download_archive(url, sha),
|
{:ok, archive} <- download_archive(url, sha),
|
||||||
pack <- copy_as(remote_pack, as || name),
|
pack <- copy_as(remote_pack, as || name),
|
||||||
|
@ -593,7 +591,7 @@ defp fetch_pack_info(remote_pack, uri, name) do
|
||||||
{:ok,
|
{:ok,
|
||||||
%{
|
%{
|
||||||
sha: sha,
|
sha: sha,
|
||||||
url: URI.merge(uri, "/api/v1/pleroma/emoji/packs/archive?name=#{name}") |> to_string()
|
url: URI.merge(uri, "/api/pleroma/emoji/packs/archive?name=#{name}") |> to_string()
|
||||||
}}
|
}}
|
||||||
|
|
||||||
%{"fallback-src" => src, "fallback-src-sha256" => sha} when is_binary(src) ->
|
%{"fallback-src" => src, "fallback-src-sha256" => sha} when is_binary(src) ->
|
||||||
|
|
|
@ -14,8 +14,6 @@ defmodule Pleroma.FollowingRelationship do
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
|
||||||
@type follow_state :: :follow_pending | :follow_accept | :follow_reject | :unfollow
|
|
||||||
|
|
||||||
schema "following_relationships" do
|
schema "following_relationships" do
|
||||||
field(:state, State, default: :follow_pending)
|
field(:state, State, default: :follow_pending)
|
||||||
|
|
||||||
|
@ -74,7 +72,6 @@ def update(%User{} = follower, %User{} = following, state) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec follow(User.t(), User.t()) :: {:ok, User.t(), User.t()} | {:error, any}
|
|
||||||
def follow(%User{} = follower, %User{} = following, state \\ :follow_accept) do
|
def follow(%User{} = follower, %User{} = following, state \\ :follow_accept) do
|
||||||
with {:ok, _following_relationship} <-
|
with {:ok, _following_relationship} <-
|
||||||
%__MODULE__{}
|
%__MODULE__{}
|
||||||
|
@ -84,7 +81,6 @@ def follow(%User{} = follower, %User{} = following, state \\ :follow_accept) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec unfollow(User.t(), User.t()) :: {:ok, User.t(), User.t()} | {:error, any}
|
|
||||||
def unfollow(%User{} = follower, %User{} = following) do
|
def unfollow(%User{} = follower, %User{} = following) do
|
||||||
case get(follower, following) do
|
case get(follower, following) do
|
||||||
%__MODULE__{} = following_relationship ->
|
%__MODULE__{} = following_relationship ->
|
||||||
|
@ -93,12 +89,10 @@ def unfollow(%User{} = follower, %User{} = following) do
|
||||||
end
|
end
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
{:ok, follower, following}
|
{:ok, nil}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec after_update(follow_state(), User.t(), User.t()) ::
|
|
||||||
{:ok, User.t(), User.t()} | {:error, any()}
|
|
||||||
defp after_update(state, %User{} = follower, %User{} = following) do
|
defp after_update(state, %User{} = follower, %User{} = following) do
|
||||||
with {:ok, following} <- User.update_follower_count(following),
|
with {:ok, following} <- User.update_follower_count(following),
|
||||||
{:ok, follower} <- User.update_following_count(follower) do
|
{:ok, follower} <- User.update_following_count(follower) do
|
||||||
|
@ -109,8 +103,6 @@ defp after_update(state, %User{} = follower, %User{} = following) do
|
||||||
})
|
})
|
||||||
|
|
||||||
{:ok, follower, following}
|
{:ok, follower, following}
|
||||||
else
|
|
||||||
err -> {:error, err}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@ defp download_build(frontend_info, dest) do
|
||||||
url = String.replace(frontend_info["build_url"], "${ref}", frontend_info["ref"])
|
url = String.replace(frontend_info["build_url"], "${ref}", frontend_info["ref"])
|
||||||
|
|
||||||
with {:ok, %{status: 200, body: zip_body}} <-
|
with {:ok, %{status: 200, body: zip_body}} <-
|
||||||
Pleroma.HTTP.get(url, [], receive_timeout: 120_000) do
|
Pleroma.HTTP.get(url, [], recv_timeout: 120_000) do
|
||||||
unzip(zip_body, dest)
|
unzip(zip_body, dest)
|
||||||
else
|
else
|
||||||
{:error, e} -> {:error, e}
|
{:error, e} -> {:error, e}
|
||||||
|
|
29
lib/pleroma/gun.ex
Normal file
29
lib/pleroma/gun.ex
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Gun do
|
||||||
|
@callback open(charlist(), pos_integer(), map()) :: {:ok, pid()}
|
||||||
|
@callback info(pid()) :: map()
|
||||||
|
@callback close(pid()) :: :ok
|
||||||
|
@callback await_up(pid, pos_integer()) :: {:ok, atom()} | {:error, atom()}
|
||||||
|
@callback connect(pid(), map()) :: reference()
|
||||||
|
@callback await(pid(), reference()) :: {:response, :fin, 200, []}
|
||||||
|
@callback set_owner(pid(), pid()) :: :ok
|
||||||
|
|
||||||
|
defp api, do: Pleroma.Config.get([Pleroma.Gun], Pleroma.Gun.API)
|
||||||
|
|
||||||
|
def open(host, port, opts), do: api().open(host, port, opts)
|
||||||
|
|
||||||
|
def info(pid), do: api().info(pid)
|
||||||
|
|
||||||
|
def close(pid), do: api().close(pid)
|
||||||
|
|
||||||
|
def await_up(pid, timeout \\ 5_000), do: api().await_up(pid, timeout)
|
||||||
|
|
||||||
|
def connect(pid, opts), do: api().connect(pid, opts)
|
||||||
|
|
||||||
|
def await(pid, ref), do: api().await(pid, ref)
|
||||||
|
|
||||||
|
def set_owner(pid, owner), do: api().set_owner(pid, owner)
|
||||||
|
end
|
46
lib/pleroma/gun/api.ex
Normal file
46
lib/pleroma/gun/api.ex
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Gun.API do
|
||||||
|
@behaviour Pleroma.Gun
|
||||||
|
|
||||||
|
alias Pleroma.Gun
|
||||||
|
|
||||||
|
@gun_keys [
|
||||||
|
:connect_timeout,
|
||||||
|
:http_opts,
|
||||||
|
:http2_opts,
|
||||||
|
:protocols,
|
||||||
|
:retry,
|
||||||
|
:retry_timeout,
|
||||||
|
:trace,
|
||||||
|
:transport,
|
||||||
|
:tls_opts,
|
||||||
|
:tcp_opts,
|
||||||
|
:socks_opts,
|
||||||
|
:ws_opts,
|
||||||
|
:supervise
|
||||||
|
]
|
||||||
|
|
||||||
|
@impl Gun
|
||||||
|
def open(host, port, opts \\ %{}), do: :gun.open(host, port, Map.take(opts, @gun_keys))
|
||||||
|
|
||||||
|
@impl Gun
|
||||||
|
defdelegate info(pid), to: :gun
|
||||||
|
|
||||||
|
@impl Gun
|
||||||
|
defdelegate close(pid), to: :gun
|
||||||
|
|
||||||
|
@impl Gun
|
||||||
|
defdelegate await_up(pid, timeout \\ 5_000), to: :gun
|
||||||
|
|
||||||
|
@impl Gun
|
||||||
|
defdelegate connect(pid, opts), to: :gun
|
||||||
|
|
||||||
|
@impl Gun
|
||||||
|
defdelegate await(pid, ref), to: :gun
|
||||||
|
|
||||||
|
@impl Gun
|
||||||
|
defdelegate set_owner(pid, owner), to: :gun
|
||||||
|
end
|
131
lib/pleroma/gun/conn.ex
Normal file
131
lib/pleroma/gun/conn.ex
Normal file
|
@ -0,0 +1,131 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Gun.Conn do
|
||||||
|
alias Pleroma.Gun
|
||||||
|
|
||||||
|
require Logger
|
||||||
|
|
||||||
|
def open(%URI{} = uri, opts) do
|
||||||
|
pool_opts = Pleroma.Config.get([:connections_pool], [])
|
||||||
|
|
||||||
|
opts =
|
||||||
|
opts
|
||||||
|
|> Enum.into(%{})
|
||||||
|
|> Map.put_new(:connect_timeout, pool_opts[:connect_timeout] || 5_000)
|
||||||
|
|> Map.put_new(:supervise, false)
|
||||||
|
|> maybe_add_tls_opts(uri)
|
||||||
|
|
||||||
|
do_open(uri, opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp maybe_add_tls_opts(opts, %URI{scheme: "http"}), do: opts
|
||||||
|
|
||||||
|
defp maybe_add_tls_opts(opts, %URI{scheme: "https"}) do
|
||||||
|
tls_opts = [
|
||||||
|
verify: :verify_peer,
|
||||||
|
cacertfile: CAStore.file_path(),
|
||||||
|
depth: 20,
|
||||||
|
reuse_sessions: false,
|
||||||
|
log_level: :warning,
|
||||||
|
customize_hostname_check: [match_fun: :public_key.pkix_verify_hostname_match_fun(:https)]
|
||||||
|
]
|
||||||
|
|
||||||
|
tls_opts =
|
||||||
|
if Keyword.keyword?(opts[:tls_opts]) do
|
||||||
|
Keyword.merge(tls_opts, opts[:tls_opts])
|
||||||
|
else
|
||||||
|
tls_opts
|
||||||
|
end
|
||||||
|
|
||||||
|
Map.put(opts, :tls_opts, tls_opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
defp do_open(uri, %{proxy: {proxy_host, proxy_port}} = opts) do
|
||||||
|
connect_opts =
|
||||||
|
uri
|
||||||
|
|> destination_opts()
|
||||||
|
|> add_http2_opts(uri.scheme, Map.get(opts, :tls_opts, []))
|
||||||
|
|
||||||
|
with open_opts <- Map.delete(opts, :tls_opts),
|
||||||
|
{:ok, conn} <- Gun.open(proxy_host, proxy_port, open_opts),
|
||||||
|
{:ok, protocol} <- Gun.await_up(conn, opts[:connect_timeout]),
|
||||||
|
stream <- Gun.connect(conn, connect_opts),
|
||||||
|
{:response, :fin, 200, _} <- Gun.await(conn, stream) do
|
||||||
|
{:ok, conn, protocol}
|
||||||
|
else
|
||||||
|
error ->
|
||||||
|
Logger.warn(
|
||||||
|
"Opening proxied connection to #{compose_uri_log(uri)} failed with error #{inspect(error)}"
|
||||||
|
)
|
||||||
|
|
||||||
|
error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp do_open(uri, %{proxy: {proxy_type, proxy_host, proxy_port}} = opts) do
|
||||||
|
version =
|
||||||
|
proxy_type
|
||||||
|
|> to_string()
|
||||||
|
|> String.last()
|
||||||
|
|> case do
|
||||||
|
"4" -> 4
|
||||||
|
_ -> 5
|
||||||
|
end
|
||||||
|
|
||||||
|
socks_opts =
|
||||||
|
uri
|
||||||
|
|> destination_opts()
|
||||||
|
|> add_http2_opts(uri.scheme, Map.get(opts, :tls_opts, []))
|
||||||
|
|> Map.put(:version, version)
|
||||||
|
|
||||||
|
opts =
|
||||||
|
opts
|
||||||
|
|> Map.put(:protocols, [:socks])
|
||||||
|
|> Map.put(:socks_opts, socks_opts)
|
||||||
|
|
||||||
|
with {:ok, conn} <- Gun.open(proxy_host, proxy_port, opts),
|
||||||
|
{:ok, protocol} <- Gun.await_up(conn, opts[:connect_timeout]) do
|
||||||
|
{:ok, conn, protocol}
|
||||||
|
else
|
||||||
|
error ->
|
||||||
|
Logger.warn(
|
||||||
|
"Opening socks proxied connection to #{compose_uri_log(uri)} failed with error #{inspect(error)}"
|
||||||
|
)
|
||||||
|
|
||||||
|
error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp do_open(%URI{host: host, port: port} = uri, opts) do
|
||||||
|
host = Pleroma.HTTP.AdapterHelper.parse_host(host)
|
||||||
|
|
||||||
|
with {:ok, conn} <- Gun.open(host, port, opts),
|
||||||
|
{:ok, protocol} <- Gun.await_up(conn, opts[:connect_timeout]) do
|
||||||
|
{:ok, conn, protocol}
|
||||||
|
else
|
||||||
|
error ->
|
||||||
|
Logger.warn(
|
||||||
|
"Opening connection to #{compose_uri_log(uri)} failed with error #{inspect(error)}"
|
||||||
|
)
|
||||||
|
|
||||||
|
error
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp destination_opts(%URI{host: host, port: port}) do
|
||||||
|
host = Pleroma.HTTP.AdapterHelper.parse_host(host)
|
||||||
|
%{host: host, port: port}
|
||||||
|
end
|
||||||
|
|
||||||
|
defp add_http2_opts(opts, "https", tls_opts) do
|
||||||
|
Map.merge(opts, %{protocols: [:http2], transport: :tls, tls_opts: tls_opts})
|
||||||
|
end
|
||||||
|
|
||||||
|
defp add_http2_opts(opts, _, _), do: opts
|
||||||
|
|
||||||
|
def compose_uri_log(%URI{scheme: scheme, host: host, path: path}) do
|
||||||
|
"#{scheme}://#{host}#{path}"
|
||||||
|
end
|
||||||
|
end
|
86
lib/pleroma/gun/connection_pool.ex
Normal file
86
lib/pleroma/gun/connection_pool.ex
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Gun.ConnectionPool do
|
||||||
|
@registry __MODULE__
|
||||||
|
|
||||||
|
alias Pleroma.Gun.ConnectionPool.WorkerSupervisor
|
||||||
|
|
||||||
|
def children do
|
||||||
|
[
|
||||||
|
{Registry, keys: :unique, name: @registry},
|
||||||
|
Pleroma.Gun.ConnectionPool.WorkerSupervisor
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec get_conn(URI.t(), keyword()) :: {:ok, pid()} | {:error, term()}
|
||||||
|
def get_conn(uri, opts) do
|
||||||
|
key = "#{uri.scheme}:#{uri.host}:#{uri.port}"
|
||||||
|
|
||||||
|
case Registry.lookup(@registry, key) do
|
||||||
|
# The key has already been registered, but connection is not up yet
|
||||||
|
[{worker_pid, nil}] ->
|
||||||
|
get_gun_pid_from_worker(worker_pid, true)
|
||||||
|
|
||||||
|
[{worker_pid, {gun_pid, _used_by, _crf, _last_reference}}] ->
|
||||||
|
GenServer.call(worker_pid, :add_client)
|
||||||
|
{:ok, gun_pid}
|
||||||
|
|
||||||
|
[] ->
|
||||||
|
# :gun.set_owner fails in :connected state for whatevever reason,
|
||||||
|
# so we open the connection in the process directly and send it's pid back
|
||||||
|
# We trust gun to handle timeouts by itself
|
||||||
|
case WorkerSupervisor.start_worker([key, uri, opts, self()]) do
|
||||||
|
{:ok, worker_pid} ->
|
||||||
|
get_gun_pid_from_worker(worker_pid, false)
|
||||||
|
|
||||||
|
{:error, {:already_started, worker_pid}} ->
|
||||||
|
get_gun_pid_from_worker(worker_pid, true)
|
||||||
|
|
||||||
|
err ->
|
||||||
|
err
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp get_gun_pid_from_worker(worker_pid, register) do
|
||||||
|
# GenServer.call will block the process for timeout length if
|
||||||
|
# the server crashes on startup (which will happen if gun fails to connect)
|
||||||
|
# so instead we use cast + monitor
|
||||||
|
|
||||||
|
ref = Process.monitor(worker_pid)
|
||||||
|
if register, do: GenServer.cast(worker_pid, {:add_client, self()})
|
||||||
|
|
||||||
|
receive do
|
||||||
|
{:conn_pid, pid} ->
|
||||||
|
Process.demonitor(ref)
|
||||||
|
{:ok, pid}
|
||||||
|
|
||||||
|
{:DOWN, ^ref, :process, ^worker_pid, reason} ->
|
||||||
|
case reason do
|
||||||
|
{:shutdown, {:error, _} = error} -> error
|
||||||
|
{:shutdown, error} -> {:error, error}
|
||||||
|
_ -> {:error, reason}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@spec release_conn(pid()) :: :ok
|
||||||
|
def release_conn(conn_pid) do
|
||||||
|
# :ets.fun2ms(fn {_, {worker_pid, {gun_pid, _, _, _}}} when gun_pid == conn_pid ->
|
||||||
|
# worker_pid end)
|
||||||
|
query_result =
|
||||||
|
Registry.select(@registry, [
|
||||||
|
{{:_, :"$1", {:"$2", :_, :_, :_}}, [{:==, :"$2", conn_pid}], [:"$1"]}
|
||||||
|
])
|
||||||
|
|
||||||
|
case query_result do
|
||||||
|
[worker_pid] ->
|
||||||
|
GenServer.call(worker_pid, :remove_client)
|
||||||
|
|
||||||
|
[] ->
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
89
lib/pleroma/gun/connection_pool/reclaimer.ex
Normal file
89
lib/pleroma/gun/connection_pool/reclaimer.ex
Normal file
|
@ -0,0 +1,89 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Gun.ConnectionPool.Reclaimer do
|
||||||
|
use GenServer, restart: :temporary
|
||||||
|
|
||||||
|
defp registry, do: Pleroma.Gun.ConnectionPool
|
||||||
|
|
||||||
|
def start_monitor do
|
||||||
|
pid =
|
||||||
|
case :gen_server.start(__MODULE__, [], name: {:via, Registry, {registry(), "reclaimer"}}) do
|
||||||
|
{:ok, pid} ->
|
||||||
|
pid
|
||||||
|
|
||||||
|
{:error, {:already_registered, pid}} ->
|
||||||
|
pid
|
||||||
|
end
|
||||||
|
|
||||||
|
{pid, Process.monitor(pid)}
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def init(_) do
|
||||||
|
{:ok, nil, {:continue, :reclaim}}
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def handle_continue(:reclaim, _) do
|
||||||
|
max_connections = Pleroma.Config.get([:connections_pool, :max_connections])
|
||||||
|
|
||||||
|
reclaim_max =
|
||||||
|
[:connections_pool, :reclaim_multiplier]
|
||||||
|
|> Pleroma.Config.get()
|
||||||
|
|> Kernel.*(max_connections)
|
||||||
|
|> round
|
||||||
|
|> max(1)
|
||||||
|
|
||||||
|
:telemetry.execute([:pleroma, :connection_pool, :reclaim, :start], %{}, %{
|
||||||
|
max_connections: max_connections,
|
||||||
|
reclaim_max: reclaim_max
|
||||||
|
})
|
||||||
|
|
||||||
|
# :ets.fun2ms(
|
||||||
|
# fn {_, {worker_pid, {_, used_by, crf, last_reference}}} when used_by == [] ->
|
||||||
|
# {worker_pid, crf, last_reference} end)
|
||||||
|
unused_conns =
|
||||||
|
Registry.select(
|
||||||
|
registry(),
|
||||||
|
[
|
||||||
|
{{:_, :"$1", {:_, :"$2", :"$3", :"$4"}}, [{:==, :"$2", []}], [{{:"$1", :"$3", :"$4"}}]}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
case unused_conns do
|
||||||
|
[] ->
|
||||||
|
:telemetry.execute(
|
||||||
|
[:pleroma, :connection_pool, :reclaim, :stop],
|
||||||
|
%{reclaimed_count: 0},
|
||||||
|
%{
|
||||||
|
max_connections: max_connections
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
{:stop, :no_unused_conns, nil}
|
||||||
|
|
||||||
|
unused_conns ->
|
||||||
|
reclaimed =
|
||||||
|
unused_conns
|
||||||
|
|> Enum.sort(fn {_pid1, crf1, last_reference1}, {_pid2, crf2, last_reference2} ->
|
||||||
|
crf1 <= crf2 and last_reference1 <= last_reference2
|
||||||
|
end)
|
||||||
|
|> Enum.take(reclaim_max)
|
||||||
|
|
||||||
|
reclaimed
|
||||||
|
|> Enum.each(fn {pid, _, _} ->
|
||||||
|
DynamicSupervisor.terminate_child(Pleroma.Gun.ConnectionPool.WorkerSupervisor, pid)
|
||||||
|
end)
|
||||||
|
|
||||||
|
:telemetry.execute(
|
||||||
|
[:pleroma, :connection_pool, :reclaim, :stop],
|
||||||
|
%{reclaimed_count: Enum.count(reclaimed)},
|
||||||
|
%{max_connections: max_connections}
|
||||||
|
)
|
||||||
|
|
||||||
|
{:stop, :normal, nil}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
153
lib/pleroma/gun/connection_pool/worker.ex
Normal file
153
lib/pleroma/gun/connection_pool/worker.ex
Normal file
|
@ -0,0 +1,153 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Gun.ConnectionPool.Worker do
|
||||||
|
alias Pleroma.Gun
|
||||||
|
use GenServer, restart: :temporary
|
||||||
|
|
||||||
|
defp registry, do: Pleroma.Gun.ConnectionPool
|
||||||
|
|
||||||
|
def start_link([key | _] = opts) do
|
||||||
|
GenServer.start_link(__MODULE__, opts, name: {:via, Registry, {registry(), key}})
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def init([_key, _uri, _opts, _client_pid] = opts) do
|
||||||
|
{:ok, nil, {:continue, {:connect, opts}}}
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def handle_continue({:connect, [key, uri, opts, client_pid]}, _) do
|
||||||
|
with {:ok, conn_pid, protocol} <- Gun.Conn.open(uri, opts),
|
||||||
|
Process.link(conn_pid) do
|
||||||
|
time = :erlang.monotonic_time(:millisecond)
|
||||||
|
|
||||||
|
{_, _} =
|
||||||
|
Registry.update_value(registry(), key, fn _ ->
|
||||||
|
{conn_pid, [client_pid], 1, time}
|
||||||
|
end)
|
||||||
|
|
||||||
|
send(client_pid, {:conn_pid, conn_pid})
|
||||||
|
|
||||||
|
{:noreply,
|
||||||
|
%{
|
||||||
|
key: key,
|
||||||
|
timer: nil,
|
||||||
|
client_monitors: %{client_pid => Process.monitor(client_pid)},
|
||||||
|
protocol: protocol
|
||||||
|
}, :hibernate}
|
||||||
|
else
|
||||||
|
err ->
|
||||||
|
{:stop, {:shutdown, err}, nil}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def handle_cast({:add_client, client_pid}, state) do
|
||||||
|
case handle_call(:add_client, {client_pid, nil}, state) do
|
||||||
|
{:reply, conn_pid, state, :hibernate} ->
|
||||||
|
send(client_pid, {:conn_pid, conn_pid})
|
||||||
|
{:noreply, state, :hibernate}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def handle_cast({:remove_client, client_pid}, state) do
|
||||||
|
case handle_call(:remove_client, {client_pid, nil}, state) do
|
||||||
|
{:reply, _, state, :hibernate} ->
|
||||||
|
{:noreply, state, :hibernate}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def handle_call(:add_client, {client_pid, _}, %{key: key, protocol: protocol} = state) do
|
||||||
|
time = :erlang.monotonic_time(:millisecond)
|
||||||
|
|
||||||
|
{{conn_pid, used_by, _, _}, _} =
|
||||||
|
Registry.update_value(registry(), key, fn {conn_pid, used_by, crf, last_reference} ->
|
||||||
|
{conn_pid, [client_pid | used_by], crf(time - last_reference, crf), time}
|
||||||
|
end)
|
||||||
|
|
||||||
|
:telemetry.execute(
|
||||||
|
[:pleroma, :connection_pool, :client, :add],
|
||||||
|
%{client_pid: client_pid, clients: used_by},
|
||||||
|
%{key: state.key, protocol: protocol}
|
||||||
|
)
|
||||||
|
|
||||||
|
state =
|
||||||
|
if state.timer != nil do
|
||||||
|
Process.cancel_timer(state[:timer])
|
||||||
|
%{state | timer: nil}
|
||||||
|
else
|
||||||
|
state
|
||||||
|
end
|
||||||
|
|
||||||
|
ref = Process.monitor(client_pid)
|
||||||
|
|
||||||
|
state = put_in(state.client_monitors[client_pid], ref)
|
||||||
|
{:reply, conn_pid, state, :hibernate}
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def handle_call(:remove_client, {client_pid, _}, %{key: key} = state) do
|
||||||
|
{{_conn_pid, used_by, _crf, _last_reference}, _} =
|
||||||
|
Registry.update_value(registry(), key, fn {conn_pid, used_by, crf, last_reference} ->
|
||||||
|
{conn_pid, List.delete(used_by, client_pid), crf, last_reference}
|
||||||
|
end)
|
||||||
|
|
||||||
|
{ref, state} = pop_in(state.client_monitors[client_pid])
|
||||||
|
|
||||||
|
Process.demonitor(ref, [:flush])
|
||||||
|
|
||||||
|
timer =
|
||||||
|
if used_by == [] do
|
||||||
|
max_idle = Pleroma.Config.get([:connections_pool, :max_idle_time], 30_000)
|
||||||
|
Process.send_after(self(), :idle_close, max_idle)
|
||||||
|
else
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
{:reply, :ok, %{state | timer: timer}, :hibernate}
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def handle_info(:idle_close, state) do
|
||||||
|
# Gun monitors the owner process, and will close the connection automatically
|
||||||
|
# when it's terminated
|
||||||
|
{:stop, :normal, state}
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def handle_info({:gun_up, _pid, _protocol}, state) do
|
||||||
|
{:noreply, state, :hibernate}
|
||||||
|
end
|
||||||
|
|
||||||
|
# Gracefully shutdown if the connection got closed without any streams left
|
||||||
|
@impl true
|
||||||
|
def handle_info({:gun_down, _pid, _protocol, _reason, []}, state) do
|
||||||
|
{:stop, :normal, state}
|
||||||
|
end
|
||||||
|
|
||||||
|
# Otherwise, wait for retry
|
||||||
|
@impl true
|
||||||
|
def handle_info({:gun_down, _pid, _protocol, _reason, _killed_streams}, state) do
|
||||||
|
{:noreply, state, :hibernate}
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def handle_info({:DOWN, _ref, :process, pid, reason}, state) do
|
||||||
|
:telemetry.execute(
|
||||||
|
[:pleroma, :connection_pool, :client, :dead],
|
||||||
|
%{client_pid: pid, reason: reason},
|
||||||
|
%{key: state.key}
|
||||||
|
)
|
||||||
|
|
||||||
|
handle_cast({:remove_client, pid}, state)
|
||||||
|
end
|
||||||
|
|
||||||
|
# LRFU policy: https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.55.1478
|
||||||
|
defp crf(time_delta, prev_crf) do
|
||||||
|
1 + :math.pow(0.5, 0.0001 * time_delta) * prev_crf
|
||||||
|
end
|
||||||
|
end
|
49
lib/pleroma/gun/connection_pool/worker_supervisor.ex
Normal file
49
lib/pleroma/gun/connection_pool/worker_supervisor.ex
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Gun.ConnectionPool.WorkerSupervisor do
|
||||||
|
@moduledoc "Supervisor for pool workers. Does not do anything except enforce max connection limit"
|
||||||
|
|
||||||
|
use DynamicSupervisor
|
||||||
|
|
||||||
|
def start_link(opts) do
|
||||||
|
DynamicSupervisor.start_link(__MODULE__, opts, name: __MODULE__)
|
||||||
|
end
|
||||||
|
|
||||||
|
def init(_opts) do
|
||||||
|
DynamicSupervisor.init(
|
||||||
|
strategy: :one_for_one,
|
||||||
|
max_children: Pleroma.Config.get([:connections_pool, :max_connections])
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
def start_worker(opts, retry \\ false) do
|
||||||
|
case DynamicSupervisor.start_child(__MODULE__, {Pleroma.Gun.ConnectionPool.Worker, opts}) do
|
||||||
|
{:error, :max_children} ->
|
||||||
|
if retry or free_pool() == :error do
|
||||||
|
:telemetry.execute([:pleroma, :connection_pool, :provision_failure], %{opts: opts})
|
||||||
|
{:error, :pool_full}
|
||||||
|
else
|
||||||
|
start_worker(opts, true)
|
||||||
|
end
|
||||||
|
|
||||||
|
res ->
|
||||||
|
res
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp free_pool do
|
||||||
|
wait_for_reclaimer_finish(Pleroma.Gun.ConnectionPool.Reclaimer.start_monitor())
|
||||||
|
end
|
||||||
|
|
||||||
|
defp wait_for_reclaimer_finish({pid, mon}) do
|
||||||
|
receive do
|
||||||
|
{:DOWN, ^mon, :process, ^pid, :no_unused_conns} ->
|
||||||
|
:error
|
||||||
|
|
||||||
|
{:DOWN, ^mon, :process, ^pid, :normal} ->
|
||||||
|
:ok
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -104,10 +104,10 @@ defp run_fifo(fifo_path, env, executable, args) do
|
||||||
args: args
|
args: args
|
||||||
])
|
])
|
||||||
|
|
||||||
fifo = File.open!(fifo_path, [:append, :binary])
|
fifo = Port.open(to_charlist(fifo_path), [:eof, :binary, :stream, :out])
|
||||||
fix = Pleroma.Helpers.QtFastStart.fix(env.body)
|
fix = Pleroma.Helpers.QtFastStart.fix(env.body)
|
||||||
IO.binwrite(fifo, fix)
|
true = Port.command(fifo, fix)
|
||||||
File.close(fifo)
|
:erlang.port_close(fifo)
|
||||||
loop_recv(pid)
|
loop_recv(pid)
|
||||||
after
|
after
|
||||||
File.rm(fifo_path)
|
File.rm(fifo_path)
|
||||||
|
|
|
@ -65,7 +65,7 @@ def request(method, url, body, headers, options) when is_binary(url) do
|
||||||
options = put_in(options[:adapter], adapter_opts)
|
options = put_in(options[:adapter], adapter_opts)
|
||||||
params = options[:params] || []
|
params = options[:params] || []
|
||||||
request = build_request(method, headers, options, url, body, params)
|
request = build_request(method, headers, options, url, body, params)
|
||||||
client = Tesla.client([Tesla.Middleware.FollowRedirects, Tesla.Middleware.Telemetry])
|
client = Tesla.client([Tesla.Middleware.FollowRedirects])
|
||||||
|
|
||||||
request(client, request)
|
request(client, request)
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,7 +14,9 @@ defmodule Pleroma.HTTP.AdapterHelper do
|
||||||
alias Pleroma.HTTP.AdapterHelper
|
alias Pleroma.HTTP.AdapterHelper
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
@type proxy :: {Connection.proxy_type(), Connection.host(), pos_integer(), list()}
|
@type proxy ::
|
||||||
|
{Connection.host(), pos_integer()}
|
||||||
|
| {Connection.proxy_type(), Connection.host(), pos_integer()}
|
||||||
|
|
||||||
@callback options(keyword(), URI.t()) :: keyword()
|
@callback options(keyword(), URI.t()) :: keyword()
|
||||||
|
|
||||||
|
@ -23,6 +25,7 @@ def format_proxy(nil), do: nil
|
||||||
|
|
||||||
def format_proxy(proxy_url) do
|
def format_proxy(proxy_url) do
|
||||||
case parse_proxy(proxy_url) do
|
case parse_proxy(proxy_url) do
|
||||||
|
{:ok, host, port} -> {:http, host, port, []}
|
||||||
{:ok, type, host, port} -> {type, host, port, []}
|
{:ok, type, host, port} -> {type, host, port, []}
|
||||||
_ -> nil
|
_ -> nil
|
||||||
end
|
end
|
||||||
|
@ -47,13 +50,6 @@ def maybe_add_proxy_pool(opts, proxy) do
|
||||||
|> put_in([:pools, :default, :conn_opts, :proxy], proxy)
|
|> put_in([:pools, :default, :conn_opts, :proxy], proxy)
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_pool_size(opts, pool_size) do
|
|
||||||
opts
|
|
||||||
|> maybe_add_pools()
|
|
||||||
|> maybe_add_default_pool()
|
|
||||||
|> put_in([:pools, :default, :size], pool_size)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp maybe_add_pools(opts) do
|
defp maybe_add_pools(opts) do
|
||||||
if Keyword.has_key?(opts, :pools) do
|
if Keyword.has_key?(opts, :pools) do
|
||||||
opts
|
opts
|
||||||
|
@ -98,7 +94,8 @@ defp proxy_type("https"), do: {:ok, :https}
|
||||||
defp proxy_type(_), do: {:error, :unknown}
|
defp proxy_type(_), do: {:error, :unknown}
|
||||||
|
|
||||||
@spec parse_proxy(String.t() | tuple() | nil) ::
|
@spec parse_proxy(String.t() | tuple() | nil) ::
|
||||||
{:ok, proxy_type(), host(), pos_integer()}
|
{:ok, host(), pos_integer()}
|
||||||
|
| {:ok, proxy_type(), host(), pos_integer()}
|
||||||
| {:error, atom()}
|
| {:error, atom()}
|
||||||
| nil
|
| nil
|
||||||
def parse_proxy(nil), do: nil
|
def parse_proxy(nil), do: nil
|
||||||
|
|
|
@ -14,7 +14,7 @@ defmodule Pleroma.Migrators.Support.BaseMigrator do
|
||||||
@callback fault_rate_allowance() :: integer() | float()
|
@callback fault_rate_allowance() :: integer() | float()
|
||||||
|
|
||||||
defmacro __using__(_opts) do
|
defmacro __using__(_opts) do
|
||||||
quote generated: true do
|
quote do
|
||||||
use GenServer
|
use GenServer
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
|
@ -237,8 +237,7 @@ def insert_log(%{actor: %User{}, action: action, target: target} = attrs)
|
||||||
insert_log_entry_with_message(%ModerationLog{data: data})
|
insert_log_entry_with_message(%ModerationLog{data: data})
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec insert_log_entry_with_message(ModerationLog.t()) ::
|
@spec insert_log_entry_with_message(ModerationLog) :: {:ok, ModerationLog} | {:error, any}
|
||||||
{:ok, ModerationLog.t()} | {:error, any}
|
|
||||||
defp insert_log_entry_with_message(entry) do
|
defp insert_log_entry_with_message(entry) do
|
||||||
entry.data["message"]
|
entry.data["message"]
|
||||||
|> put_in(get_log_entry_message(entry))
|
|> put_in(get_log_entry_message(entry))
|
||||||
|
|
|
@ -240,7 +240,7 @@ def delete(%Object{data: %{"id" => id}} = object) do
|
||||||
{:ok, _} <- invalid_object_cache(object) do
|
{:ok, _} <- invalid_object_cache(object) do
|
||||||
cleanup_attachments(
|
cleanup_attachments(
|
||||||
Config.get([:instance, :cleanup_attachments]),
|
Config.get([:instance, :cleanup_attachments]),
|
||||||
%{object: object}
|
%{"object" => object}
|
||||||
)
|
)
|
||||||
|
|
||||||
{:ok, object, deleted_activity}
|
{:ok, object, deleted_activity}
|
||||||
|
@ -249,7 +249,7 @@ def delete(%Object{data: %{"id" => id}} = object) do
|
||||||
|
|
||||||
@spec cleanup_attachments(boolean(), %{required(:object) => map()}) ::
|
@spec cleanup_attachments(boolean(), %{required(:object) => map()}) ::
|
||||||
{:ok, Oban.Job.t() | nil}
|
{:ok, Oban.Job.t() | nil}
|
||||||
def cleanup_attachments(true, %{object: _} = params) do
|
def cleanup_attachments(true, %{"object" => _} = params) do
|
||||||
AttachmentsCleanupWorker.enqueue("cleanup_attachments", params)
|
AttachmentsCleanupWorker.enqueue("cleanup_attachments", params)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -262,7 +262,7 @@ def fetch_and_contain_remote_object_from_id(id) when is_binary(id) do
|
||||||
def fetch_and_contain_remote_object_from_id(_id),
|
def fetch_and_contain_remote_object_from_id(_id),
|
||||||
do: {:error, "id must be a string"}
|
do: {:error, "id must be a string"}
|
||||||
|
|
||||||
def get_object(id) do
|
defp get_object(id) do
|
||||||
date = Pleroma.Signature.signed_date()
|
date = Pleroma.Signature.signed_date()
|
||||||
|
|
||||||
headers =
|
headers =
|
||||||
|
@ -282,11 +282,6 @@ def get_object(id) do
|
||||||
%{"profile" => "https://www.w3.org/ns/activitystreams"}} ->
|
%{"profile" => "https://www.w3.org/ns/activitystreams"}} ->
|
||||||
{:ok, body}
|
{:ok, body}
|
||||||
|
|
||||||
# pixelfed sometimes (and only sometimes) responds with http instead of https
|
|
||||||
{:ok, "application", "ld+json",
|
|
||||||
%{"profile" => "http://www.w3.org/ns/activitystreams"}} ->
|
|
||||||
{:ok, body}
|
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
{:error, {:content_type, content_type}}
|
{:error, {:content_type, content_type}}
|
||||||
end
|
end
|
||||||
|
|
|
@ -88,9 +88,9 @@ def paginate(query, options, :offset, table_binding) do
|
||||||
|
|
||||||
defp cast_params(params) do
|
defp cast_params(params) do
|
||||||
param_types = %{
|
param_types = %{
|
||||||
min_id: params[:id_type] || :string,
|
min_id: :string,
|
||||||
since_id: params[:id_type] || :string,
|
since_id: :string,
|
||||||
max_id: params[:id_type] || :string,
|
max_id: :string,
|
||||||
offset: :integer,
|
offset: :integer,
|
||||||
limit: :integer,
|
limit: :integer,
|
||||||
skip_extra_order: :boolean,
|
skip_extra_order: :boolean,
|
||||||
|
|
|
@ -1,55 +0,0 @@
|
||||||
defmodule Pleroma.Password do
|
|
||||||
@moduledoc """
|
|
||||||
This module handles password hashing and verification.
|
|
||||||
It will delegate to the appropriate module based on the password hash.
|
|
||||||
It also handles upgrading of password hashes.
|
|
||||||
"""
|
|
||||||
|
|
||||||
alias Pleroma.User
|
|
||||||
alias Pleroma.Password.Pbkdf2
|
|
||||||
require Logger
|
|
||||||
|
|
||||||
@hashing_module Argon2
|
|
||||||
|
|
||||||
@spec hash_pwd_salt(String.t()) :: String.t()
|
|
||||||
defdelegate hash_pwd_salt(pass), to: @hashing_module
|
|
||||||
|
|
||||||
@spec checkpw(String.t(), String.t()) :: boolean()
|
|
||||||
def checkpw(password, "$2" <> _ = password_hash) do
|
|
||||||
# Handle bcrypt passwords for Mastodon migration
|
|
||||||
Bcrypt.verify_pass(password, password_hash)
|
|
||||||
end
|
|
||||||
|
|
||||||
def checkpw(password, "$pbkdf2" <> _ = password_hash) do
|
|
||||||
Pbkdf2.verify_pass(password, password_hash)
|
|
||||||
end
|
|
||||||
|
|
||||||
def checkpw(password, "$argon2" <> _ = password_hash) do
|
|
||||||
Argon2.verify_pass(password, password_hash)
|
|
||||||
end
|
|
||||||
|
|
||||||
def checkpw(_password, _password_hash) do
|
|
||||||
Logger.error("Password hash not recognized")
|
|
||||||
false
|
|
||||||
end
|
|
||||||
|
|
||||||
@spec maybe_update_password(User.t(), String.t()) ::
|
|
||||||
{:ok, User.t()} | {:error, Ecto.Changeset.t()}
|
|
||||||
def maybe_update_password(%User{password_hash: "$2" <> _} = user, password) do
|
|
||||||
do_update_password(user, password)
|
|
||||||
end
|
|
||||||
|
|
||||||
def maybe_update_password(%User{password_hash: "$6" <> _} = user, password) do
|
|
||||||
do_update_password(user, password)
|
|
||||||
end
|
|
||||||
|
|
||||||
def maybe_update_password(%User{password_hash: "$pbkdf2" <> _} = user, password) do
|
|
||||||
do_update_password(user, password)
|
|
||||||
end
|
|
||||||
|
|
||||||
def maybe_update_password(user, _), do: {:ok, user}
|
|
||||||
|
|
||||||
defp do_update_password(user, password) do
|
|
||||||
User.reset_password(user, %{password: password, password_confirmation: password})
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -1,49 +0,0 @@
|
||||||
defmodule Pleroma.PrometheusExporter do
|
|
||||||
@moduledoc """
|
|
||||||
Exports metrics in Prometheus format.
|
|
||||||
Mostly exists because of https://github.com/beam-telemetry/telemetry_metrics_prometheus_core/issues/52
|
|
||||||
Basically we need to fetch metrics every so often, or the lib will let them pile up and eventually crash the VM.
|
|
||||||
It also sorta acts as a cache so there is that too.
|
|
||||||
"""
|
|
||||||
|
|
||||||
use GenServer
|
|
||||||
require Logger
|
|
||||||
|
|
||||||
def start_link(_opts) do
|
|
||||||
GenServer.start_link(__MODULE__, :ok, name: __MODULE__)
|
|
||||||
end
|
|
||||||
|
|
||||||
def init(_opts) do
|
|
||||||
schedule_next()
|
|
||||||
{:ok, ""}
|
|
||||||
end
|
|
||||||
|
|
||||||
defp schedule_next do
|
|
||||||
Process.send_after(self(), :gather, 60_000)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Scheduled function, gather metrics and schedule next run
|
|
||||||
def handle_info(:gather, _state) do
|
|
||||||
schedule_next()
|
|
||||||
state = TelemetryMetricsPrometheus.Core.scrape()
|
|
||||||
{:noreply, state}
|
|
||||||
end
|
|
||||||
|
|
||||||
# Trigger the call dynamically, mostly for testing
|
|
||||||
def handle_call(:gather, _from, _state) do
|
|
||||||
state = TelemetryMetricsPrometheus.Core.scrape()
|
|
||||||
{:reply, state, state}
|
|
||||||
end
|
|
||||||
|
|
||||||
def handle_call(:show, _from, state) do
|
|
||||||
{:reply, state, state}
|
|
||||||
end
|
|
||||||
|
|
||||||
def show do
|
|
||||||
GenServer.call(__MODULE__, :show)
|
|
||||||
end
|
|
||||||
|
|
||||||
def gather do
|
|
||||||
GenServer.call(__MODULE__, :gather)
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -61,6 +61,9 @@ def create do
|
||||||
IO.puts("The database for #{inspect(@repo)} has already been created")
|
IO.puts("The database for #{inspect(@repo)} has already been created")
|
||||||
|
|
||||||
{:error, term} when is_binary(term) ->
|
{:error, term} when is_binary(term) ->
|
||||||
|
IO.puts(:stderr, "The database for #{inspect(@repo)} couldn't be created: #{term}")
|
||||||
|
|
||||||
|
{:error, term} ->
|
||||||
IO.puts(
|
IO.puts(
|
||||||
:stderr,
|
:stderr,
|
||||||
"The database for #{inspect(@repo)} couldn't be created: #{inspect(term)}"
|
"The database for #{inspect(@repo)} couldn't be created: #{inspect(term)}"
|
||||||
|
|
25
lib/pleroma/reverse_proxy/client/hackney.ex
Normal file
25
lib/pleroma/reverse_proxy/client/hackney.ex
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.ReverseProxy.Client.Hackney do
|
||||||
|
@behaviour Pleroma.ReverseProxy.Client
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def request(method, url, headers, body, opts \\ []) do
|
||||||
|
opts = Keyword.put(opts, :ssl_options, versions: [:"tlsv1.2", :"tlsv1.1", :tlsv1])
|
||||||
|
:hackney.request(method, url, headers, body, opts)
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def stream_body(ref) do
|
||||||
|
case :hackney.stream_body(ref) do
|
||||||
|
:done -> :done
|
||||||
|
{:ok, data} -> {:ok, data, ref}
|
||||||
|
{:error, error} -> {:error, error}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@impl true
|
||||||
|
def close(ref), do: :hackney.close(ref)
|
||||||
|
end
|
|
@ -5,6 +5,8 @@
|
||||||
defmodule Pleroma.ReverseProxy.Client.Tesla do
|
defmodule Pleroma.ReverseProxy.Client.Tesla do
|
||||||
@behaviour Pleroma.ReverseProxy.Client
|
@behaviour Pleroma.ReverseProxy.Client
|
||||||
|
|
||||||
|
alias Pleroma.Gun.ConnectionPool
|
||||||
|
|
||||||
@type headers() :: [{String.t(), String.t()}]
|
@type headers() :: [{String.t(), String.t()}]
|
||||||
@type status() :: pos_integer()
|
@type status() :: pos_integer()
|
||||||
|
|
||||||
|
@ -31,6 +33,8 @@ def request(method, url, headers, body, opts \\ []) do
|
||||||
if is_map(response.body) and method != :head do
|
if is_map(response.body) and method != :head do
|
||||||
{:ok, response.status, response.headers, response.body}
|
{:ok, response.status, response.headers, response.body}
|
||||||
else
|
else
|
||||||
|
conn_pid = response.opts[:adapter][:conn]
|
||||||
|
ConnectionPool.release_conn(conn_pid)
|
||||||
{:ok, response.status, response.headers}
|
{:ok, response.status, response.headers}
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
@ -41,7 +45,8 @@ def request(method, url, headers, body, opts \\ []) do
|
||||||
@impl true
|
@impl true
|
||||||
@spec stream_body(map()) ::
|
@spec stream_body(map()) ::
|
||||||
{:ok, binary(), map()} | {:error, atom() | String.t()} | :done | no_return()
|
{:ok, binary(), map()} | {:error, atom() | String.t()} | :done | no_return()
|
||||||
def stream_body(%{pid: _pid, fin: true}) do
|
def stream_body(%{pid: pid, fin: true}) do
|
||||||
|
ConnectionPool.release_conn(pid)
|
||||||
:done
|
:done
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -65,13 +70,17 @@ defp read_chunk!(%{pid: pid, stream: stream, opts: opts}) do
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
@spec close(map) :: :ok | no_return()
|
@spec close(map) :: :ok | no_return()
|
||||||
def close(%{pid: _pid}) do
|
def close(%{pid: pid}) do
|
||||||
:ok
|
ConnectionPool.release_conn(pid)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp check_adapter do
|
defp check_adapter do
|
||||||
adapter = Application.get_env(:tesla, :adapter)
|
adapter = Application.get_env(:tesla, :adapter)
|
||||||
|
|
||||||
|
unless adapter == Tesla.Adapter.Gun do
|
||||||
|
raise "#{adapter} doesn't support reading body in chunks"
|
||||||
|
end
|
||||||
|
|
||||||
adapter
|
adapter
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,6 +23,8 @@ defp client do
|
||||||
|> client()
|
|> client()
|
||||||
end
|
end
|
||||||
|
|
||||||
defp client({Tesla.Adapter.Finch, _}), do: Pleroma.ReverseProxy.Client.Tesla
|
defp client(Tesla.Adapter.Hackney), do: Pleroma.ReverseProxy.Client.Hackney
|
||||||
|
defp client(Tesla.Adapter.Gun), do: Pleroma.ReverseProxy.Client.Tesla
|
||||||
|
defp client({Tesla.Adapter.Finch, _}), do: Pleroma.ReverseProxy.Client.Hackney
|
||||||
defp client(_), do: Pleroma.Config.get!(Pleroma.ReverseProxy.Client)
|
defp client(_), do: Pleroma.Config.get!(Pleroma.ReverseProxy.Client)
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,21 +13,25 @@ defmodule Pleroma.Search.Elasticsearch do
|
||||||
def es_query(:activity, query, offset, limit) do
|
def es_query(:activity, query, offset, limit) do
|
||||||
must = Parsers.Activity.parse(query)
|
must = Parsers.Activity.parse(query)
|
||||||
|
|
||||||
%{
|
if must == [] do
|
||||||
size: limit,
|
:skip
|
||||||
from: offset,
|
else
|
||||||
terminate_after: 50,
|
%{
|
||||||
timeout: "5s",
|
size: limit,
|
||||||
sort: [
|
from: offset,
|
||||||
"_score",
|
terminate_after: 50,
|
||||||
%{"_timestamp" => %{order: "desc", format: "basic_date_time"}}
|
timeout: "5s",
|
||||||
],
|
sort: [
|
||||||
query: %{
|
"_score",
|
||||||
bool: %{
|
%{"_timestamp" => %{order: "desc", format: "basic_date_time"}}
|
||||||
must: must
|
],
|
||||||
|
query: %{
|
||||||
|
bool: %{
|
||||||
|
must: must
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp maybe_fetch(:activity, search_query) do
|
defp maybe_fetch(:activity, search_query) do
|
||||||
|
|
|
@ -57,5 +57,5 @@ def encode(activity) do
|
||||||
defimpl Elasticsearch.Document, for: Pleroma.Object do
|
defimpl Elasticsearch.Document, for: Pleroma.Object do
|
||||||
def id(obj), do: obj.id
|
def id(obj), do: obj.id
|
||||||
def routing(_), do: false
|
def routing(_), do: false
|
||||||
def encode(_), do: %{}
|
def encode(_), do: nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -154,11 +154,10 @@ def add_to_index(activity) do
|
||||||
|
|
||||||
with {:ok, res} <- result,
|
with {:ok, res} <- result,
|
||||||
true <- Map.has_key?(res, "taskUid") do
|
true <- Map.has_key?(res, "taskUid") do
|
||||||
{:ok, res}
|
# Do nothing
|
||||||
else
|
else
|
||||||
err ->
|
_ ->
|
||||||
Logger.error("Failed to add activity #{activity.id} to index: #{inspect(result)}")
|
Logger.error("Failed to add activity #{activity.id} to index: #{inspect(result)}")
|
||||||
{:error, err}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,7 @@ defmodule Pleroma.Search.SearchBackend do
|
||||||
|
|
||||||
The whole activity is passed, to allow filtering on things such as scope.
|
The whole activity is passed, to allow filtering on things such as scope.
|
||||||
"""
|
"""
|
||||||
@callback add_to_index(activity :: Pleroma.Activity.t()) :: {:ok, any()} | {:error, any()}
|
@callback add_to_index(activity :: Pleroma.Activity.t()) :: nil
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Remove the object from the index.
|
Remove the object from the index.
|
||||||
|
@ -13,5 +13,5 @@ defmodule Pleroma.Search.SearchBackend do
|
||||||
is what contains the actual content and there is no need for fitlering when removing
|
is what contains the actual content and there is no need for fitlering when removing
|
||||||
from index.
|
from index.
|
||||||
"""
|
"""
|
||||||
@callback remove_from_index(object :: Pleroma.Object.t()) :: {:ok, any()} | {:error, any()}
|
@callback remove_from_index(object :: Pleroma.Object.t()) :: nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -27,7 +27,7 @@ def key_id_to_actor_id(key_id) do
|
||||||
|
|
||||||
_ ->
|
_ ->
|
||||||
case Pleroma.Web.WebFinger.finger(maybe_ap_id) do
|
case Pleroma.Web.WebFinger.finger(maybe_ap_id) do
|
||||||
{:ok, %{"ap_id" => ap_id}} -> {:ok, ap_id}
|
%{"ap_id" => ap_id} -> {:ok, ap_id}
|
||||||
_ -> {:error, maybe_ap_id}
|
_ -> {:error, maybe_ap_id}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,7 +11,7 @@ defmodule Pleroma.Stats do
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
|
||||||
@interval :timer.seconds(300)
|
@interval :timer.seconds(60)
|
||||||
|
|
||||||
def start_link(_) do
|
def start_link(_) do
|
||||||
GenServer.start_link(
|
GenServer.start_link(
|
||||||
|
@ -85,24 +85,14 @@ def calculate_stat_data do
|
||||||
where: not u.invisible
|
where: not u.invisible
|
||||||
)
|
)
|
||||||
|
|
||||||
remote_users_query =
|
|
||||||
from(u in User,
|
|
||||||
where: u.is_active == true,
|
|
||||||
where: u.local == false,
|
|
||||||
where: not is_nil(u.nickname),
|
|
||||||
where: not u.invisible
|
|
||||||
)
|
|
||||||
|
|
||||||
user_count = Repo.aggregate(users_query, :count, :id)
|
user_count = Repo.aggregate(users_query, :count, :id)
|
||||||
remote_user_count = Repo.aggregate(remote_users_query, :count, :id)
|
|
||||||
|
|
||||||
%{
|
%{
|
||||||
peers: peers,
|
peers: peers,
|
||||||
stats: %{
|
stats: %{
|
||||||
domain_count: domain_count,
|
domain_count: domain_count,
|
||||||
status_count: status_count || 0,
|
status_count: status_count || 0,
|
||||||
user_count: user_count,
|
user_count: user_count
|
||||||
remote_user_count: remote_user_count
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
50
lib/pleroma/tesla/middleware/connection_pool.ex
Normal file
50
lib/pleroma/tesla/middleware/connection_pool.ex
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
# Pleroma: A lightweight social networking server
|
||||||
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
||||||
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
|
defmodule Pleroma.Tesla.Middleware.ConnectionPool do
|
||||||
|
@moduledoc """
|
||||||
|
Middleware to get/release connections from `Pleroma.Gun.ConnectionPool`
|
||||||
|
"""
|
||||||
|
|
||||||
|
@behaviour Tesla.Middleware
|
||||||
|
|
||||||
|
alias Pleroma.Gun.ConnectionPool
|
||||||
|
|
||||||
|
@impl Tesla.Middleware
|
||||||
|
def call(%Tesla.Env{url: url, opts: opts} = env, next, _) do
|
||||||
|
uri = URI.parse(url)
|
||||||
|
|
||||||
|
# Avoid leaking connections when the middleware is called twice
|
||||||
|
# with body_as: :chunks. We assume only the middleware can set
|
||||||
|
# opts[:adapter][:conn]
|
||||||
|
if opts[:adapter][:conn] do
|
||||||
|
ConnectionPool.release_conn(opts[:adapter][:conn])
|
||||||
|
end
|
||||||
|
|
||||||
|
case ConnectionPool.get_conn(uri, opts[:adapter]) do
|
||||||
|
{:ok, conn_pid} ->
|
||||||
|
adapter_opts = Keyword.merge(opts[:adapter], conn: conn_pid, close_conn: false)
|
||||||
|
opts = Keyword.put(opts, :adapter, adapter_opts)
|
||||||
|
env = %{env | opts: opts}
|
||||||
|
|
||||||
|
case Tesla.run(env, next) do
|
||||||
|
{:ok, env} ->
|
||||||
|
unless opts[:adapter][:body_as] == :chunks do
|
||||||
|
ConnectionPool.release_conn(conn_pid)
|
||||||
|
{_, res} = pop_in(env.opts[:adapter][:conn])
|
||||||
|
{:ok, res}
|
||||||
|
else
|
||||||
|
{:ok, env}
|
||||||
|
end
|
||||||
|
|
||||||
|
err ->
|
||||||
|
ConnectionPool.release_conn(conn_pid)
|
||||||
|
err
|
||||||
|
end
|
||||||
|
|
||||||
|
err ->
|
||||||
|
err
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -162,7 +162,7 @@ defp prepare_upload(%Plug.Upload{} = file, opts) do
|
||||||
defp prepare_upload(%{img: "data:image/" <> image_data}, opts) do
|
defp prepare_upload(%{img: "data:image/" <> image_data}, opts) do
|
||||||
parsed = Regex.named_captures(~r/(?<filetype>jpeg|png|gif);base64,(?<data>.*)/, image_data)
|
parsed = Regex.named_captures(~r/(?<filetype>jpeg|png|gif);base64,(?<data>.*)/, image_data)
|
||||||
data = Base.decode64!(parsed["data"], ignore: :whitespace)
|
data = Base.decode64!(parsed["data"], ignore: :whitespace)
|
||||||
hash = Base.encode16(:crypto.hash(:sha256, data), case: :lower)
|
hash = Base.encode16(:crypto.hash(:sha256, data), lower: true)
|
||||||
|
|
||||||
with :ok <- check_binary_size(data, opts.size_limit),
|
with :ok <- check_binary_size(data, opts.size_limit),
|
||||||
tmp_path <- tempfile_for_image(data),
|
tmp_path <- tempfile_for_image(data),
|
||||||
|
|
|
@ -77,6 +77,7 @@ defp media_dimensions(file) do
|
||||||
%{width: width, height: height}
|
%{width: width, height: height}
|
||||||
else
|
else
|
||||||
nil -> {:error, {:ffprobe, :command_not_found}}
|
nil -> {:error, {:ffprobe, :command_not_found}}
|
||||||
|
{:error, _} = error -> error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -9,12 +9,11 @@ defmodule Pleroma.Upload.Filter.Exiftool do
|
||||||
"""
|
"""
|
||||||
@behaviour Pleroma.Upload.Filter
|
@behaviour Pleroma.Upload.Filter
|
||||||
|
|
||||||
@spec filter(Pleroma.Upload.t()) :: {:ok, :noop} | {:ok, :filtered} | {:error, String.t()}
|
@spec filter(Pleroma.Upload.t()) :: {:ok, any()} | {:error, String.t()}
|
||||||
|
|
||||||
# Formats not compatible with exiftool at this time
|
# Formats not compatible with exiftool at this time
|
||||||
def filter(%Pleroma.Upload{content_type: "image/heic"}), do: {:ok, :noop}
|
def filter(%Pleroma.Upload{content_type: "image/heic"}), do: {:ok, :noop}
|
||||||
def filter(%Pleroma.Upload{content_type: "image/webp"}), do: {:ok, :noop}
|
def filter(%Pleroma.Upload{content_type: "image/webp"}), do: {:ok, :noop}
|
||||||
def filter(%Pleroma.Upload{content_type: "image/svg+xml"}), do: {:ok, :noop}
|
|
||||||
|
|
||||||
def filter(%Pleroma.Upload{tempfile: file, content_type: "image" <> _}) do
|
def filter(%Pleroma.Upload{tempfile: file, content_type: "image" <> _}) do
|
||||||
try do
|
try do
|
||||||
|
|
|
@ -38,7 +38,7 @@ defmodule Pleroma.Upload.Filter.Mogrifun do
|
||||||
[{"fill", "yellow"}, {"tint", "40"}]
|
[{"fill", "yellow"}, {"tint", "40"}]
|
||||||
]
|
]
|
||||||
|
|
||||||
@spec filter(Pleroma.Upload.t()) :: {:ok, :filtered | :noop} | {:error, String.t()}
|
@spec filter(Pleroma.Upload.t()) :: {:ok, atom()} | {:error, String.t()}
|
||||||
def filter(%Pleroma.Upload{tempfile: file, content_type: "image" <> _}) do
|
def filter(%Pleroma.Upload{tempfile: file, content_type: "image" <> _}) do
|
||||||
try do
|
try do
|
||||||
Filter.Mogrify.do_filter(file, [Enum.random(@filters)])
|
Filter.Mogrify.do_filter(file, [Enum.random(@filters)])
|
||||||
|
|
|
@ -3,10 +3,6 @@
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.User do
|
defmodule Pleroma.User do
|
||||||
@moduledoc """
|
|
||||||
A user, local or remote
|
|
||||||
"""
|
|
||||||
|
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
|
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
|
@ -479,7 +475,7 @@ def remote_user_changeset(struct \\ %User{local: false}, params) do
|
||||||
|> validate_format(:nickname, @email_regex)
|
|> validate_format(:nickname, @email_regex)
|
||||||
|> validate_length(:bio, max: bio_limit)
|
|> validate_length(:bio, max: bio_limit)
|
||||||
|> validate_length(:name, max: name_limit)
|
|> validate_length(:name, max: name_limit)
|
||||||
|> validate_fields(true, struct)
|
|> validate_fields(true)
|
||||||
|> validate_non_local()
|
|> validate_non_local()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -549,21 +545,13 @@ def update_changeset(struct, params \\ %{}) do
|
||||||
:pleroma_settings_store,
|
:pleroma_settings_store,
|
||||||
&{:ok, Map.merge(struct.pleroma_settings_store, &1)}
|
&{:ok, Map.merge(struct.pleroma_settings_store, &1)}
|
||||||
)
|
)
|
||||||
|> validate_fields(false, struct)
|
|> validate_fields(false)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp put_fields(changeset) do
|
defp put_fields(changeset) do
|
||||||
# These fields are inconsistent in tests when it comes to binary/atom keys
|
|
||||||
if raw_fields = get_change(changeset, :raw_fields) do
|
if raw_fields = get_change(changeset, :raw_fields) do
|
||||||
raw_fields =
|
raw_fields =
|
||||||
raw_fields
|
raw_fields
|
||||||
|> Enum.map(fn
|
|
||||||
%{name: name, value: value} ->
|
|
||||||
%{"name" => name, "value" => value}
|
|
||||||
|
|
||||||
%{"name" => _} = field ->
|
|
||||||
field
|
|
||||||
end)
|
|
||||||
|> Enum.filter(fn %{"name" => n} -> n != "" end)
|
|> Enum.filter(fn %{"name" => n} -> n != "" end)
|
||||||
|
|
||||||
fields =
|
fields =
|
||||||
|
@ -611,13 +599,7 @@ defp put_change_if_present(changeset, map_field, value_function) do
|
||||||
{:ok, new_value} <- value_function.(value) do
|
{:ok, new_value} <- value_function.(value) do
|
||||||
put_change(changeset, map_field, new_value)
|
put_change(changeset, map_field, new_value)
|
||||||
else
|
else
|
||||||
{:error, :file_too_large} ->
|
_ -> changeset
|
||||||
Ecto.Changeset.validate_change(changeset, map_field, fn map_field, _value ->
|
|
||||||
[{map_field, "file is too large"}]
|
|
||||||
end)
|
|
||||||
|
|
||||||
_ ->
|
|
||||||
changeset
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -717,8 +699,7 @@ def register_changeset_ldap(struct, params = %{password: password})
|
||||||
|> put_private_key()
|
|> put_private_key()
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec register_changeset(User.t(), map(), keyword()) :: Changeset.t()
|
def register_changeset(struct, params \\ %{}, opts \\ []) do
|
||||||
def register_changeset(%User{} = struct, params \\ %{}, opts \\ []) do
|
|
||||||
bio_limit = Config.get([:instance, :user_bio_length], 5000)
|
bio_limit = Config.get([:instance, :user_bio_length], 5000)
|
||||||
name_limit = Config.get([:instance, :user_name_length], 100)
|
name_limit = Config.get([:instance, :user_name_length], 100)
|
||||||
reason_limit = Config.get([:instance, :registration_reason_length], 500)
|
reason_limit = Config.get([:instance, :registration_reason_length], 500)
|
||||||
|
@ -832,14 +813,12 @@ defp autofollowing_users(user) do
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc "Inserts provided changeset, performs post-registration actions (confirmation email sending etc.)"
|
@doc "Inserts provided changeset, performs post-registration actions (confirmation email sending etc.)"
|
||||||
@spec register(Changeset.t()) :: {:ok, User.t()} | {:error, any} | nil
|
|
||||||
def register(%Ecto.Changeset{} = changeset) do
|
def register(%Ecto.Changeset{} = changeset) do
|
||||||
with {:ok, user} <- Repo.insert(changeset) do
|
with {:ok, user} <- Repo.insert(changeset) do
|
||||||
post_register_action(user)
|
post_register_action(user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec post_register_action(User.t()) :: {:error, any} | {:ok, User.t()}
|
|
||||||
def post_register_action(%User{is_confirmed: false} = user) do
|
def post_register_action(%User{is_confirmed: false} = user) do
|
||||||
with {:ok, _} <- maybe_send_confirmation_email(user) do
|
with {:ok, _} <- maybe_send_confirmation_email(user) do
|
||||||
{:ok, user}
|
{:ok, user}
|
||||||
|
@ -954,8 +933,7 @@ def needs_update?(%User{local: false} = user) do
|
||||||
|
|
||||||
def needs_update?(_), do: true
|
def needs_update?(_), do: true
|
||||||
|
|
||||||
@spec maybe_direct_follow(User.t(), User.t()) ::
|
@spec maybe_direct_follow(User.t(), User.t()) :: {:ok, User.t()} | {:error, String.t()}
|
||||||
{:ok, User.t(), User.t()} | {:error, String.t()}
|
|
||||||
|
|
||||||
# "Locked" (self-locked) users demand explicit authorization of follow requests
|
# "Locked" (self-locked) users demand explicit authorization of follow requests
|
||||||
def maybe_direct_follow(%User{} = follower, %User{local: true, is_locked: true} = followed) do
|
def maybe_direct_follow(%User{} = follower, %User{local: true, is_locked: true} = followed) do
|
||||||
|
@ -1088,11 +1066,6 @@ def get_by_guessed_nickname(ap_id) do
|
||||||
get_cached_by_nickname(nickname)
|
get_cached_by_nickname(nickname)
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec set_cache(
|
|
||||||
{:error, any}
|
|
||||||
| {:ok, User.t()}
|
|
||||||
| User.t()
|
|
||||||
) :: {:ok, User.t()} | {:error, any}
|
|
||||||
def set_cache({:ok, user}), do: set_cache(user)
|
def set_cache({:ok, user}), do: set_cache(user)
|
||||||
def set_cache({:error, err}), do: {:error, err}
|
def set_cache({:error, err}), do: {:error, err}
|
||||||
|
|
||||||
|
@ -1103,14 +1076,12 @@ def set_cache(%User{} = user) do
|
||||||
{:ok, user}
|
{:ok, user}
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec update_and_set_cache(User.t(), map()) :: {:ok, User.t()} | {:error, any}
|
|
||||||
def update_and_set_cache(struct, params) do
|
def update_and_set_cache(struct, params) do
|
||||||
struct
|
struct
|
||||||
|> update_changeset(params)
|
|> update_changeset(params)
|
||||||
|> update_and_set_cache()
|
|> update_and_set_cache()
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec update_and_set_cache(Changeset.t()) :: {:ok, User.t()} | {:error, any}
|
|
||||||
def update_and_set_cache(%{data: %Pleroma.User{} = user} = changeset) do
|
def update_and_set_cache(%{data: %Pleroma.User{} = user} = changeset) do
|
||||||
was_superuser_before_update = User.superuser?(user)
|
was_superuser_before_update = User.superuser?(user)
|
||||||
|
|
||||||
|
@ -1165,7 +1136,6 @@ def get_cached_by_ap_id(ap_id) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec get_cached_by_id(String.t()) :: nil | Pleroma.User.t()
|
|
||||||
def get_cached_by_id(id) do
|
def get_cached_by_id(id) do
|
||||||
key = "id:#{id}"
|
key = "id:#{id}"
|
||||||
|
|
||||||
|
@ -2277,7 +2247,7 @@ def get_ap_ids_by_nicknames(nicknames) do
|
||||||
defp put_password_hash(
|
defp put_password_hash(
|
||||||
%Ecto.Changeset{valid?: true, changes: %{password: password}} = changeset
|
%Ecto.Changeset{valid?: true, changes: %{password: password}} = changeset
|
||||||
) do
|
) do
|
||||||
change(changeset, password_hash: Pleroma.Password.hash_pwd_salt(password))
|
change(changeset, password_hash: Pleroma.Password.Pbkdf2.hash_pwd_salt(password))
|
||||||
end
|
end
|
||||||
|
|
||||||
defp put_password_hash(changeset), do: changeset
|
defp put_password_hash(changeset), do: changeset
|
||||||
|
@ -2326,7 +2296,6 @@ def add_alias(user, new_alias_user) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec delete_alias(User.t(), User.t()) :: {:error, :no_such_alias}
|
|
||||||
def delete_alias(user, alias_user) do
|
def delete_alias(user, alias_user) do
|
||||||
current_aliases = user.also_known_as || []
|
current_aliases = user.also_known_as || []
|
||||||
alias_ap_id = alias_user.ap_id
|
alias_ap_id = alias_user.ap_id
|
||||||
|
@ -2359,8 +2328,7 @@ def update_background(user, background) do
|
||||||
|> update_and_set_cache()
|
|> update_and_set_cache()
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec validate_fields(Ecto.Changeset.t(), Boolean.t(), User.t()) :: Ecto.Changeset.t()
|
def validate_fields(changeset, remote? \\ false) do
|
||||||
def validate_fields(changeset, remote? \\ false, struct) do
|
|
||||||
limit_name = if remote?, do: :max_remote_account_fields, else: :max_account_fields
|
limit_name = if remote?, do: :max_remote_account_fields, else: :max_account_fields
|
||||||
limit = Config.get([:instance, limit_name], 0)
|
limit = Config.get([:instance, limit_name], 0)
|
||||||
|
|
||||||
|
@ -2373,7 +2341,6 @@ def validate_fields(changeset, remote? \\ false, struct) do
|
||||||
[fields: "invalid"]
|
[fields: "invalid"]
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|> maybe_validate_rel_me_field(struct)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
defp valid_field?(%{"name" => name, "value" => value}) do
|
defp valid_field?(%{"name" => name, "value" => value}) do
|
||||||
|
@ -2386,75 +2353,6 @@ defp valid_field?(%{"name" => name, "value" => value}) do
|
||||||
|
|
||||||
defp valid_field?(_), do: false
|
defp valid_field?(_), do: false
|
||||||
|
|
||||||
defp is_url(nil), do: nil
|
|
||||||
|
|
||||||
defp is_url(uri) do
|
|
||||||
case URI.parse(uri) do
|
|
||||||
%URI{host: nil} -> false
|
|
||||||
%URI{scheme: nil} -> false
|
|
||||||
_ -> true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
@spec maybe_validate_rel_me_field(Changeset.t(), User.t()) :: Changeset.t()
|
|
||||||
defp maybe_validate_rel_me_field(changeset, %User{ap_id: _ap_id} = struct) do
|
|
||||||
fields = get_change(changeset, :fields)
|
|
||||||
raw_fields = get_change(changeset, :raw_fields)
|
|
||||||
|
|
||||||
if is_nil(fields) do
|
|
||||||
changeset
|
|
||||||
else
|
|
||||||
validate_rel_me_field(changeset, fields, raw_fields, struct)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
defp maybe_validate_rel_me_field(changeset, _), do: changeset
|
|
||||||
|
|
||||||
@spec validate_rel_me_field(Changeset.t(), [Map.t()], [Map.t()], User.t()) :: Changeset.t()
|
|
||||||
defp validate_rel_me_field(changeset, fields, raw_fields, %User{
|
|
||||||
nickname: nickname,
|
|
||||||
ap_id: ap_id
|
|
||||||
}) do
|
|
||||||
fields =
|
|
||||||
fields
|
|
||||||
|> Enum.with_index()
|
|
||||||
|> Enum.map(fn {%{"name" => name, "value" => value}, index} ->
|
|
||||||
raw_value =
|
|
||||||
if is_nil(raw_fields) do
|
|
||||||
nil
|
|
||||||
else
|
|
||||||
Enum.at(raw_fields, index)["value"]
|
|
||||||
end
|
|
||||||
|
|
||||||
if is_url(raw_value) do
|
|
||||||
frontend_url =
|
|
||||||
Pleroma.Web.Router.Helpers.redirect_url(
|
|
||||||
Pleroma.Web.Endpoint,
|
|
||||||
:redirector_with_meta,
|
|
||||||
nickname
|
|
||||||
)
|
|
||||||
|
|
||||||
possible_urls = [ap_id, frontend_url]
|
|
||||||
|
|
||||||
with "me" <- RelMe.maybe_put_rel_me(raw_value, possible_urls) do
|
|
||||||
%{
|
|
||||||
"name" => name,
|
|
||||||
"value" => value,
|
|
||||||
"verified_at" => DateTime.to_iso8601(DateTime.utc_now())
|
|
||||||
}
|
|
||||||
else
|
|
||||||
e ->
|
|
||||||
Logger.error("Could not check for rel=me, #{inspect(e)}")
|
|
||||||
%{"name" => name, "value" => value}
|
|
||||||
end
|
|
||||||
else
|
|
||||||
%{"name" => name, "value" => value}
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
put_change(changeset, :fields, fields)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp truncate_field(%{"name" => name, "value" => value}) do
|
defp truncate_field(%{"name" => name, "value" => value}) do
|
||||||
{name, _chopped} =
|
{name, _chopped} =
|
||||||
String.split_at(name, Config.get([:instance, :account_field_name_length], 255))
|
String.split_at(name, Config.get([:instance, :account_field_name_length], 255))
|
||||||
|
@ -2513,7 +2411,7 @@ def confirmation_changeset(user, set_confirmation: confirmed?) do
|
||||||
cast(user, params, [:is_confirmed, :confirmation_token])
|
cast(user, params, [:is_confirmed, :confirmation_token])
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec approval_changeset(Changeset.t(), keyword()) :: Changeset.t()
|
@spec approval_changeset(User.t(), keyword()) :: Changeset.t()
|
||||||
def approval_changeset(user, set_approval: approved?) do
|
def approval_changeset(user, set_approval: approved?) do
|
||||||
cast(user, %{is_approved: approved?}, [:is_approved])
|
cast(user, %{is_approved: approved?}, [:is_approved])
|
||||||
end
|
end
|
||||||
|
@ -2588,19 +2486,15 @@ defp add_to_block(%User{} = user, %User{} = blocked) do
|
||||||
with {:ok, relationship} <- UserRelationship.create_block(user, blocked) do
|
with {:ok, relationship} <- UserRelationship.create_block(user, blocked) do
|
||||||
@cachex.del(:user_cache, "blocked_users_ap_ids:#{user.ap_id}")
|
@cachex.del(:user_cache, "blocked_users_ap_ids:#{user.ap_id}")
|
||||||
{:ok, relationship}
|
{:ok, relationship}
|
||||||
else
|
|
||||||
err -> err
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec remove_from_block(User.t(), User.t()) ::
|
@spec add_to_block(User.t(), User.t()) ::
|
||||||
{:ok, UserRelationship.t()} | {:ok, nil} | {:error, Ecto.Changeset.t()}
|
{:ok, UserRelationship.t()} | {:ok, nil} | {:error, Ecto.Changeset.t()}
|
||||||
defp remove_from_block(%User{} = user, %User{} = blocked) do
|
defp remove_from_block(%User{} = user, %User{} = blocked) do
|
||||||
with {:ok, relationship} <- UserRelationship.delete_block(user, blocked) do
|
with {:ok, relationship} <- UserRelationship.delete_block(user, blocked) do
|
||||||
@cachex.del(:user_cache, "blocked_users_ap_ids:#{user.ap_id}")
|
@cachex.del(:user_cache, "blocked_users_ap_ids:#{user.ap_id}")
|
||||||
{:ok, relationship}
|
{:ok, relationship}
|
||||||
else
|
|
||||||
err -> err
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -2622,8 +2516,11 @@ def sanitize_html(%User{} = user) do
|
||||||
# - display name
|
# - display name
|
||||||
def sanitize_html(%User{} = user, filter) do
|
def sanitize_html(%User{} = user, filter) do
|
||||||
fields =
|
fields =
|
||||||
Enum.map(user.fields, fn %{"value" => value} = field ->
|
Enum.map(user.fields, fn %{"name" => name, "value" => value} ->
|
||||||
Map.put(field, "value", HTML.filter_tags(value, Pleroma.HTML.Scrubber.LinksOnly))
|
%{
|
||||||
|
"name" => name,
|
||||||
|
"value" => HTML.filter_tags(value, Pleroma.HTML.Scrubber.LinksOnly)
|
||||||
|
}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
user
|
user
|
||||||
|
|
|
@ -130,8 +130,7 @@ def export(%__MODULE__{} = backup) do
|
||||||
:ok <- statuses(dir, backup.user),
|
:ok <- statuses(dir, backup.user),
|
||||||
:ok <- likes(dir, backup.user),
|
:ok <- likes(dir, backup.user),
|
||||||
:ok <- bookmarks(dir, backup.user),
|
:ok <- bookmarks(dir, backup.user),
|
||||||
{:ok, zip_path} <-
|
{:ok, zip_path} <- :zip.create(String.to_charlist(dir <> ".zip"), @files, cwd: dir),
|
||||||
:zip.create(String.to_charlist(dir <> ".zip"), @files, cwd: String.to_charlist(dir)),
|
|
||||||
{:ok, _} <- File.rm_rf(dir) do
|
{:ok, _} <- File.rm_rf(dir) do
|
||||||
{:ok, to_string(zip_path)}
|
{:ok, to_string(zip_path)}
|
||||||
end
|
end
|
||||||
|
|
|
@ -43,13 +43,7 @@ def get(%User{} = user, %Hashtag{} = hashtag) do
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_by_user(%User{} = user) do
|
def get_by_user(%User{} = user) do
|
||||||
user
|
Ecto.assoc(user, :followed_hashtags)
|
||||||
|> followed_hashtags_query()
|
|
||||||
|> Repo.all()
|
|> Repo.all()
|
||||||
end
|
end
|
||||||
|
|
||||||
def followed_hashtags_query(%User{} = user) do
|
|
||||||
Ecto.assoc(user, :followed_hashtags)
|
|
||||||
|> Ecto.Query.order_by([h], desc: h.id)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -56,10 +56,7 @@ defp skip_plug(conn, plug_modules) do
|
||||||
plug_module.skip_plug(conn)
|
plug_module.skip_plug(conn)
|
||||||
rescue
|
rescue
|
||||||
UndefinedFunctionError ->
|
UndefinedFunctionError ->
|
||||||
reraise(
|
raise "`#{plug_module}` is not skippable. Append `use Pleroma.Web, :plug` to its code."
|
||||||
"`#{plug_module}` is not skippable. Append `use Pleroma.Web, :plug` to its code.",
|
|
||||||
__STACKTRACE__
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
@ -132,6 +129,66 @@ defp maybe_halt_on_missing_oauth_scopes_check(conn) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def view do
|
||||||
|
quote do
|
||||||
|
use Phoenix.View,
|
||||||
|
root: "lib/pleroma/web/templates",
|
||||||
|
namespace: Pleroma.Web
|
||||||
|
|
||||||
|
# Import convenience functions from controllers
|
||||||
|
import Phoenix.Controller, only: [get_csrf_token: 0, get_flash: 2, view_module: 1]
|
||||||
|
|
||||||
|
import Pleroma.Web.ErrorHelpers
|
||||||
|
import Pleroma.Web.Gettext
|
||||||
|
|
||||||
|
alias Pleroma.Web.Router.Helpers, as: Routes
|
||||||
|
|
||||||
|
require Logger
|
||||||
|
|
||||||
|
@doc "Same as `render/3` but wrapped in a rescue block"
|
||||||
|
def safe_render(view, template, assigns \\ %{}) do
|
||||||
|
Phoenix.View.render(view, template, assigns)
|
||||||
|
rescue
|
||||||
|
error ->
|
||||||
|
Logger.error(
|
||||||
|
"#{__MODULE__} failed to render #{inspect({view, template})}\n" <>
|
||||||
|
Exception.format(:error, error, __STACKTRACE__)
|
||||||
|
)
|
||||||
|
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
@doc """
|
||||||
|
Same as `render_many/4` but wrapped in rescue block.
|
||||||
|
"""
|
||||||
|
def safe_render_many(collection, view, template, assigns \\ %{}) do
|
||||||
|
Enum.map(collection, fn resource ->
|
||||||
|
as = Map.get(assigns, :as) || view.__resource__
|
||||||
|
assigns = Map.put(assigns, as, resource)
|
||||||
|
safe_render(view, template, assigns)
|
||||||
|
end)
|
||||||
|
|> Enum.filter(& &1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def router do
|
||||||
|
quote do
|
||||||
|
use Phoenix.Router
|
||||||
|
# credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse
|
||||||
|
import Plug.Conn
|
||||||
|
import Phoenix.Controller
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def channel do
|
||||||
|
quote do
|
||||||
|
# credo:disable-for-next-line Credo.Check.Consistency.MultiAliasImportRequireUse
|
||||||
|
import Phoenix.Channel
|
||||||
|
import Pleroma.Web.Gettext
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def plug do
|
def plug do
|
||||||
quote do
|
quote do
|
||||||
@behaviour Pleroma.Web.Plug
|
@behaviour Pleroma.Web.Plug
|
||||||
|
@ -176,80 +233,6 @@ def call(%Plug.Conn{} = conn, options) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def view do
|
|
||||||
quote do
|
|
||||||
use Phoenix.View,
|
|
||||||
root: "lib/pleroma/web/templates",
|
|
||||||
namespace: Pleroma.Web
|
|
||||||
|
|
||||||
# Import convenience functions from controllers
|
|
||||||
import Phoenix.Controller,
|
|
||||||
only: [get_flash: 1, get_flash: 2, view_module: 1, view_template: 1]
|
|
||||||
|
|
||||||
# Include shared imports and aliases for views
|
|
||||||
unquote(view_helpers())
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def live_view do
|
|
||||||
quote do
|
|
||||||
use Phoenix.LiveView,
|
|
||||||
layout: {Pleroma.Web.LayoutView, "live.html"}
|
|
||||||
|
|
||||||
unquote(view_helpers())
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def live_component do
|
|
||||||
quote do
|
|
||||||
use Phoenix.LiveComponent
|
|
||||||
|
|
||||||
unquote(view_helpers())
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def component do
|
|
||||||
quote do
|
|
||||||
use Phoenix.Component
|
|
||||||
|
|
||||||
unquote(view_helpers())
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def router do
|
|
||||||
quote do
|
|
||||||
use Phoenix.Router
|
|
||||||
|
|
||||||
import Plug.Conn
|
|
||||||
import Phoenix.Controller
|
|
||||||
import Phoenix.LiveView.Router
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def channel do
|
|
||||||
quote do
|
|
||||||
use Phoenix.Channel
|
|
||||||
import Pleroma.Web.Gettext
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
defp view_helpers do
|
|
||||||
quote do
|
|
||||||
# Use all HTML functionality (forms, tags, etc)
|
|
||||||
use Phoenix.HTML
|
|
||||||
|
|
||||||
# Import LiveView and .heex helpers (live_render, live_patch, <.form>, etc)
|
|
||||||
import Phoenix.LiveView.Helpers
|
|
||||||
|
|
||||||
# Import basic rendering functionality (render, render_layout, etc)
|
|
||||||
import Phoenix.View
|
|
||||||
|
|
||||||
import Pleroma.Web.ErrorHelpers
|
|
||||||
import Pleroma.Web.Gettext
|
|
||||||
alias Pleroma.Web.Router.Helpers, as: Routes
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
When used, dispatch to the appropriate controller/view/etc.
|
When used, dispatch to the appropriate controller/view/etc.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1531,10 +1531,6 @@ defp normalize_image(%{"url" => url}) do
|
||||||
defp normalize_image(urls) when is_list(urls), do: urls |> List.first() |> normalize_image()
|
defp normalize_image(urls) when is_list(urls), do: urls |> List.first() |> normalize_image()
|
||||||
defp normalize_image(_), do: nil
|
defp normalize_image(_), do: nil
|
||||||
|
|
||||||
defp normalize_also_known_as(aka) when is_list(aka), do: aka
|
|
||||||
defp normalize_also_known_as(aka) when is_binary(aka), do: [aka]
|
|
||||||
defp normalize_also_known_as(nil), do: []
|
|
||||||
|
|
||||||
defp object_to_user_data(data, additional) do
|
defp object_to_user_data(data, additional) do
|
||||||
fields =
|
fields =
|
||||||
data
|
data
|
||||||
|
@ -1580,7 +1576,6 @@ defp object_to_user_data(data, additional) do
|
||||||
also_known_as =
|
also_known_as =
|
||||||
data
|
data
|
||||||
|> Map.get("alsoKnownAs", [])
|
|> Map.get("alsoKnownAs", [])
|
||||||
|> normalize_also_known_as()
|
|
||||||
|> Enum.filter(fn url ->
|
|> Enum.filter(fn url ->
|
||||||
case URI.parse(url) do
|
case URI.parse(url) do
|
||||||
%URI{scheme: "http"} -> true
|
%URI{scheme: "http"} -> true
|
||||||
|
|
|
@ -12,7 +12,7 @@ defmodule Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy do
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
@adapter_options [
|
@adapter_options [
|
||||||
receive_timeout: 10_000
|
recv_timeout: 10_000
|
||||||
]
|
]
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
|
|
@ -14,11 +14,11 @@ defmodule Pleroma.Web.AdminAPI.StatusView do
|
||||||
defdelegate merge_account_views(user), to: AdminAPI.AccountView
|
defdelegate merge_account_views(user), to: AdminAPI.AccountView
|
||||||
|
|
||||||
def render("index.json", %{total: total} = opts) do
|
def render("index.json", %{total: total} = opts) do
|
||||||
%{total: total, activities: render_many(opts.activities, __MODULE__, "show.json", opts)}
|
%{total: total, activities: safe_render_many(opts.activities, __MODULE__, "show.json", opts)}
|
||||||
end
|
end
|
||||||
|
|
||||||
def render("index.json", opts) do
|
def render("index.json", opts) do
|
||||||
render_many(opts.activities, __MODULE__, "show.json", opts)
|
safe_render_many(opts.activities, __MODULE__, "show.json", opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
def render("show.json", %{activity: %{data: %{"object" => _object}} = activity} = opts) do
|
def render("show.json", %{activity: %{data: %{"object" => _object}} = activity} = opts) do
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
defmodule Pleroma.Web.AkkomaAPI.MetricsController do
|
|
||||||
use Pleroma.Web, :controller
|
|
||||||
|
|
||||||
alias Pleroma.Web.Plugs.OAuthScopesPlug
|
|
||||||
alias Pleroma.Config
|
|
||||||
|
|
||||||
plug(
|
|
||||||
OAuthScopesPlug,
|
|
||||||
%{scopes: ["admin:metrics"]}
|
|
||||||
when action in [
|
|
||||||
:show
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
def show(conn, _params) do
|
|
||||||
if Config.get([:instance, :export_prometheus_metrics], true) do
|
|
||||||
conn
|
|
||||||
|> text(Pleroma.PrometheusExporter.show())
|
|
||||||
else
|
|
||||||
conn
|
|
||||||
|> send_resp(404, "Not Found")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -3,8 +3,6 @@ defmodule Pleroma.Web.AkkomaAPI.TranslationController do
|
||||||
|
|
||||||
alias Pleroma.Web.Plugs.OAuthScopesPlug
|
alias Pleroma.Web.Plugs.OAuthScopesPlug
|
||||||
|
|
||||||
require Logger
|
|
||||||
|
|
||||||
@cachex Pleroma.Config.get([:cachex, :provider], Cachex)
|
@cachex Pleroma.Config.get([:cachex, :provider], Cachex)
|
||||||
|
|
||||||
@unauthenticated_access %{fallback: :proceed_unauthenticated, scopes: []}
|
@unauthenticated_access %{fallback: :proceed_unauthenticated, scopes: []}
|
||||||
|
@ -28,12 +26,8 @@ def languages(conn, _params) do
|
||||||
conn
|
conn
|
||||||
|> json(%{source: source_languages, target: dest_languages})
|
|> json(%{source: source_languages, target: dest_languages})
|
||||||
else
|
else
|
||||||
{:enabled, false} ->
|
{:enabled, false} -> json(conn, %{})
|
||||||
json(conn, %{})
|
e -> IO.inspect(e)
|
||||||
|
|
||||||
e ->
|
|
||||||
Logger.error("Translation language list error: #{inspect(e)}")
|
|
||||||
{:error, e}
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -23,19 +23,19 @@ def spec(opts \\ []) do
|
||||||
[]
|
[]
|
||||||
end,
|
end,
|
||||||
info: %OpenApiSpex.Info{
|
info: %OpenApiSpex.Info{
|
||||||
title: "Akkoma API",
|
title: "Pleroma API",
|
||||||
description: """
|
description: """
|
||||||
This is documentation for the Akkoma API. Most of the endpoints and entities come
|
This is documentation for client Pleroma API. Most of the endpoints and entities come
|
||||||
from Mastodon API and have custom extensions on top.
|
from Mastodon API and have custom extensions on top.
|
||||||
|
|
||||||
While this document aims to be a complete guide to the client API Akkoma exposes,
|
While this document aims to be a complete guide to the client API Pleroma exposes,
|
||||||
it may not be complete. Some endpoints may have incomplete or poorly worded documentation.
|
the details are still being worked out. Some endpoints may have incomplete or poorly worded documentation.
|
||||||
You might want to check the following resources if something is not clear:
|
You might want to check the following resources if something is not clear:
|
||||||
- [Legacy Pleroma-specific endpoint documentation](https://docs-develop.pleroma.social/backend/development/API/pleroma_api/)
|
- [Legacy Pleroma-specific endpoint documentation](https://docs-develop.pleroma.social/backend/development/API/pleroma_api/)
|
||||||
- [Mastodon API documentation](https://docs.joinmastodon.org/client/intro/)
|
- [Mastodon API documentation](https://docs.joinmastodon.org/client/intro/)
|
||||||
- [Differences in Mastodon API responses from vanilla Mastodon](https://docs.akkoma.dev/stable/development/API/differences_in_mastoapi_responses/)
|
- [Differences in Mastodon API responses from vanilla Mastodon](https://docs-develop.pleroma.social/backend/development/API/differences_in_mastoapi_responses/)
|
||||||
|
|
||||||
Please report such occurrences on our [issue tracker](https://akkoma.dev/AkkomaGang/akkoma). Feel free to submit API questions or proposals there too!
|
Please report such occurences on our [issue tracker](https://git.pleroma.social/pleroma/pleroma/-/issues). Feel free to submit API questions or proposals there too!
|
||||||
""",
|
""",
|
||||||
# Strip environment from the version
|
# Strip environment from the version
|
||||||
version: Application.spec(:pleroma, :vsn) |> to_string() |> String.replace(~r/\+.*$/, ""),
|
version: Application.spec(:pleroma, :vsn) |> to_string() |> String.replace(~r/\+.*$/, ""),
|
||||||
|
|
|
@ -64,8 +64,7 @@ def update_credentials_operation do
|
||||||
requestBody: request_body("Parameters", update_credentials_request(), required: true),
|
requestBody: request_body("Parameters", update_credentials_request(), required: true),
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => Operation.response("Account", "application/json", Account),
|
200 => Operation.response("Account", "application/json", Account),
|
||||||
403 => Operation.response("Error", "application/json", ApiError),
|
403 => Operation.response("Error", "application/json", ApiError)
|
||||||
413 => Operation.response("Error", "application/json", ApiError)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
@ -432,7 +431,6 @@ def lookup_operation do
|
||||||
],
|
],
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => Operation.response("Account", "application/json", Account),
|
200 => Operation.response("Account", "application/json", Account),
|
||||||
401 => Operation.response("Error", "application/json", ApiError),
|
|
||||||
404 => Operation.response("Error", "application/json", ApiError)
|
404 => Operation.response("Error", "application/json", ApiError)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -231,18 +231,9 @@ defp emoji_packs_response do
|
||||||
"application/json",
|
"application/json",
|
||||||
%Schema{
|
%Schema{
|
||||||
type: :object,
|
type: :object,
|
||||||
properties: %{
|
additionalProperties: emoji_pack(),
|
||||||
count: %Schema{type: :integer},
|
|
||||||
packs: %Schema{
|
|
||||||
type: :object,
|
|
||||||
additionalProperties: emoji_pack()
|
|
||||||
}
|
|
||||||
},
|
|
||||||
example: %{
|
example: %{
|
||||||
"count" => 4,
|
"emojos" => emoji_pack().example
|
||||||
"packs" => %{
|
|
||||||
"emojos" => emoji_pack().example
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -44,7 +44,7 @@ def unfollow_operation do
|
||||||
tags: ["Tags"],
|
tags: ["Tags"],
|
||||||
summary: "Unfollow a hashtag",
|
summary: "Unfollow a hashtag",
|
||||||
description: "Unfollow a hashtag",
|
description: "Unfollow a hashtag",
|
||||||
security: [%{"oAuth" => ["write:follows"]}],
|
security: [%{"oAuth" => ["write:follow"]}],
|
||||||
parameters: [id_param()],
|
parameters: [id_param()],
|
||||||
operationId: "TagController.unfollow",
|
operationId: "TagController.unfollow",
|
||||||
responses: %{
|
responses: %{
|
||||||
|
@ -54,26 +54,6 @@ def unfollow_operation do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
def show_followed_operation do
|
|
||||||
%Operation{
|
|
||||||
tags: ["Tags"],
|
|
||||||
summary: "Followed hashtags",
|
|
||||||
description: "View a list of hashtags the currently authenticated user is following",
|
|
||||||
parameters: pagination_params(),
|
|
||||||
security: [%{"oAuth" => ["read:follows"]}],
|
|
||||||
operationId: "TagController.show_followed",
|
|
||||||
responses: %{
|
|
||||||
200 =>
|
|
||||||
Operation.response("Hashtags", "application/json", %Schema{
|
|
||||||
type: :array,
|
|
||||||
items: Tag
|
|
||||||
}),
|
|
||||||
403 => Operation.response("Forbidden", "application/json", ApiError),
|
|
||||||
404 => Operation.response("Not Found", "application/json", ApiError)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
defp id_param do
|
defp id_param do
|
||||||
Operation.parameter(
|
Operation.parameter(
|
||||||
:id,
|
:id,
|
||||||
|
@ -82,22 +62,4 @@ defp id_param do
|
||||||
"Name of the hashtag"
|
"Name of the hashtag"
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def pagination_params do
|
|
||||||
[
|
|
||||||
Operation.parameter(:max_id, :query, :integer, "Return items older than this ID"),
|
|
||||||
Operation.parameter(
|
|
||||||
:min_id,
|
|
||||||
:query,
|
|
||||||
:integer,
|
|
||||||
"Return the oldest items newer than this ID"
|
|
||||||
),
|
|
||||||
Operation.parameter(
|
|
||||||
:limit,
|
|
||||||
:query,
|
|
||||||
%Schema{type: :integer, default: 20},
|
|
||||||
"Maximum number of items to return. Will be ignored if it's more than 40"
|
|
||||||
)
|
|
||||||
]
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -21,12 +21,6 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Tag do
|
||||||
following: %Schema{
|
following: %Schema{
|
||||||
type: :boolean,
|
type: :boolean,
|
||||||
description: "Whether the authenticated user is following the hashtag"
|
description: "Whether the authenticated user is following the hashtag"
|
||||||
},
|
|
||||||
history: %Schema{
|
|
||||||
type: :array,
|
|
||||||
items: %Schema{type: :string},
|
|
||||||
description:
|
|
||||||
"A list of historical uses of the hashtag (not implemented, for compatibility only)"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
example: %{
|
example: %{
|
||||||
|
|
|
@ -6,6 +6,7 @@ defmodule Pleroma.Web.Auth.PleromaAuthenticator do
|
||||||
alias Pleroma.Registration
|
alias Pleroma.Registration
|
||||||
alias Pleroma.Repo
|
alias Pleroma.Repo
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
alias Pleroma.Web.Plugs.AuthenticationPlug
|
||||||
|
|
||||||
import Pleroma.Web.Auth.Helpers, only: [fetch_credentials: 1, fetch_user: 1]
|
import Pleroma.Web.Auth.Helpers, only: [fetch_credentials: 1, fetch_user: 1]
|
||||||
|
|
||||||
|
@ -14,8 +15,8 @@ defmodule Pleroma.Web.Auth.PleromaAuthenticator do
|
||||||
def get_user(%Plug.Conn{} = conn) do
|
def get_user(%Plug.Conn{} = conn) do
|
||||||
with {:ok, {name, password}} <- fetch_credentials(conn),
|
with {:ok, {name, password}} <- fetch_credentials(conn),
|
||||||
{_, %User{} = user} <- {:user, fetch_user(name)},
|
{_, %User{} = user} <- {:user, fetch_user(name)},
|
||||||
{_, true} <- {:checkpw, Pleroma.Password.checkpw(password, user.password_hash)},
|
{_, true} <- {:checkpw, AuthenticationPlug.checkpw(password, user.password_hash)},
|
||||||
{:ok, user} <- Pleroma.Password.maybe_update_password(user, password) do
|
{:ok, user} <- AuthenticationPlug.maybe_update_password(user, password) do
|
||||||
{:ok, user}
|
{:ok, user}
|
||||||
else
|
else
|
||||||
{:error, _reason} = error -> error
|
{:error, _reason} = error -> error
|
||||||
|
@ -59,8 +60,6 @@ def get_registration(%Plug.Conn{
|
||||||
def get_registration(%Plug.Conn{} = _conn), do: {:error, :missing_credentials}
|
def get_registration(%Plug.Conn{} = _conn), do: {:error, :missing_credentials}
|
||||||
|
|
||||||
@doc "Creates Pleroma.User record basing on params and Pleroma.Registration record."
|
@doc "Creates Pleroma.User record basing on params and Pleroma.Registration record."
|
||||||
@spec create_from_registration(Plug.Conn.t(), Registration.t()) ::
|
|
||||||
{:ok, User.t()} | {:error, any()}
|
|
||||||
def create_from_registration(
|
def create_from_registration(
|
||||||
%Plug.Conn{params: %{"authorization" => registration_attrs}},
|
%Plug.Conn{params: %{"authorization" => registration_attrs}},
|
||||||
%Registration{} = registration
|
%Registration{} = registration
|
||||||
|
@ -90,8 +89,6 @@ def create_from_registration(
|
||||||
{:ok, _} <-
|
{:ok, _} <-
|
||||||
Registration.changeset(registration, %{user_id: new_user.id}) |> Repo.update() do
|
Registration.changeset(registration, %{user_id: new_user.id}) |> Repo.update() do
|
||||||
{:ok, new_user}
|
{:ok, new_user}
|
||||||
else
|
|
||||||
err -> err
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ defmodule Pleroma.Web.Auth.TOTPAuthenticator do
|
||||||
alias Pleroma.MFA
|
alias Pleroma.MFA
|
||||||
alias Pleroma.MFA.TOTP
|
alias Pleroma.MFA.TOTP
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
alias Pleroma.Web.Plugs.AuthenticationPlug
|
||||||
|
|
||||||
@doc "Verify code or check backup code."
|
@doc "Verify code or check backup code."
|
||||||
@spec verify(String.t(), User.t()) ::
|
@spec verify(String.t(), User.t()) ::
|
||||||
|
@ -30,7 +31,7 @@ def verify_recovery_code(
|
||||||
code
|
code
|
||||||
)
|
)
|
||||||
when is_list(codes) and is_binary(code) do
|
when is_list(codes) and is_binary(code) do
|
||||||
hash_code = Enum.find(codes, fn hash -> Pleroma.Password.checkpw(code, hash) end)
|
hash_code = Enum.find(codes, fn hash -> AuthenticationPlug.checkpw(code, hash) end)
|
||||||
|
|
||||||
if hash_code do
|
if hash_code do
|
||||||
MFA.invalidate_backup_code(user, hash_code)
|
MFA.invalidate_backup_code(user, hash_code)
|
||||||
|
|
|
@ -177,7 +177,7 @@ defp to_and_cc(draft) do
|
||||||
end
|
end
|
||||||
|
|
||||||
defp context(draft) do
|
defp context(draft) do
|
||||||
context = Utils.make_context(draft)
|
context = Utils.make_context(draft.in_reply_to, draft.in_reply_to_conversation)
|
||||||
%__MODULE__{draft | context: context}
|
%__MODULE__{draft | context: context}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue