Use EXIF data of image to prefill image description

During attachment upload Pleroma returns a "description" field. Pleroma-fe has an MR to use that to pre-fill the image description field, <https://git.pleroma.social/pleroma/pleroma-fe/-/merge_requests/1399>

* This MR allows Pleroma to read the EXIF data during upload and return the description to the FE
    * If a description is already present (e.g. because a previous module added it), it will use that
    * Otherwise it will read from the EXIF data. First it will check -ImageDescription, if that's empty, it will check -iptc:Caption-Abstract
    * If no description is found, it will simply return nil, just like before
* When people set up a new instance, they will be asked if they want to read metadata and this module will be activated if so

This was taken from an MR i did on Pleroma and isn't finished yet.
This commit is contained in:
Ilja 2022-02-14 13:14:25 +01:00
commit cd316d7269
11 changed files with 219 additions and 14 deletions

View file

@ -35,6 +35,7 @@ defmodule Mix.Tasks.Pleroma.Instance do
listen_ip: :string,
listen_port: :string,
strip_uploads: :string,
read_uploads_data: :string,
anonymize_uploads: :string,
dedupe_uploads: :string
],
@ -178,6 +179,23 @@ defmodule Mix.Tasks.Pleroma.Instance do
strip_uploads_default
) === "y"
{read_uploads_data_message, read_uploads_data_default} =
if Pleroma.Utils.command_available?("exiftool") do
{"Do you want to read data from uploaded files so clients can use it to prefill fields like image description? This requires exiftool, it was detected as installed. (y/n)",
"y"}
else
{"Do you want to read data from uploaded files so clients can use it to prefill fields like image description? This requires exiftool, it was detected as not installed, please install it if you answer yes. (y/n)",
"n"}
end
read_uploads_data =
get_option(
options,
:read_uploads_data,
read_uploads_data_message,
read_uploads_data_default
) === "y"
anonymize_uploads =
get_option(
options,
@ -230,6 +248,7 @@ defmodule Mix.Tasks.Pleroma.Instance do
upload_filters:
upload_filters(%{
strip: strip_uploads,
read_data: read_uploads_data,
anonymize: anonymize_uploads,
dedupe: dedupe_uploads
})
@ -303,6 +322,13 @@ defmodule Mix.Tasks.Pleroma.Instance do
[]
end
enabled_filters =
if filters.read_data do
enabled_filters ++ [Pleroma.Upload.Filter.ExiftoolReadData]
else
enabled_filters
end
enabled_filters =
if filters.anonymize do
enabled_filters ++ [Pleroma.Upload.Filter.AnonymizeFilename]