Attachments: Have the mediaType on the root, too.
authorlain <lain@soykaf.club>
Thu, 21 May 2020 13:08:56 +0000 (15:08 +0200)
committerlain <lain@soykaf.club>
Thu, 21 May 2020 13:08:56 +0000 (15:08 +0200)
lib/pleroma/upload.ex
test/web/activity_pub/object_validator_test.exs

index 1be1a3a5b3e03c371b89549374b8cf9579187e0c..797555bffa324643d7105450f21cbc1090304c39 100644 (file)
@@ -67,6 +67,7 @@ defmodule Pleroma.Upload do
       {:ok,
        %{
          "type" => opts.activity_type,
+         "mediaType" => upload.content_type,
          "url" => [
            %{
              "type" => "Link",
index ed6b84e8eb09d4336b41e5e8499eeffe89c82c99..f9990bd2cc29be082ff9367a946a5cdee5224582 100644 (file)
@@ -25,6 +25,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidatorTest do
       assert {:ok, attachment} =
                AttachmentValidator.cast_and_validate(attachment)
                |> Ecto.Changeset.apply_action(:insert)
+
+      assert attachment.mediaType == "application/octet-stream"
     end
 
     test "it turns mastodon attachments into our attachments" do
@@ -48,6 +50,27 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidatorTest do
                  mediaType: "image/jpeg"
                }
              ] = attachment.url
+
+      assert attachment.mediaType == "image/jpeg"
+    end
+
+    test "it handles our own uploads" do
+      user = insert(:user)
+
+      file = %Plug.Upload{
+        content_type: "image/jpg",
+        path: Path.absname("test/fixtures/image.jpg"),
+        filename: "an_image.jpg"
+      }
+
+      {:ok, attachment} = ActivityPub.upload(file, actor: user.ap_id)
+
+      {:ok, attachment} =
+        attachment.data
+        |> AttachmentValidator.cast_and_validate()
+        |> Ecto.Changeset.apply_action(:insert)
+
+      assert attachment.mediaType == "image/jpeg"
     end
   end