Fix uploads and favorites in twidere / twittnuker.
This commit is contained in:
parent
fa0c279139
commit
90b38fd51b
|
@ -39,6 +39,8 @@ def user_fetcher(username) do
|
||||||
post "/friendships/create", TwitterAPI.Controller, :follow
|
post "/friendships/create", TwitterAPI.Controller, :follow
|
||||||
post "/friendships/destroy", TwitterAPI.Controller, :unfollow
|
post "/friendships/destroy", TwitterAPI.Controller, :unfollow
|
||||||
post "/statusnet/media/upload", TwitterAPI.Controller, :upload
|
post "/statusnet/media/upload", TwitterAPI.Controller, :upload
|
||||||
|
post "/media/upload", TwitterAPI.Controller, :upload_json
|
||||||
post "/favorites/create/:id", TwitterAPI.Controller, :favorite
|
post "/favorites/create/:id", TwitterAPI.Controller, :favorite
|
||||||
|
post "/favorites/create", TwitterAPI.Controller, :favorite
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -137,13 +137,15 @@ def favorite(%User{} = user, %Activity{data: %{"object" => object}} = activity)
|
||||||
{:ok, status}
|
{:ok, status}
|
||||||
end
|
end
|
||||||
|
|
||||||
def upload(%Plug.Upload{} = file) do
|
def upload(%Plug.Upload{} = file, format \\ "xml") do
|
||||||
{:ok, object} = ActivityPub.upload(file)
|
{:ok, object} = ActivityPub.upload(file)
|
||||||
|
|
||||||
url = List.first(object.data["url"])
|
url = List.first(object.data["url"])
|
||||||
href = url["href"]
|
href = url["href"]
|
||||||
type = url["mediaType"]
|
type = url["mediaType"]
|
||||||
|
|
||||||
|
case format do
|
||||||
|
"xml" ->
|
||||||
# Fake this as good as possible...
|
# Fake this as good as possible...
|
||||||
"""
|
"""
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
@ -156,6 +158,14 @@ def upload(%Plug.Upload{} = file) do
|
||||||
<atom:link rel="enclosure" href="#{href}" type="#{type}"></atom:link>
|
<atom:link rel="enclosure" href="#{href}" type="#{type}"></atom:link>
|
||||||
</rsp>
|
</rsp>
|
||||||
"""
|
"""
|
||||||
|
"json" ->
|
||||||
|
%{
|
||||||
|
media_id: object.id,
|
||||||
|
media_id_string: "#{object.id}}",
|
||||||
|
media_url: href,
|
||||||
|
size: 0
|
||||||
|
} |> Poison.encode!
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_mentions(text) do
|
def parse_mentions(text) do
|
||||||
|
|
|
@ -84,6 +84,12 @@ def upload(conn, %{"media" => media}) do
|
||||||
|> send_resp(200, response)
|
|> send_resp(200, response)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def upload_json(conn, %{"media" => media}) do
|
||||||
|
response = TwitterAPI.upload(media, "json")
|
||||||
|
conn
|
||||||
|
|> json_reply(200, response)
|
||||||
|
end
|
||||||
|
|
||||||
def config(conn, _params) do
|
def config(conn, _params) do
|
||||||
response = %{
|
response = %{
|
||||||
site: %{
|
site: %{
|
||||||
|
|
Loading…
Reference in New Issue