diff --git a/lib/pleroma/web/router.ex b/lib/pleroma/web/router.ex index a61e32b40..e11086538 100644 --- a/lib/pleroma/web/router.ex +++ b/lib/pleroma/web/router.ex @@ -39,6 +39,8 @@ def user_fetcher(username) 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 diff --git a/lib/pleroma/web/twitter_api/twitter_api.ex b/lib/pleroma/web/twitter_api/twitter_api.ex index 33ddebbc1..19f3c1c8c 100644 --- a/lib/pleroma/web/twitter_api/twitter_api.ex +++ b/lib/pleroma/web/twitter_api/twitter_api.ex @@ -137,25 +137,35 @@ def favorite(%User{} = user, %Activity{data: %{"object" => object}} = activity) {: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... - """ - - - #{object.id} - #{object.id} - #{object.id} - #{href} - #{href} - - - """ + case format do + "xml" -> + # Fake this as good as possible... + """ + + + #{object.id} + #{object.id} + #{object.id} + #{href} + #{href} + + + """ + "json" -> + %{ + media_id: object.id, + media_id_string: "#{object.id}}", + media_url: href, + size: 0 + } |> Poison.encode! + end end def parse_mentions(text) do diff --git a/lib/pleroma/web/twitter_api/twitter_api_controller.ex b/lib/pleroma/web/twitter_api/twitter_api_controller.ex index 3969e92a6..f66238e0a 100644 --- a/lib/pleroma/web/twitter_api/twitter_api_controller.ex +++ b/lib/pleroma/web/twitter_api/twitter_api_controller.ex @@ -84,6 +84,12 @@ def upload(conn, %{"media" => media}) 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: %{