fix mediaType of object
This commit is contained in:
parent
5e365448f3
commit
c5c09fc61b
|
@ -35,6 +35,7 @@ def fix_object(object, options \\ []) do
|
|||
|> fix_actor
|
||||
|> fix_url
|
||||
|> fix_attachments
|
||||
|> fix_media_type
|
||||
|> fix_context
|
||||
|> fix_in_reply_to(options)
|
||||
|> fix_emoji
|
||||
|
@ -357,6 +358,12 @@ def fix_type(%{"inReplyTo" => reply_id, "name" => _} = object, options)
|
|||
|
||||
def fix_type(object, _), do: object
|
||||
|
||||
defp fix_media_type(%{"mediaType" => _} = object) do
|
||||
Map.put(object, "mediaType", "text/html")
|
||||
end
|
||||
|
||||
defp fix_media_type(object), do: object
|
||||
|
||||
defp mastodon_follow_hack(%{"id" => id, "actor" => follower_id}, followed) do
|
||||
with true <- id =~ "follows",
|
||||
%User{local: true} = follower <- User.get_cached_by_ap_id(follower_id),
|
||||
|
@ -1207,18 +1214,24 @@ def add_attributed_to(object) do
|
|||
|
||||
def prepare_attachments(object) do
|
||||
attachments =
|
||||
(object["attachment"] || [])
|
||||
object
|
||||
|> Map.get("attachment", [])
|
||||
|> Enum.map(fn data ->
|
||||
[%{"mediaType" => media_type, "href" => href} | _] = data["url"]
|
||||
%{"url" => href, "mediaType" => media_type, "name" => data["name"], "type" => "Document"}
|
||||
|
||||
%{
|
||||
"url" => href,
|
||||
"mediaType" => media_type,
|
||||
"name" => data["name"],
|
||||
"type" => "Document"
|
||||
}
|
||||
end)
|
||||
|
||||
Map.put(object, "attachment", attachments)
|
||||
end
|
||||
|
||||
def strip_internal_fields(object) do
|
||||
object
|
||||
|> Map.drop(Pleroma.Constants.object_internal_fields())
|
||||
Map.drop(object, Pleroma.Constants.object_internal_fields())
|
||||
end
|
||||
|
||||
defp strip_internal_tags(%{"tag" => tags} = object) do
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1 @@
|
|||
{"type":"Person","id":"https://bittube.video/accounts/hanimated.moh","following":"https://bittube.video/accounts/hanimated.moh/following","followers":"https://bittube.video/accounts/hanimated.moh/followers","playlists":"https://bittube.video/accounts/hanimated.moh/playlists","inbox":"https://bittube.video/accounts/hanimated.moh/inbox","outbox":"https://bittube.video/accounts/hanimated.moh/outbox","preferredUsername":"hanimated.moh","url":"https://bittube.video/accounts/hanimated.moh","name":"Nosat","endpoints":{"sharedInbox":"https://bittube.video/inbox"},"publicKey":{"id":"https://bittube.video/accounts/hanimated.moh#main-key","owner":"https://bittube.video/accounts/hanimated.moh","publicKeyPem":"-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwuoQT+4uyAboQcf/okCM\nFqUS/LuqFc2888OSKZFAz00Op/dyOB/pkr1+QLxbl8ZGiUWhmnmhNwmmd3tbhSsC\nvLv9Mz/YaWQPYLfRS/s/7iIxdniC4lo/YgicOrzcvetHmk1feOg5vb5/yc+bgUSm\nOk+L4azqXP9GmZyofzvufT65bUmzQRFXP19eL55YZWvZDaC81QAfRXsqtCqbehtF\nQNOjGhnl6a7Kfe8KprRDPV/3WvvFjftnNO2qenIIOFLLeznkQ0ELP6lyb9pvv/1C\n2/GRh2BwmgVlCTw1kTxLSdj80BFX5P8AudSiIx079lVkhamEhzsNLkMpQFqWAAlg\nrQIDAQAB\n-----END PUBLIC KEY-----"},"icon":{"type":"Image","mediaType":"image/jpeg","url":"https://bittube.video/lazy-static/avatars/84b8acc3-e48b-4642-a9f4-360a4499579b.jpg"},"@context":["https://www.w3.org/ns/activitystreams","https://w3id.org/security/v1",{"RsaSignature2017":"https://w3id.org/security#RsaSignature2017","pt":"https://joinpeertube.org/ns#","sc":"http://schema.org#","Hashtag":"as:Hashtag","uuid":"sc:identifier","category":"sc:category","licence":"sc:license","subtitleLanguage":"sc:subtitleLanguage","sensitive":"as:sensitive","language":"sc:inLanguage","expires":"sc:expires","CacheFile":"pt:CacheFile","Infohash":"pt:Infohash","originallyPublishedAt":"sc:datePublished","views":{"@type":"sc:Number","@id":"pt:views"},"state":{"@type":"sc:Number","@id":"pt:state"},"size":{"@type":"sc:Number","@id":"pt:size"},"fps":{"@type":"sc:Number","@id":"pt:fps"},"startTimestamp":{"@type":"sc:Number","@id":"pt:startTimestamp"},"stopTimestamp":{"@type":"sc:Number","@id":"pt:stopTimestamp"},"position":{"@type":"sc:Number","@id":"pt:position"},"commentsEnabled":{"@type":"sc:Boolean","@id":"pt:commentsEnabled"},"downloadEnabled":{"@type":"sc:Boolean","@id":"pt:downloadEnabled"},"waitTranscoding":{"@type":"sc:Boolean","@id":"pt:waitTranscoding"},"support":{"@type":"sc:Text","@id":"pt:support"}},{"likes":{"@id":"as:likes","@type":"@id"},"dislikes":{"@id":"as:dislikes","@type":"@id"},"playlists":{"@id":"pt:playlists","@type":"@id"},"shares":{"@id":"as:shares","@type":"@id"},"comments":{"@id":"as:comments","@type":"@id"}}],"summary":null}
|
|
@ -308,6 +308,22 @@ def get("https://peertube.moe/videos/watch/df5f464b-be8d-46fb-ad81-2d4c2d1630e3"
|
|||
}}
|
||||
end
|
||||
|
||||
def get("https://bittube.video/accounts/hanimated.moh", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/hanimated.json")
|
||||
}}
|
||||
end
|
||||
|
||||
def get("https://bittube.video/videos/watch/2aad7dfb-5c75-4ee6-a9ed-08436af0558b", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 200,
|
||||
body: File.read!("test/fixtures/tesla_mock/bittube-video.json")
|
||||
}}
|
||||
end
|
||||
|
||||
def get("https://mobilizon.org/events/252d5816-00a3-4a89-a66f-15bf65c33e39", _, _, [
|
||||
{"accept", "application/activity+json"}
|
||||
]) do
|
||||
|
|
|
@ -1221,6 +1221,15 @@ test "it rejects activities without a valid ID" do
|
|||
:error = Transmogrifier.handle_incoming(data)
|
||||
end
|
||||
|
||||
test "it remaps mediaType of object" do
|
||||
{:ok, object} =
|
||||
Fetcher.fetch_object_from_id(
|
||||
"https://bittube.video/videos/watch/2aad7dfb-5c75-4ee6-a9ed-08436af0558b"
|
||||
)
|
||||
|
||||
assert object.data["mediaType"] == "text/html"
|
||||
end
|
||||
|
||||
test "it remaps video URLs as attachments if necessary" do
|
||||
{:ok, object} =
|
||||
Fetcher.fetch_object_from_id(
|
||||
|
|
Loading…
Reference in New Issue