feat(config): migrate Exiftool upload filters in ConfigDB to Exif names

This commit is contained in:
Lain Soykaf 2026-10-27 17:35:32 +04:00
commit bd6602f4ce
No known key found for this signature in database
2 changed files with 105 additions and 0 deletions

View file

@ -0,0 +1,41 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2026 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Repo.Migrations.UploadFilterExiftoolToExif do
use Ecto.Migration
alias Pleroma.ConfigDB
@up %{
Pleroma.Upload.Filter.Exiftool => Pleroma.Upload.Filter.Exif.StripLocation,
Pleroma.Upload.Filter.Exiftool.StripLocation => Pleroma.Upload.Filter.Exif.StripLocation,
Pleroma.Upload.Filter.Exiftool.ReadDescription => Pleroma.Upload.Filter.Exif.ReadDescription
}
@down %{
Pleroma.Upload.Filter.Exif.StripLocation => Pleroma.Upload.Filter.Exiftool.StripLocation,
Pleroma.Upload.Filter.Exif.ReadDescription => Pleroma.Upload.Filter.Exiftool.ReadDescription
}
def up, do: rename_filters(@up)
def down, do: rename_filters(@down)
defp rename_filters(renames) do
case ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Upload}) do
%{value: value} ->
new_value =
Keyword.update(value, :filters, [], fn filters ->
filters
|> Enum.map(&Map.get(renames, &1, &1))
|> Enum.uniq()
end)
ConfigDB.update_or_create(%{group: :pleroma, key: Pleroma.Upload, value: new_value})
_ ->
nil
end
end
end

View file

@ -0,0 +1,64 @@
# Pleroma: A lightweight social networking server
# Copyright © 2017-2026 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Repo.Migrations.UploadFilterExiftoolToExifTest do
use Pleroma.DataCase
import Pleroma.Factory
import Pleroma.Tests.Helpers
alias Pleroma.ConfigDB
setup_all do: require_migration("20261027000000_upload_filter_exiftool_to_exif")
defp filters do
ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Upload}).value[:filters]
end
test "up/0 renames the Exiftool filters", %{migration: migration} do
insert(:config,
group: :pleroma,
key: Pleroma.Upload,
value: [
filters: [
Pleroma.Upload.Filter.Dedupe,
Pleroma.Upload.Filter.Exiftool,
Pleroma.Upload.Filter.Exiftool.StripLocation,
Pleroma.Upload.Filter.Exiftool.ReadDescription
]
]
)
migration.up()
assert filters() == [
Pleroma.Upload.Filter.Dedupe,
Pleroma.Upload.Filter.Exif.StripLocation,
Pleroma.Upload.Filter.Exif.ReadDescription
]
end
test "down/0 restores the Exiftool filters", %{migration: migration} do
insert(:config,
group: :pleroma,
key: Pleroma.Upload,
value: [
filters: [
Pleroma.Upload.Filter.Exif.StripLocation,
Pleroma.Upload.Filter.Exif.ReadDescription
]
]
)
migration.down()
assert filters() == [
Pleroma.Upload.Filter.Exiftool.StripLocation,
Pleroma.Upload.Filter.Exiftool.ReadDescription
]
end
test "up/0 does nothing without a database config", %{migration: migration} do
assert migration.up() == nil
assert ConfigDB.get_by_params(%{group: :pleroma, key: Pleroma.Upload}) == nil
end
end