Try to use custom filename in attachment_links
This commit is contained in:
parent
3000f3ff7c
commit
019c211353
@ -91,7 +91,7 @@ defmodule Pleroma.Upload do
|
||||
}
|
||||
],
|
||||
"name" => description,
|
||||
"filename" => Map.get(opts, :filename) || upload.name
|
||||
"filename" => Map.get(opts, :filename)
|
||||
}}
|
||||
else
|
||||
{:description_limit, _} ->
|
||||
|
||||
@ -255,7 +255,7 @@ defmodule Pleroma.Web.CommonAPI.Utils do
|
||||
end
|
||||
|
||||
defp build_attachment_link(%{"url" => [%{"href" => href} | _]} = attachment) do
|
||||
name = attachment["name"] || URI.decode(Path.basename(href))
|
||||
name = attachment["filename"] || attachment["name"] || URI.decode(Path.basename(href))
|
||||
href = MediaProxy.url(href)
|
||||
"<a href=\"#{href}\" class='attachment'>#{shortname(name)}</a>"
|
||||
end
|
||||
|
||||
@ -62,7 +62,7 @@ defmodule Pleroma.UploadTest do
|
||||
"type" => "Link"
|
||||
}
|
||||
],
|
||||
"filename" => "image.jpg"
|
||||
"filename" => nil
|
||||
}}
|
||||
|
||||
Task.await(Agent.get(TestUploaderSuccess, fn task_pid -> task_pid end))
|
||||
@ -139,7 +139,7 @@ defmodule Pleroma.UploadTest do
|
||||
assert data["filename"] == filename
|
||||
end
|
||||
|
||||
test "saves default filename if opts don't have one" do
|
||||
test "sets filename to nil if opts don't have one" do
|
||||
File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
|
||||
|
||||
desc = "sample file"
|
||||
@ -154,7 +154,7 @@ defmodule Pleroma.UploadTest do
|
||||
{:ok, data} = Upload.store(file, description: desc)
|
||||
|
||||
assert data["name"] == desc
|
||||
assert data["filename"] == filename
|
||||
refute data["filename"]
|
||||
end
|
||||
|
||||
@tag capture_log: true
|
||||
|
||||
@ -126,6 +126,38 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
||||
)
|
||||
end
|
||||
|
||||
test "posting a status with an attachment", %{user: user, conn: conn} do
|
||||
clear_config([:instance, :attachment_links], true)
|
||||
filename = "an_image.jpg"
|
||||
custom_filename = "look at this.jpg"
|
||||
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: filename
|
||||
}
|
||||
|
||||
{:ok, upload} =
|
||||
ActivityPub.upload(file,
|
||||
actor: user.ap_id,
|
||||
description: "test image",
|
||||
filename: custom_filename
|
||||
)
|
||||
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/statuses", %{
|
||||
"status" => "cofe",
|
||||
"spoiler_text" => "2hu",
|
||||
"media_ids" => [to_string(upload.id)]
|
||||
})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert String.ends_with?(response["content"], "#{filename}\">#{custom_filename}</a>")
|
||||
assert length(response["media_attachments"]) == 1
|
||||
end
|
||||
|
||||
test "it fails to create a status if `expires_in` is less or equal than an hour", %{
|
||||
conn: conn
|
||||
} do
|
||||
@ -166,22 +198,28 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
||||
end
|
||||
|
||||
test "posting an undefined status with an attachment", %{user: user, conn: conn} do
|
||||
clear_config([:instance, :attachment_links], true)
|
||||
filename = "an_image.jpg"
|
||||
description = "test image"
|
||||
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpeg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.jpg"
|
||||
filename: filename
|
||||
}
|
||||
|
||||
{:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
|
||||
{:ok, upload} = ActivityPub.upload(file, actor: user.ap_id, description: description)
|
||||
|
||||
conn =
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/statuses", %{
|
||||
"media_ids" => [to_string(upload.id)]
|
||||
})
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert json_response_and_validate_schema(conn, 200)
|
||||
assert String.ends_with?(response["content"], "#{filename}\">#{description}</a>")
|
||||
assert length(response["media_attachments"]) == 1
|
||||
end
|
||||
|
||||
test "replying to a status", %{user: user, conn: conn} do
|
||||
|
||||
Loading…
Reference in New Issue
Block a user