Merge branch 'fix/attachments-cleanup' into 'develop'

Fix attachments cleanup with custom base_url

See merge request pleroma/pleroma!2154
This commit is contained in:
feld 2020-01-28 14:52:57 +00:00
commit d9cb8acd3e
2 changed files with 38 additions and 1 deletions

View file

@ -73,7 +73,11 @@ def perform(
_ -> "" _ -> ""
end end
base_url = Pleroma.Config.get([__MODULE__, :base_url], Pleroma.Web.base_url()) base_url =
String.trim_trailing(
Pleroma.Config.get([Pleroma.Upload, :base_url], Pleroma.Web.base_url()),
"/"
)
file_path = String.trim_leading(href, "#{base_url}/#{prefix}") file_path = String.trim_leading(href, "#{base_url}/#{prefix}")

View file

@ -177,6 +177,39 @@ test "with objects that have legacy data.url attribute" do
assert {:ok, []} == File.ls("#{uploads_dir}/#{path}") assert {:ok, []} == File.ls("#{uploads_dir}/#{path}")
end end
test "With custom base_url" do
Pleroma.Config.put([Pleroma.Upload, :uploader], Pleroma.Uploaders.Local)
Pleroma.Config.put([Pleroma.Upload, :base_url], "https://sub.domain.tld/dir/")
file = %Plug.Upload{
content_type: "image/jpg",
path: Path.absname("test/fixtures/image.jpg"),
filename: "an_image.jpg"
}
user = insert(:user)
{:ok, %Object{} = attachment} =
Pleroma.Web.ActivityPub.ActivityPub.upload(file, actor: user.ap_id)
%{data: %{"attachment" => [%{"url" => [%{"href" => href}]}]}} =
note = insert(:note, %{user: user, data: %{"attachment" => [attachment.data]}})
uploads_dir = Pleroma.Config.get!([Pleroma.Uploaders.Local, :uploads])
path = href |> Path.dirname() |> Path.basename()
assert {:ok, ["an_image.jpg"]} == File.ls("#{uploads_dir}/#{path}")
Object.delete(note)
ObanHelpers.perform(all_enqueued(worker: Pleroma.Workers.AttachmentsCleanupWorker))
assert Object.get_by_id(attachment.id) == nil
assert {:ok, []} == File.ls("#{uploads_dir}/#{path}")
end
end end
describe "normalizer" do describe "normalizer" do