From cb21bf5fc225899ad6cf87f5ab0253506cf0531e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20Mah=C3=A9?= Date: Tue, 26 Jun 2018 13:45:47 -0700 Subject: [PATCH 1/7] filter exif data #187 --- config/config.exs | 4 +++- lib/pleroma/upload.ex | 8 ++++++++ mix.exs | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/config/config.exs b/config/config.exs index cf6cbaa9d..fd9662aea 100644 --- a/config/config.exs +++ b/config/config.exs @@ -10,7 +10,9 @@ config :pleroma, Pleroma.Repo, types: Pleroma.PostgresTypes -config :pleroma, Pleroma.Upload, uploads: "uploads" +config :pleroma, Pleroma.Upload, + uploads: "uploads", + strip_exif: false # Configures the endpoint config :pleroma, Pleroma.Web.Endpoint, diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index 43df0d418..dee281f5b 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -80,6 +80,14 @@ def store(%{"img" => "data:image/" <> image_data}, should_dedupe) do } end + def strip_exif_data(file) do + settings = Application.get_env(:pleroma, Pleroma.Upload) + @do_strip = Keyword.fetch!(settings, :strip_exif) + if @do_strip == true do + Mogrify.open(file) |> Mogrify.custom("strip") |> Mogrify.save(in_place: true) + end + end + def upload_path do settings = Application.get_env(:pleroma, Pleroma.Upload) Keyword.fetch!(settings, :uploads) diff --git a/mix.exs b/mix.exs index 281687294..cc279a7f9 100644 --- a/mix.exs +++ b/mix.exs @@ -47,7 +47,8 @@ defp deps do {:jason, "~> 1.0"}, {:ex_machina, "~> 2.0", only: :test}, {:credo, "~> 0.7", only: [:dev, :test]}, - {:mock, "~> 0.3.0", only: :test} + {:mock, "~> 0.3.0", only: :test}, + {:mogrify, "~> 0.6.1"} ] end From c67cf8e9af3ab9b52f34387a686a68ee4e1554b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20Mah=C3=A9?= Date: Tue, 26 Jun 2018 13:49:57 -0700 Subject: [PATCH 2/7] format... --- config/config.exs | 2 +- lib/pleroma/upload.ex | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/config/config.exs b/config/config.exs index fd9662aea..33b7f098e 100644 --- a/config/config.exs +++ b/config/config.exs @@ -10,7 +10,7 @@ config :pleroma, Pleroma.Repo, types: Pleroma.PostgresTypes -config :pleroma, Pleroma.Upload, +config :pleroma, Pleroma.Upload, uploads: "uploads", strip_exif: false diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index dee281f5b..e412e43fa 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -83,8 +83,9 @@ def store(%{"img" => "data:image/" <> image_data}, should_dedupe) do def strip_exif_data(file) do settings = Application.get_env(:pleroma, Pleroma.Upload) @do_strip = Keyword.fetch!(settings, :strip_exif) + if @do_strip == true do - Mogrify.open(file) |> Mogrify.custom("strip") |> Mogrify.save(in_place: true) + Mogrify.open(file) |> Mogrify.custom("strip") |> Mogrify.save(in_place: true) end end From d8d43f1173aaea677a74aee6315d1195d59197e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20Mah=C3=A9?= Date: Tue, 26 Jun 2018 14:03:23 -0700 Subject: [PATCH 3/7] do the filtering --- lib/pleroma/upload.ex | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index e412e43fa..1640c1f9c 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -18,6 +18,8 @@ def store(%Plug.Upload{} = file, should_dedupe) do File.cp!(file.path, result_file) end + strip_exif_data(content_type, file.path) + %{ "type" => "Image", "url" => [ @@ -67,6 +69,8 @@ def store(%{"img" => "data:image/" <> image_data}, should_dedupe) do File.rename(uuidpath, result_file) end + strip_exif_data(content_type, uuidpath) + %{ "type" => "Image", "url" => [ @@ -80,11 +84,12 @@ def store(%{"img" => "data:image/" <> image_data}, should_dedupe) do } end - def strip_exif_data(file) do + def strip_exif_data(content_type, file) do settings = Application.get_env(:pleroma, Pleroma.Upload) @do_strip = Keyword.fetch!(settings, :strip_exif) + [filetype, ext] = String.split(content_type, "/") - if @do_strip == true do + if filetype == "image" and @do_strip == true do Mogrify.open(file) |> Mogrify.custom("strip") |> Mogrify.save(in_place: true) end end From 2df0fd1462c7fed0fe80bafecdfc72309025c943 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20Mah=C3=A9?= Date: Tue, 26 Jun 2018 14:16:28 -0700 Subject: [PATCH 4/7] mogrify mix.lock --- mix.lock | 1 + 1 file changed, 1 insertion(+) diff --git a/mix.lock b/mix.lock index 2a826111c..9ae8fe0ac 100644 --- a/mix.lock +++ b/mix.lock @@ -25,6 +25,7 @@ "mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], [], "hexpm"}, "mochiweb": {:hex, :mochiweb, "2.15.0", "e1daac474df07651e5d17cc1e642c4069c7850dc4508d3db7263a0651330aacc", [:rebar3], [], "hexpm"}, "mock": {:hex, :mock, "0.3.1", "994f00150f79a0ea50dc9d86134cd9ebd0d177ad60bd04d1e46336cdfdb98ff9", [:mix], [{:meck, "~> 0.8.8", [hex: :meck, repo: "hexpm", optional: false]}], "hexpm"}, + "mogrify": {:hex, :mogrify, "0.6.1", "de1b527514f2d95a7bbe9642eb556061afb337e220cf97adbf3a4e6438ed70af", [:mix], [], "hexpm"}, "parse_trans": {:hex, :parse_trans, "3.2.0", "2adfa4daf80c14dc36f522cf190eb5c4ee3e28008fc6394397c16f62a26258c2", [:rebar3], [], "hexpm"}, "pbkdf2_elixir": {:hex, :pbkdf2_elixir, "0.12.3", "6706a148809a29c306062862c803406e88f048277f6e85b68faf73291e820b84", [:mix], [], "hexpm"}, "phoenix": {:hex, :phoenix, "1.3.2", "2a00d751f51670ea6bc3f2ba4e6eb27ecb8a2c71e7978d9cd3e5de5ccf7378bd", [:mix], [{:cowboy, "~> 1.0", [hex: :cowboy, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:plug, "~> 1.3.3 or ~> 1.4", [hex: :plug, repo: "hexpm", optional: false]}, {:poison, "~> 2.2 or ~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"}, From ca63585a329f0afa02f7d539328f5fb3485d2a29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20Mah=C3=A9?= Date: Tue, 26 Jun 2018 14:35:35 -0700 Subject: [PATCH 5/7] maybe I should learn proper elixir ;D --- lib/pleroma/upload.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index 1640c1f9c..45fac9060 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -86,10 +86,10 @@ def store(%{"img" => "data:image/" <> image_data}, should_dedupe) do def strip_exif_data(content_type, file) do settings = Application.get_env(:pleroma, Pleroma.Upload) - @do_strip = Keyword.fetch!(settings, :strip_exif) + do_strip = Keyword.fetch!(settings, :strip_exif) [filetype, ext] = String.split(content_type, "/") - if filetype == "image" and @do_strip == true do + if filetype == "image" and do_strip == true do Mogrify.open(file) |> Mogrify.custom("strip") |> Mogrify.save(in_place: true) end end From dc8ace29d12e8022ef7381d273724d7e5e7e3a19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20Mah=C3=A9?= Date: Tue, 26 Jun 2018 15:09:45 -0700 Subject: [PATCH 6/7] use the correct end file --- lib/pleroma/upload.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pleroma/upload.ex b/lib/pleroma/upload.ex index 45fac9060..dd2bbab9f 100644 --- a/lib/pleroma/upload.ex +++ b/lib/pleroma/upload.ex @@ -18,7 +18,7 @@ def store(%Plug.Upload{} = file, should_dedupe) do File.cp!(file.path, result_file) end - strip_exif_data(content_type, file.path) + strip_exif_data(content_type, result_file) %{ "type" => "Image", @@ -69,7 +69,7 @@ def store(%{"img" => "data:image/" <> image_data}, should_dedupe) do File.rename(uuidpath, result_file) end - strip_exif_data(content_type, uuidpath) + strip_exif_data(content_type, result_file) %{ "type" => "Image", From c06a5af386a3cdfeda0b2c21963d9200fb7d6c89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tristan=20Mah=C3=A9?= Date: Thu, 28 Jun 2018 10:49:44 -0700 Subject: [PATCH 7/7] CONFIGURATION.md: add doc about upload and strip_exif --- CONFIGURATION.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/CONFIGURATION.md b/CONFIGURATION.md index 3f0ecafb5..51a76d1b7 100644 --- a/CONFIGURATION.md +++ b/CONFIGURATION.md @@ -13,6 +13,21 @@ Instead, overload the settings by editing the following files: * `dev.secret.exs`: custom additional configuration for `MIX_ENV=dev` * `prod.secret.exs`: custom additional configuration for `MIX_ENV=prod` +## Uploads configuration + +To configure where to upload files, and wether or not +you want to remove automatically EXIF data from pictures +being uploaded. + + config :pleroma, Pleroma.Upload, + uploads: "uploads", + strip_exif: false + +* `uploads`: where to put the uploaded files, relative to pleroma's main directory. +* `strip_exif`: whether or not to remove EXIF data from uploaded pics automatically. + This needs Imagemagick installed on the system ( apt install imagemagick ). + + ## Block functionality config :pleroma, :activitypub,