Merge remote-tracking branch 'upstream/develop' into feature/filter_exif
authorTristan Mahé <gled@remote-shell.net>
Fri, 20 Jul 2018 00:44:18 +0000 (17:44 -0700)
committerTristan Mahé <gled@remote-shell.net>
Fri, 20 Jul 2018 00:44:18 +0000 (17:44 -0700)
CONFIGURATION.md
config/config.exs
lib/pleroma/upload.ex
mix.exs
mix.lock

index 3f0ecafb5c514eaa268a8a4c40831568b80b0e91..51a76d1b7afac9af6da2d6b8918e8ce77310bd2f 100644 (file)
@@ -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,
index 922acea4be41eafa80aef7a7f8a670b9d7f024b0..3a730134882ce3192a5a7781eb7ae15369bd59c8 100644 (file)
@@ -10,7 +10,9 @@ config :pleroma, ecto_repos: [Pleroma.Repo]
 
 config :pleroma, Pleroma.Repo, types: Pleroma.PostgresTypes
 
-config :pleroma, Pleroma.Upload, uploads: "uploads"
+config :pleroma, Pleroma.Upload,
+  uploads: "uploads",
+  strip_exif: false
 
 config :pleroma, :emoji, shortcode_globs: ["/emoji/custom/**/*.png"]
 
index 92a89e2961b72e3d5a2364ed0677f93b6906d1fd..408a3fc560e81958bdf0f19ce3aae85e814df273 100644 (file)
@@ -18,6 +18,8 @@ defmodule Pleroma.Upload do
       File.cp!(file.path, result_file)
     end
 
+    strip_exif_data(content_type, result_file)
+
     %{
       "type" => "Document",
       "url" => [
@@ -67,6 +69,8 @@ defmodule Pleroma.Upload do
       File.rename(uuidpath, result_file)
     end
 
+    strip_exif_data(content_type, result_file)
+
     %{
       "type" => "Image",
       "url" => [
@@ -80,6 +84,16 @@ defmodule Pleroma.Upload do
     }
   end
 
+  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 filetype == "image" and 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 28168729486989c62d36c00a079e5d969f091739..cc279a7f9daad550e22e365e75954769727bd166 100644 (file)
--- a/mix.exs
+++ b/mix.exs
@@ -47,7 +47,8 @@ defmodule Pleroma.Mixfile 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
 
index 2a826111c63efdcf96ed1e1930455507c7181509..9ae8fe0ac49c5ad3cd5132529cc3c4a9f51572ff 100644 (file)
--- 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"},