Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pleroma
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
normandy
pleroma
Commits
59a76ea4
Commit
59a76ea4
authored
7 years ago
by
kaniini
Committed by
lain
7 years ago
Browse files
Options
Downloads
Patches
Plain Diff
activitypub transmogrifier: rewrite non-http URLs using the object's external URL
Signed-off-by:
lain
<
lain@soykaf.club
>
parent
68aa9a28
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/pleroma/web/activity_pub/transmogrifier.ex
+20
-0
20 additions, 0 deletions
lib/pleroma/web/activity_pub/transmogrifier.ex
test/web/activity_pub/transmogrifier_test.exs
+13
-0
13 additions, 0 deletions
test/web/activity_pub/transmogrifier_test.exs
with
33 additions
and
0 deletions
lib/pleroma/web/activity_pub/transmogrifier.ex
+
20
−
0
View file @
59a76ea4
...
...
@@ -210,11 +210,31 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
def
prepare_outgoing
(%{
"type"
=>
type
}
=
data
)
do
data
=
data
|>
maybe_fix_object_url
|>
Map
.
put
(
"@context"
,
"https://www.w3.org/ns/activitystreams"
)
{
:ok
,
data
}
end
def
maybe_fix_object_url
(
data
)
do
if
is_binary
(
data
[
"object"
])
and
not
String
.
starts_with?
(
data
[
"object"
],
"http"
)
do
case
ActivityPub
.
fetch_object_from_id
(
data
[
"object"
])
do
{
:ok
,
relative_object
}
->
if
relative_object
.
data
[
"external_url"
]
do
data
=
data
|>
Map
.
put
(
"object"
,
relative_object
.
data
[
"external_url"
])
else
data
end
e
->
Logger
.
error
(
"Couldn't fetch
#{
data
[
"object"
]
}
#{
inspect
(
e
)
}
"
)
data
end
else
data
end
end
def
add_hashtags
(
object
)
do
tags
=
(
object
[
"tag"
]
||
[])
|>
Enum
.
map
fn
(
tag
)
->
%{
"href"
=>
Pleroma
.
Web
.
Endpoint
.
url
()
<>
"/tags/
#{
tag
}
"
,
"name"
=>
"#
#{
tag
}
"
,
"type"
=>
"Hashtag"
}
end
...
...
This diff is collapsed.
Click to expand it.
test/web/activity_pub/transmogrifier_test.exs
+
13
−
0
View file @
59a76ea4
defmodule
Pleroma
.
Web
.
ActivityPub
.
TransmogrifierTest
do
use
Pleroma
.
DataCase
alias
Pleroma
.
Web
.
ActivityPub
.
Transmogrifier
alias
Pleroma
.
Web
.
OStatus
alias
Pleroma
.
Activity
alias
Pleroma
.
User
alias
Pleroma
.
Repo
...
...
@@ -220,6 +221,18 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
assert
modified
[
"object"
][
"actor"
]
==
modified
[
"object"
][
"attributedTo"
]
end
test
"it translates ostatus IDs to external URLs"
do
incoming
=
File
.
read!
(
"test/fixtures/incoming_note_activity.xml"
)
{
:ok
,
[
referent_activity
]}
=
OStatus
.
handle_incoming
(
incoming
)
user
=
insert
(
:user
)
{
:ok
,
activity
,
_
}
=
CommonAPI
.
favorite
(
referent_activity
.
id
,
user
)
{
:ok
,
modified
}
=
Transmogrifier
.
prepare_outgoing
(
activity
.
data
)
assert
modified
[
"object"
]
==
"http://gs.example.org:4040/index.php/notice/29"
end
end
describe
"user upgrade"
do
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment