weaken the require image description mrf
This commit is contained in:
parent
0939be5a64
commit
07086a5eeb
1 changed files with 62 additions and 36 deletions
|
@ -5,9 +5,18 @@ index 000000000..3550a30f2
|
||||||
+++ b/.envrc
|
+++ b/.envrc
|
||||||
@@ -0,0 +1 @@
|
@@ -0,0 +1 @@
|
||||||
+use flake
|
+use flake
|
||||||
|
diff --git a/.gitignore b/.gitignore
|
||||||
|
index f9de4ed49..dc3db2257 100644
|
||||||
|
--- a/.gitignore
|
||||||
|
+++ b/.gitignore
|
||||||
|
@@ -1,3 +1,4 @@
|
||||||
|
+.direnv/
|
||||||
|
# App artifacts
|
||||||
|
docs/site
|
||||||
|
*.sw*
|
||||||
diff --git a/flake.lock b/flake.lock
|
diff --git a/flake.lock b/flake.lock
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 000000000..fcb32b26f
|
index 000000000..22ac3721f
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/flake.lock
|
+++ b/flake.lock
|
||||||
@@ -0,0 +1,42 @@
|
@@ -0,0 +1,42 @@
|
||||||
|
@ -15,11 +24,11 @@ index 000000000..fcb32b26f
|
||||||
+ "nodes": {
|
+ "nodes": {
|
||||||
+ "flake-utils": {
|
+ "flake-utils": {
|
||||||
+ "locked": {
|
+ "locked": {
|
||||||
+ "lastModified": 1659877975,
|
+ "lastModified": 1667395993,
|
||||||
+ "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
|
+ "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
|
||||||
+ "owner": "numtide",
|
+ "owner": "numtide",
|
||||||
+ "repo": "flake-utils",
|
+ "repo": "flake-utils",
|
||||||
+ "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
|
+ "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
|
||||||
+ "type": "github"
|
+ "type": "github"
|
||||||
+ },
|
+ },
|
||||||
+ "original": {
|
+ "original": {
|
||||||
|
@ -30,11 +39,11 @@ index 000000000..fcb32b26f
|
||||||
+ },
|
+ },
|
||||||
+ "nixpkgs": {
|
+ "nixpkgs": {
|
||||||
+ "locked": {
|
+ "locked": {
|
||||||
+ "lastModified": 1663141849,
|
+ "lastModified": 1667573297,
|
||||||
+ "narHash": "sha256-7c9PePBWzOSgiXiSaocvQ55egmc6tYULmRaRvCyIdqk=",
|
+ "narHash": "sha256-nPPcRXXqovzJZZQtVJGujMAF+LGNoTp+Q/z5drq+rso=",
|
||||||
+ "owner": "NixOS",
|
+ "owner": "NixOS",
|
||||||
+ "repo": "nixpkgs",
|
+ "repo": "nixpkgs",
|
||||||
+ "rev": "8614d1dd20e05abbc7fc7284bb7431c9e5ff2f37",
|
+ "rev": "dac8adf99ace8480b759dd24a16c9aad2507e6cb",
|
||||||
+ "type": "github"
|
+ "type": "github"
|
||||||
+ },
|
+ },
|
||||||
+ "original": {
|
+ "original": {
|
||||||
|
@ -55,10 +64,10 @@ index 000000000..fcb32b26f
|
||||||
+}
|
+}
|
||||||
diff --git a/flake.nix b/flake.nix
|
diff --git a/flake.nix b/flake.nix
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 000000000..4a0cdee4d
|
index 000000000..56ad90a4a
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/flake.nix
|
+++ b/flake.nix
|
||||||
@@ -0,0 +1,24 @@
|
@@ -0,0 +1,29 @@
|
||||||
+{
|
+{
|
||||||
+ description = "Akkoma dev flake";
|
+ description = "Akkoma dev flake";
|
||||||
+
|
+
|
||||||
|
@ -67,21 +76,26 @@ index 000000000..4a0cdee4d
|
||||||
+ flake-utils.url = "github:numtide/flake-utils";
|
+ flake-utils.url = "github:numtide/flake-utils";
|
||||||
+ };
|
+ };
|
||||||
+
|
+
|
||||||
+ outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system:
|
+ outputs = {
|
||||||
+ let pkgs = import nixpkgs { inherit system; };
|
+ self,
|
||||||
+ in
|
+ nixpkgs,
|
||||||
+ {
|
+ flake-utils,
|
||||||
+ formatter = pkgs.alejandra;
|
+ }:
|
||||||
+ devShells.default = pkgs.mkShell {
|
+ flake-utils.lib.eachDefaultSystem (system: let
|
||||||
+ buildInputs = with pkgs; [
|
+ pkgs = import nixpkgs {inherit system;};
|
||||||
+ file
|
+ in {
|
||||||
+ ];
|
+ formatter = pkgs.alejandra;
|
||||||
+ nativeBuildInputs = with pkgs; [
|
+ devShells.default = pkgs.mkShell {
|
||||||
+ elixir
|
+ buildInputs = with pkgs; [
|
||||||
+ cmake
|
+ file
|
||||||
+ ];
|
+ ];
|
||||||
+ };
|
+ nativeBuildInputs = with pkgs; [
|
||||||
+ });
|
+ elixir
|
||||||
|
+ cmake
|
||||||
|
+ libxcrypt
|
||||||
|
+ ];
|
||||||
|
+ };
|
||||||
|
+ });
|
||||||
+}
|
+}
|
||||||
diff --git a/lib/mix/migrator.ex b/lib/mix/migrator.ex
|
diff --git a/lib/mix/migrator.ex b/lib/mix/migrator.ex
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
|
@ -842,10 +856,10 @@ index 000000000..f3894c8ae
|
||||||
+end
|
+end
|
||||||
diff --git a/lib/pleroma/web/activity_pub/mrf/require_image_description.ex b/lib/pleroma/web/activity_pub/mrf/require_image_description.ex
|
diff --git a/lib/pleroma/web/activity_pub/mrf/require_image_description.ex b/lib/pleroma/web/activity_pub/mrf/require_image_description.ex
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 000000000..eaa3fe695
|
index 000000000..ea7c1ee68
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/lib/pleroma/web/activity_pub/mrf/require_image_description.ex
|
+++ b/lib/pleroma/web/activity_pub/mrf/require_image_description.ex
|
||||||
@@ -0,0 +1,33 @@
|
@@ -0,0 +1,45 @@
|
||||||
+defmodule Pleroma.Web.ActivityPub.MRF.RequireImageDescription do
|
+defmodule Pleroma.Web.ActivityPub.MRF.RequireImageDescription do
|
||||||
+ @moduledoc "MRF policy which removes media without image description"
|
+ @moduledoc "MRF policy which removes media without image description"
|
||||||
+ @behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
+ @behaviour Pleroma.Web.ActivityPub.MRF.Policy
|
||||||
|
@ -855,20 +869,32 @@ index 000000000..eaa3fe695
|
||||||
+ ), do: is_binary(name) and !String.equivalent?(name, "")
|
+ ), do: is_binary(name) and !String.equivalent?(name, "")
|
||||||
+ def is_valid_attachment(_), do: false
|
+ def is_valid_attachment(_), do: false
|
||||||
+
|
+
|
||||||
|
+ def mark_sensitive(object) do
|
||||||
|
+ object |> Map.put("sensitive", true)
|
||||||
|
+ {:ok, object}
|
||||||
|
+ end
|
||||||
|
+
|
||||||
|
+ def correct_attachment(object) do
|
||||||
|
+ if is_valid_attachment(object) do
|
||||||
|
+ {:ok, object}
|
||||||
|
+ else
|
||||||
|
+ mark_sensitive(object)
|
||||||
|
+ end
|
||||||
|
+ end
|
||||||
|
+
|
||||||
+ @impl true
|
+ @impl true
|
||||||
+ def filter(
|
+ def filter(
|
||||||
+ %{"type" => "Create", "object" => %{"attachment" => attachments, "content" => content} = object } = message
|
+ %{"type" => "Create", "object" => %{"attachment" => attachments} = object } = message
|
||||||
+ ) when is_list(attachments) and length(attachments) > 0 and is_binary(content) do
|
+ ) when is_list(attachments) and length(attachments) > 0 do
|
||||||
+ old_length = attachments |> length()
|
+ if attachments |> Enum.all?(fn(attach) -> is_valid_attachment(attach) end) do
|
||||||
+ attachments = attachments |> Enum.filter(fn(attach) -> is_valid_attachment(attach) end)
|
+ {:ok, message}
|
||||||
+ content = if old_length != attachments |> length() do
|
|
||||||
+ content <> "<br/><emph>This post contained media without content description. Offending media has been removed from this post.</emph>";
|
|
||||||
+ else
|
+ else
|
||||||
+ content
|
+ attachments = attachments |> Enum.map(fn v -> correct_attachment(v) end)
|
||||||
|
+ object = object |> Map.update("summary", "Missing media descriptions", fn v -> v <> "; Missing media descriptions" end)
|
||||||
|
+ |> Map.put("attachment", attachments)
|
||||||
|
+ message = message |> Map.put("object", object)
|
||||||
|
+ {:ok, message}
|
||||||
+ end
|
+ end
|
||||||
+ object = object |> Map.put("content", content) |> Map.put("attachment", attachments)
|
|
||||||
+ message = message |> Map.put("object", object)
|
|
||||||
+ {:ok, message}
|
|
||||||
+ end
|
+ end
|
||||||
+
|
+
|
||||||
+ @impl true
|
+ @impl true
|
||||||
|
|
Reference in a new issue