Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
fcd3eca1
Commit
fcd3eca1
authored
May 04, 2018
by
lain
Browse files
MastodonAPI: Support idempotency key.
parent
5b6d6d7f
Pipeline
#1613
passed with stages
in 4 minutes and 49 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
lib/pleroma/web/mastodon_api/mastodon_api_controller.ex
View file @
fcd3eca1
...
...
@@ -275,7 +275,19 @@ def post_status(%{assigns: %{user: user}} = conn, %{"status" => _} = params) do
|>
Map
.
put
(
"in_reply_to_status_id"
,
params
[
"in_reply_to_id"
])
|>
Map
.
put
(
"no_attachment_links"
,
true
)
{
:ok
,
activity
}
=
CommonAPI
.
post
(
user
,
params
)
idempotency_key
=
case
get_req_header
(
conn
,
"idempotency-key"
)
do
[
key
]
->
key
_
->
Ecto
.
UUID
.
generate
()
end
{
:ok
,
activity
}
=
Cachex
.
get!
(
:user_cache
,
"idem:
#{
idempotency_key
}
"
,
fallback:
fn
_
->
CommonAPI
.
post
(
user
,
params
)
end
)
render
(
conn
,
StatusView
,
"status.json"
,
%{
activity:
activity
,
for:
user
,
as:
:activity
})
end
...
...
test/web/mastodon_api/mastodon_api_controller_test.exs
View file @
fcd3eca1
...
...
@@ -63,9 +63,12 @@ test "the public timeline", %{conn: conn} do
test
"posting a status"
,
%{
conn:
conn
}
do
user
=
insert
(
:user
)
conn
=
idempotency_key
=
"Pikachu rocks!"
conn_one
=
conn
|>
assign
(
:user
,
user
)
|>
put_req_header
(
"idempotency-key"
,
idempotency_key
)
|>
post
(
"/api/v1/statuses"
,
%{
"status"
=>
"cofe"
,
"spoiler_text"
=>
"2hu"
,
...
...
@@ -73,9 +76,23 @@ test "posting a status", %{conn: conn} do
})
assert
%{
"content"
=>
"cofe"
,
"id"
=>
id
,
"spoiler_text"
=>
"2hu"
,
"sensitive"
=>
false
}
=
json_response
(
conn
,
200
)
json_response
(
conn
_one
,
200
)
assert
Repo
.
get
(
Activity
,
id
)
conn_two
=
conn
|>
assign
(
:user
,
user
)
|>
put_req_header
(
"idempotency-key"
,
idempotency_key
)
|>
post
(
"/api/v1/statuses"
,
%{
"status"
=>
"cofe"
,
"spoiler_text"
=>
"2hu"
,
"sensitive"
=>
"false"
})
assert
%{
"id"
=>
second_id
}
=
json_response
(
conn_two
,
200
)
assert
id
==
second_id
end
test
"posting a sensitive status"
,
%{
conn:
conn
}
do
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment