2021-05-12 18:38:11 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-05-18 20:33:33 +00:00
|
|
|
defmodule Pleroma.Upload.Filter.AnalyzeMetadataTest do
|
2021-05-12 18:38:11 +00:00
|
|
|
use Pleroma.DataCase, async: true
|
2021-05-18 20:33:33 +00:00
|
|
|
alias Pleroma.Upload.Filter.AnalyzeMetadata
|
2021-05-12 18:38:11 +00:00
|
|
|
|
2021-06-08 19:05:13 +00:00
|
|
|
test "adds the dimensions and blurhash for images" do
|
2021-05-12 18:38:11 +00:00
|
|
|
upload = %Pleroma.Upload{
|
|
|
|
name: "an… image.jpg",
|
|
|
|
content_type: "image/jpeg",
|
|
|
|
path: Path.absname("test/fixtures/image.jpg"),
|
|
|
|
tempfile: Path.absname("test/fixtures/image.jpg")
|
|
|
|
}
|
|
|
|
|
2021-06-08 19:49:57 +00:00
|
|
|
{:ok, :filtered, meta} = AnalyzeMetadata.filter(upload)
|
|
|
|
|
|
|
|
assert %{width: 1024, height: 768} = meta
|
|
|
|
assert meta.blurhash
|
2022-07-02 14:05:32 +00:00
|
|
|
# Blurhashes should be a valid base83 string
|
|
|
|
assert meta.blurhash =~ ~r/^[A-Za-z0-9#$%*\+,-\.:;=\?@\[\]\^_{|}~]{6,}$/
|
2021-05-12 18:38:11 +00:00
|
|
|
end
|
2021-06-08 19:02:56 +00:00
|
|
|
|
2021-06-08 19:05:13 +00:00
|
|
|
test "adds the dimensions for videos" do
|
2021-06-08 19:02:56 +00:00
|
|
|
upload = %Pleroma.Upload{
|
|
|
|
name: "coolvideo.mp4",
|
|
|
|
content_type: "video/mp4",
|
|
|
|
path: Path.absname("test/fixtures/video.mp4"),
|
|
|
|
tempfile: Path.absname("test/fixtures/video.mp4")
|
|
|
|
}
|
|
|
|
|
|
|
|
assert {:ok, :filtered, %{width: 480, height: 480}} = AnalyzeMetadata.filter(upload)
|
|
|
|
end
|
2021-05-12 18:38:11 +00:00
|
|
|
end
|