This commit is contained in:
Ekaterina Vaartis 2026-11-04 20:18:25 +03:00
commit f8195b356d
4 changed files with 17 additions and 12 deletions

View file

@ -34,10 +34,10 @@ defmodule Pleroma.Upload do
""" """
alias Ecto.UUID alias Ecto.UUID
alias Pleroma.Repo
alias Pleroma.Object
alias Pleroma.Maps alias Pleroma.Maps
alias Pleroma.Object
alias Pleroma.Pagination alias Pleroma.Pagination
alias Pleroma.Repo
alias Pleroma.Utils.URIEncoding alias Pleroma.Utils.URIEncoding
alias Pleroma.Web.ActivityPub.Utils alias Pleroma.Web.ActivityPub.Utils
@ -326,11 +326,13 @@ defmodule Pleroma.Upload do
# Ugly as sin, but I could not figure out a better way to do this in ecto # Ugly as sin, but I could not figure out a better way to do this in ecto
# This tries to find any objects with this attachment # This tries to find any objects with this attachment
# This DOES NOT handle chat messages and SKIPS them, because they have attachments as an object instead of an array # This DOES NOT handle chat messages and SKIPS them,
# because they have attachments as an object instead of an array
Repo.query!( Repo.query!(
""" """
SELECT * FROM SELECT * FROM
(SELECT objects.data->>'id' AS id, jsonb_array_elements(objects.data->'attachment') as json_attachments FROM objects WHERE jsonb_typeof(objects.data->'attachment') = 'array') (SELECT objects.data->>'id' AS id, jsonb_array_elements(objects.data->'attachment') as json_attachments FROM objects
WHERE jsonb_typeof(objects.data->'attachment') = 'array')
WHERE STARTS_WITH(json_attachments->'url'->0->>'href', $1) WHERE STARTS_WITH(json_attachments->'url'->0->>'href', $1)
""", """,
[clean_href] [clean_href]
@ -343,7 +345,10 @@ defmodule Pleroma.Upload do
where: where:
fragment("(?)->>'type' = ?", obj.data, "Document") and fragment("(?)->>'type' = ?", obj.data, "Document") and
fragment("(?)->>'actor' = ?", obj.data, ^user.ap_id), fragment("(?)->>'actor' = ?", obj.data, ^user.ap_id),
order_by: [desc: obj.id], limit: ^limit, offset: ^offset order_by: [desc: obj.id],
) |> Repo.all() limit: ^limit,
offset: ^offset
)
|> Repo.all()
end end
end end

View file

@ -6,8 +6,8 @@ defmodule Pleroma.Web.ApiSpec.PleromaUtilOperation do
alias OpenApiSpex.Operation alias OpenApiSpex.Operation
alias OpenApiSpex.Schema alias OpenApiSpex.Schema
alias Pleroma.Web.ApiSpec.Schemas.ApiError alias Pleroma.Web.ApiSpec.Schemas.ApiError
alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
alias Pleroma.Web.ApiSpec.Schemas.Attachment alias Pleroma.Web.ApiSpec.Schemas.Attachment
alias Pleroma.Web.ApiSpec.Schemas.BooleanLike
import Pleroma.Web.ApiSpec.Helpers import Pleroma.Web.ApiSpec.Helpers

View file

@ -6,8 +6,8 @@ defmodule Pleroma.Web.MastodonAPI.MediaController do
use Pleroma.Web, :controller use Pleroma.Web, :controller
alias Pleroma.Object alias Pleroma.Object
alias Pleroma.User
alias Pleroma.Repo alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.Plugs.OAuthScopesPlug alias Pleroma.Web.Plugs.OAuthScopesPlug

View file

@ -10,8 +10,8 @@ defmodule Pleroma.Web.PleromaAPI.UtilController do
alias Pleroma.Config alias Pleroma.Config
alias Pleroma.Emoji alias Pleroma.Emoji
alias Pleroma.Healthcheck alias Pleroma.Healthcheck
alias Pleroma.User
alias Pleroma.Pagination alias Pleroma.Pagination
alias Pleroma.User
alias Pleroma.Utils.URIEncoding alias Pleroma.Utils.URIEncoding
alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.Auth.WrapperAuthenticator, as: Authenticator alias Pleroma.Web.Auth.WrapperAuthenticator, as: Authenticator
@ -285,7 +285,7 @@ defmodule Pleroma.Web.PleromaAPI.UtilController do
Pleroma.Upload.list_uploaded_by(user, offset, 50) Pleroma.Upload.list_uploaded_by(user, offset, 50)
|> Enum.map(fn %Pleroma.Object{ |> Enum.map(fn %Pleroma.Object{
id: id, id: id,
data: %{"url" => [mediaUrl], "name" => name}, data: %{"url" => [media_url], "name" => name},
inserted_at: uploaded inserted_at: uploaded
} -> } ->
%{ %{
@ -293,8 +293,8 @@ defmodule Pleroma.Web.PleromaAPI.UtilController do
attachment: %{ attachment: %{
description: name, description: name,
id: to_string(id), id: to_string(id),
url: mediaUrl["href"], url: media_url["href"],
pleroma: %{mime_type: mediaUrl["mediaType"]}, pleroma: %{mime_type: media_url["mediaType"]},
type: "unknown" type: "unknown"
} }
} }