Merge branch 'develop' into feature/addressable-lists
[akkoma] / lib / pleroma / web / uploader_controller.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.UploaderController do
6 use Pleroma.Web, :controller
7
8 alias Pleroma.Uploaders.Uploader
9
10 def callback(conn, %{"upload_path" => upload_path} = params) do
11 process_callback(conn, :global.whereis_name({Uploader, upload_path}), params)
12 end
13
14 def callbacks(conn, _) do
15 render_error(conn, :bad_request, "bad request")
16 end
17
18 defp process_callback(conn, pid, params) when is_pid(pid) do
19 send(pid, {Uploader, self(), conn, params})
20
21 receive do
22 {Uploader, conn} -> conn
23 end
24 end
25
26 defp process_callback(conn, _, _) do
27 render_error(conn, :bad_request, "bad request")
28 end
29 end