# Configures the endpoint
config :pleroma, Pleroma.Web.Endpoint,
url: [host: "localhost"],
+ protocol: "https",
secret_key_base: "aK4Abxf29xU9TTDKre9coZPUgevcVCFQJe/5xP/7Lt4BEif6idBIbjupVbOrbKxl",
render_errors: [view: Pleroma.Web.ErrorView, accepts: ~w(json)],
pubsub: [name: Pleroma.PubSub,
# with brunch.io to recompile .js and .css sources.
config :pleroma, Pleroma.Web.Endpoint,
http: [port: 4000],
+ protocol: "http",
debug_errors: true,
code_reloader: true,
check_origin: false,
|> Keyword.fetch!(:url)
|> Keyword.fetch!(:host)
- "https://#{host}/media/#{file}"
+ protocol = Application.get_env(:pleroma, Pleroma.Web.Endpoint) |> Keyword.fetch!(:protocol)
+
+ "#{protocol}://#{host}/media/#{file}"
end
end
defmodule Pleroma.Web.ActivityPub.ActivityPub do
alias Pleroma.Repo
- alias Pleroma.Activity
+ alias Pleroma.{Activity, Object, Upload}
import Ecto.Query
def insert(map) when is_map(map) do
Application.get_env(:pleroma, Pleroma.Web.Endpoint)
|> Keyword.fetch!(:url)
|> Keyword.fetch!(:host)
- "https://#{host}/#{type}/#{Ecto.UUID.generate}"
+
+ protocol = Application.get_env(:pleroma, Pleroma.Web.Endpoint) |> Keyword.fetch!(:protocol)
+ "#{protocol}://#{host}/#{type}/#{Ecto.UUID.generate}"
end
def fetch_public_activities(opts \\ %{}) do
where: fragment("? @> ?", activity.data, ^%{ context: context })
Repo.all(query)
end
+
+ def upload(%Plug.Upload{} = file) do
+ data = Upload.store(file)
+ Repo.insert(%Object{data: data})
+ end
end
# You should set gzip to true if you are running phoenix.digest
# when deploying your static files in production.
plug Plug.Static,
- at: "/", from: :pleroma, gzip: false,
- only: ~w(css fonts images js favicon.ico robots.txt)
+ at: "/media", from: "uploads", gzip: false
# Code reloading can be explicitly enabled under the
# :code_reloader configuration of your endpoint.
get "/statuses/friends_timeline", TwitterAPI.Controller, :friends_timeline
post "/friendships/create", TwitterAPI.Controller, :follow
post "/friendships/destroy", TwitterAPI.Controller, :unfollow
+ post "/statusnet/media/upload", TwitterAPI.Controller, :upload
end
end
end
end
+ def upload(%Plug.Upload{} = file) do
+ {:ok, object} = ActivityPub.upload(file)
+
+ # 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>#{object.data["href"]}</media_url>
+ <mediaurl>#{object.data["href"]}</mediaurl>
+ <atom:link rel="enclosure" href="#{object.data["href"]}" type="image"></atom:link>
+ </rsp>
+ """
+ end
+
defp add_conversation_id(activity) do
if is_integer(activity.data["statusnetConversationId"]) do
{:ok, activity}
|> json_reply(200, response)
end
+ def upload(conn, %{"media" => media}) do
+ response = TwitterAPI.upload(media)
+ conn
+ |> put_resp_content_type("application/atom+xml")
+ |> send_resp(200, response)
+ end
defp json_reply(conn, status, json) do
conn
defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
use Pleroma.DataCase
alias Pleroma.Web.ActivityPub.ActivityPub
- alias Pleroma.Activity
+ alias Pleroma.{Activity, Object}
alias Pleroma.Builders.ActivityBuilder
describe "insertion" do
assert last == last_expected
end
end
+
+ describe "uploading files" do
+ test "copies the file to the configured folder" do
+ file = %Plug.Upload{content_type: "image/jpg", path: Path.absname("test/fixtures/image.jpg"), filename: "an_image.jpg"}
+
+ {:ok, %Object{} = object} = ActivityPub.upload(file)
+ assert object.data["name"] == "an_image.jpg"
+ end
+ end
end
assert Enum.at(statuses, 0)["id"] == activity.id
assert Enum.at(statuses, 1)["id"] == activity_two.id
end
+
+ test "upload a file" do
+ file = %Plug.Upload{content_type: "image/jpg", path: Path.absname("test/fixtures/image.jpg"), filename: "an_image.jpg"}
+
+ response = TwitterAPI.upload(file)
+
+ assert is_binary(response)
+ end
end