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: filter exif data #187 --- lib/pleroma/upload.ex | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib') 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 @@ defmodule Pleroma.Upload 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) -- cgit v1.2.3 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: format... --- lib/pleroma/upload.ex | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib') 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 @@ defmodule Pleroma.Upload 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 -- cgit v1.2.3 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: do the filtering --- lib/pleroma/upload.ex | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib') 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 @@ defmodule Pleroma.Upload do File.cp!(file.path, result_file) end + strip_exif_data(content_type, file.path) + %{ "type" => "Image", "url" => [ @@ -67,6 +69,8 @@ defmodule Pleroma.Upload do File.rename(uuidpath, result_file) end + strip_exif_data(content_type, uuidpath) + %{ "type" => "Image", "url" => [ @@ -80,11 +84,12 @@ defmodule Pleroma.Upload 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 -- cgit v1.2.3 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: maybe I should learn proper elixir ;D --- lib/pleroma/upload.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') 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 @@ defmodule Pleroma.Upload 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 -- cgit v1.2.3 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: use the correct end file --- lib/pleroma/upload.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') 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 @@ defmodule Pleroma.Upload 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 @@ defmodule Pleroma.Upload do File.rename(uuidpath, result_file) end - strip_exif_data(content_type, uuidpath) + strip_exif_data(content_type, result_file) %{ "type" => "Image", -- cgit v1.2.3