Fix uploads and favorites in twidere / twittnuker.
authorRoger Braun <roger@rogerbraun.net>
Fri, 14 Apr 2017 14:13:34 +0000 (16:13 +0200)
committerRoger Braun <roger@rogerbraun.net>
Fri, 14 Apr 2017 14:13:34 +0000 (16:13 +0200)
lib/pleroma/web/router.ex
lib/pleroma/web/twitter_api/twitter_api.ex
lib/pleroma/web/twitter_api/twitter_api_controller.ex

index a61e32b409958edcc8433c7eb3238d59e7a784f5..e11086538390379a457d2c3a1de04937edb6e8ae 100644 (file)
@@ -39,6 +39,8 @@ defmodule Pleroma.Web.Router do
     post "/friendships/create", TwitterAPI.Controller, :follow
     post "/friendships/destroy", TwitterAPI.Controller, :unfollow
     post "/statusnet/media/upload", TwitterAPI.Controller, :upload
+    post "/media/upload", TwitterAPI.Controller, :upload_json
     post "/favorites/create/:id", TwitterAPI.Controller, :favorite
+    post "/favorites/create", TwitterAPI.Controller, :favorite
   end
 end
index 33ddebbc1ac884a5e9acb3e84bbbe7f2b0817754..19f3c1c8c0f34873b24a918ed4ec86f00f4ad538 100644 (file)
@@ -137,25 +137,35 @@ defmodule Pleroma.Web.TwitterAPI.TwitterAPI do
     {:ok, status}
   end
 
-  def upload(%Plug.Upload{} = file) do
+  def upload(%Plug.Upload{} = file, format \\ "xml") do
     {:ok, object} = ActivityPub.upload(file)
 
     url = List.first(object.data["url"])
     href = url["href"]
     type = url["mediaType"]
 
-    # Fake this as good as possible...
-    """
-    <?xml version="1.0" encoding="UTF-8"?>
-    <rsp stat="ok" xmlns:atom="http://www.w3.org/2005/Atom">
-      <mediaid>#{object.id}</mediaid>
-      <media_id>#{object.id}</media_id>
-      <media_id_string>#{object.id}</media_id_string>
-      <media_url>#{href}</media_url>
-      <mediaurl>#{href}</mediaurl>
-      <atom:link rel="enclosure" href="#{href}" type="#{type}"></atom:link>
-    </rsp>
-    """
+    case format do
+      "xml" ->
+        # Fake this as good as possible...
+        """
+        <?xml version="1.0" encoding="UTF-8"?>
+        <rsp stat="ok" xmlns:atom="http://www.w3.org/2005/Atom">
+        <mediaid>#{object.id}</mediaid>
+        <media_id>#{object.id}</media_id>
+        <media_id_string>#{object.id}</media_id_string>
+        <media_url>#{href}</media_url>
+        <mediaurl>#{href}</mediaurl>
+        <atom:link rel="enclosure" href="#{href}" type="#{type}"></atom:link>
+        </rsp>
+        """
+      "json" ->
+        %{
+          media_id: object.id,
+          media_id_string: "#{object.id}}",
+          media_url: href,
+          size: 0
+        } |> Poison.encode!
+    end
   end
 
   def parse_mentions(text) do
index 3969e92a65164000d274d7ad7b611e8f52445dff..f66238e0a9d1d3c115fb677ba978f92e3a68c0ef 100644 (file)
@@ -84,6 +84,12 @@ defmodule Pleroma.Web.TwitterAPI.Controller do
     |> send_resp(200, response)
   end
 
+  def upload_json(conn, %{"media" => media}) do
+    response = TwitterAPI.upload(media, "json")
+    conn
+    |> json_reply(200, response)
+  end
+
   def config(conn, _params) do
     response = %{
       site: %{