2019-10-01 07:36:35 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2023-01-02 20:38:50 +00:00
|
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
2019-10-01 07:36:35 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.MastodonAPI.MediaController do
|
|
|
|
use Pleroma.Web, :controller
|
|
|
|
|
|
|
|
alias Pleroma.Object
|
|
|
|
alias Pleroma.User
|
|
|
|
alias Pleroma.Web.ActivityPub.ActivityPub
|
2020-06-24 10:07:47 +00:00
|
|
|
alias Pleroma.Web.Plugs.OAuthScopesPlug
|
2019-10-01 07:36:35 +00:00
|
|
|
|
|
|
|
action_fallback(Pleroma.Web.MastodonAPI.FallbackController)
|
2020-06-16 17:00:54 +00:00
|
|
|
plug(Majic.Plug, [pool: Pleroma.MajicPool] when action in [:create, :create2])
|
2020-05-14 08:50:12 +00:00
|
|
|
plug(Pleroma.Web.ApiSpec.CastAndValidate)
|
2019-10-01 07:36:35 +00:00
|
|
|
|
2020-05-17 05:46:43 +00:00
|
|
|
plug(OAuthScopesPlug, %{scopes: ["read:media"]} when action == :show)
|
|
|
|
plug(OAuthScopesPlug, %{scopes: ["write:media"]} when action != :show)
|
2019-10-06 14:12:17 +00:00
|
|
|
|
2020-05-14 08:50:12 +00:00
|
|
|
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.MediaOperation
|
|
|
|
|
2019-10-01 07:36:35 +00:00
|
|
|
@doc "POST /api/v1/media"
|
Pleroma.Web.MastodonAPI.MediaController: dialyzer errors
lib/pleroma/web/mastodon_api/controllers/media_controller.ex:32:call
The function call will not succeed.
Phoenix.Controller.render(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:file => _, _ => _},
_ => _
},
<<97, 116, 116, 97, 99, 104, 109, 101, 110, 116, 46, 106, 115, 111, 110>>,
%{:attachment => map()}
)
will never return since the success typing is:
(
%Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{binary() => binary() | [any()] | map()},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() => binary() | [any()] | map()
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{_, _}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{_, _}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state =>
:chunked | :file | :sent | :set | :set_chunked | :set_file | :unset | :upgraded,
:status => nil | non_neg_integer()
},
atom() | binary(),
atom() | binary() | [{_, _}] | map()
) :: %Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{binary() => binary() | [any()] | map()},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() => binary() | [any()] | map()
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{_, _}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{_, _}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state => :sent,
:status => nil | non_neg_integer()
}
and the contract is
(Plug.Conn.t(), binary() | atom(), Keyword.t() | map()) :: Plug.Conn.t()
________________________________________________________________________________
lib/pleroma/web/mastodon_api/controllers/media_controller.ex:48:call
The function call will not succeed.
Plug.Conn.put_status(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:file => _, _ => _},
_ => _
},
202
)
breaks the contract
(t(), status()) :: t()
________________________________________________________________________________
lib/pleroma/web/mastodon_api/controllers/media_controller.ex:63:call
The function call will not succeed.
Phoenix.Controller.render(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:description => _, _ => _},
_ => _
},
<<97, 116, 116, 97, 99, 104, 109, 101, 110, 116, 46, 106, 115, 111, 110>>,
%{:attachment => map()}
)
will never return since the success typing is:
(
%Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{binary() => binary() | [any()] | map()},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() => binary() | [any()] | map()
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{_, _}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{_, _}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state =>
:chunked | :file | :sent | :set | :set_chunked | :set_file | :unset | :upgraded,
:status => nil | non_neg_integer()
},
atom() | binary(),
atom() | binary() | [{_, _}] | map()
) :: %Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{binary() => binary() | [any()] | map()},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() => binary() | [any()] | map()
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{_, _}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{_, _}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state => :sent,
:status => nil | non_neg_integer()
}
and the contract is
(Plug.Conn.t(), binary() | atom(), Keyword.t() | map()) :: Plug.Conn.t()
2024-01-29 23:11:03 +00:00
|
|
|
def create(%{assigns: %{user: user}, body_params: %{"file" => file} = data} = conn, _) do
|
2019-10-01 07:36:35 +00:00
|
|
|
with {:ok, object} <-
|
|
|
|
ActivityPub.upload(
|
|
|
|
file,
|
|
|
|
actor: User.ap_id(user),
|
Pleroma.Web.MastodonAPI.MediaController: dialyzer errors
lib/pleroma/web/mastodon_api/controllers/media_controller.ex:32:call
The function call will not succeed.
Phoenix.Controller.render(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:file => _, _ => _},
_ => _
},
<<97, 116, 116, 97, 99, 104, 109, 101, 110, 116, 46, 106, 115, 111, 110>>,
%{:attachment => map()}
)
will never return since the success typing is:
(
%Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{binary() => binary() | [any()] | map()},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() => binary() | [any()] | map()
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{_, _}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{_, _}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state =>
:chunked | :file | :sent | :set | :set_chunked | :set_file | :unset | :upgraded,
:status => nil | non_neg_integer()
},
atom() | binary(),
atom() | binary() | [{_, _}] | map()
) :: %Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{binary() => binary() | [any()] | map()},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() => binary() | [any()] | map()
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{_, _}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{_, _}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state => :sent,
:status => nil | non_neg_integer()
}
and the contract is
(Plug.Conn.t(), binary() | atom(), Keyword.t() | map()) :: Plug.Conn.t()
________________________________________________________________________________
lib/pleroma/web/mastodon_api/controllers/media_controller.ex:48:call
The function call will not succeed.
Plug.Conn.put_status(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:file => _, _ => _},
_ => _
},
202
)
breaks the contract
(t(), status()) :: t()
________________________________________________________________________________
lib/pleroma/web/mastodon_api/controllers/media_controller.ex:63:call
The function call will not succeed.
Phoenix.Controller.render(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:description => _, _ => _},
_ => _
},
<<97, 116, 116, 97, 99, 104, 109, 101, 110, 116, 46, 106, 115, 111, 110>>,
%{:attachment => map()}
)
will never return since the success typing is:
(
%Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{binary() => binary() | [any()] | map()},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() => binary() | [any()] | map()
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{_, _}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{_, _}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state =>
:chunked | :file | :sent | :set | :set_chunked | :set_file | :unset | :upgraded,
:status => nil | non_neg_integer()
},
atom() | binary(),
atom() | binary() | [{_, _}] | map()
) :: %Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{binary() => binary() | [any()] | map()},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() => binary() | [any()] | map()
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{_, _}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{_, _}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state => :sent,
:status => nil | non_neg_integer()
}
and the contract is
(Plug.Conn.t(), binary() | atom(), Keyword.t() | map()) :: Plug.Conn.t()
2024-01-29 23:11:03 +00:00
|
|
|
description: Map.get(data, "description")
|
2019-10-01 07:36:35 +00:00
|
|
|
) do
|
|
|
|
attachment_data = Map.put(object.data, "id", object.id)
|
|
|
|
|
|
|
|
render(conn, "attachment.json", %{attachment: attachment_data})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-29 15:38:14 +00:00
|
|
|
def create(_conn, _data), do: {:error, :bad_request}
|
|
|
|
|
|
|
|
@doc "POST /api/v2/media"
|
Pleroma.Web.MastodonAPI.MediaController: dialyzer errors
lib/pleroma/web/mastodon_api/controllers/media_controller.ex:32:call
The function call will not succeed.
Phoenix.Controller.render(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:file => _, _ => _},
_ => _
},
<<97, 116, 116, 97, 99, 104, 109, 101, 110, 116, 46, 106, 115, 111, 110>>,
%{:attachment => map()}
)
will never return since the success typing is:
(
%Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{binary() => binary() | [any()] | map()},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() => binary() | [any()] | map()
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{_, _}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{_, _}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state =>
:chunked | :file | :sent | :set | :set_chunked | :set_file | :unset | :upgraded,
:status => nil | non_neg_integer()
},
atom() | binary(),
atom() | binary() | [{_, _}] | map()
) :: %Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{binary() => binary() | [any()] | map()},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() => binary() | [any()] | map()
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{_, _}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{_, _}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state => :sent,
:status => nil | non_neg_integer()
}
and the contract is
(Plug.Conn.t(), binary() | atom(), Keyword.t() | map()) :: Plug.Conn.t()
________________________________________________________________________________
lib/pleroma/web/mastodon_api/controllers/media_controller.ex:48:call
The function call will not succeed.
Plug.Conn.put_status(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:file => _, _ => _},
_ => _
},
202
)
breaks the contract
(t(), status()) :: t()
________________________________________________________________________________
lib/pleroma/web/mastodon_api/controllers/media_controller.ex:63:call
The function call will not succeed.
Phoenix.Controller.render(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:description => _, _ => _},
_ => _
},
<<97, 116, 116, 97, 99, 104, 109, 101, 110, 116, 46, 106, 115, 111, 110>>,
%{:attachment => map()}
)
will never return since the success typing is:
(
%Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{binary() => binary() | [any()] | map()},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() => binary() | [any()] | map()
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{_, _}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{_, _}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state =>
:chunked | :file | :sent | :set | :set_chunked | :set_file | :unset | :upgraded,
:status => nil | non_neg_integer()
},
atom() | binary(),
atom() | binary() | [{_, _}] | map()
) :: %Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{binary() => binary() | [any()] | map()},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() => binary() | [any()] | map()
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{_, _}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{_, _}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state => :sent,
:status => nil | non_neg_integer()
}
and the contract is
(Plug.Conn.t(), binary() | atom(), Keyword.t() | map()) :: Plug.Conn.t()
2024-01-29 23:11:03 +00:00
|
|
|
def create2(%{assigns: %{user: user}, body_params: %{"file" => file} = data} = conn, _) do
|
2020-04-29 15:38:14 +00:00
|
|
|
with {:ok, object} <-
|
|
|
|
ActivityPub.upload(
|
|
|
|
file,
|
|
|
|
actor: User.ap_id(user),
|
Pleroma.Web.MastodonAPI.MediaController: dialyzer errors
lib/pleroma/web/mastodon_api/controllers/media_controller.ex:32:call
The function call will not succeed.
Phoenix.Controller.render(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:file => _, _ => _},
_ => _
},
<<97, 116, 116, 97, 99, 104, 109, 101, 110, 116, 46, 106, 115, 111, 110>>,
%{:attachment => map()}
)
will never return since the success typing is:
(
%Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{binary() => binary() | [any()] | map()},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() => binary() | [any()] | map()
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{_, _}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{_, _}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state =>
:chunked | :file | :sent | :set | :set_chunked | :set_file | :unset | :upgraded,
:status => nil | non_neg_integer()
},
atom() | binary(),
atom() | binary() | [{_, _}] | map()
) :: %Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{binary() => binary() | [any()] | map()},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() => binary() | [any()] | map()
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{_, _}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{_, _}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state => :sent,
:status => nil | non_neg_integer()
}
and the contract is
(Plug.Conn.t(), binary() | atom(), Keyword.t() | map()) :: Plug.Conn.t()
________________________________________________________________________________
lib/pleroma/web/mastodon_api/controllers/media_controller.ex:48:call
The function call will not succeed.
Plug.Conn.put_status(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:file => _, _ => _},
_ => _
},
202
)
breaks the contract
(t(), status()) :: t()
________________________________________________________________________________
lib/pleroma/web/mastodon_api/controllers/media_controller.ex:63:call
The function call will not succeed.
Phoenix.Controller.render(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:description => _, _ => _},
_ => _
},
<<97, 116, 116, 97, 99, 104, 109, 101, 110, 116, 46, 106, 115, 111, 110>>,
%{:attachment => map()}
)
will never return since the success typing is:
(
%Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{binary() => binary() | [any()] | map()},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() => binary() | [any()] | map()
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{_, _}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{_, _}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state =>
:chunked | :file | :sent | :set | :set_chunked | :set_file | :unset | :upgraded,
:status => nil | non_neg_integer()
},
atom() | binary(),
atom() | binary() | [{_, _}] | map()
) :: %Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{binary() => binary() | [any()] | map()},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() => binary() | [any()] | map()
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{_, _}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{_, _}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state => :sent,
:status => nil | non_neg_integer()
}
and the contract is
(Plug.Conn.t(), binary() | atom(), Keyword.t() | map()) :: Plug.Conn.t()
2024-01-29 23:11:03 +00:00
|
|
|
description: Map.get(data, "description")
|
2020-04-29 15:38:14 +00:00
|
|
|
) do
|
|
|
|
attachment_data = Map.put(object.data, "id", object.id)
|
|
|
|
|
|
|
|
conn
|
|
|
|
|> put_status(202)
|
|
|
|
|> render("attachment.json", %{attachment: attachment_data})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create2(_conn, _data), do: {:error, :bad_request}
|
|
|
|
|
2019-10-01 07:36:35 +00:00
|
|
|
@doc "PUT /api/v1/media/:id"
|
Pleroma.Web.MastodonAPI.MediaController: dialyzer errors
lib/pleroma/web/mastodon_api/controllers/media_controller.ex:32:call
The function call will not succeed.
Phoenix.Controller.render(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:file => _, _ => _},
_ => _
},
<<97, 116, 116, 97, 99, 104, 109, 101, 110, 116, 46, 106, 115, 111, 110>>,
%{:attachment => map()}
)
will never return since the success typing is:
(
%Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{binary() => binary() | [any()] | map()},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() => binary() | [any()] | map()
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{_, _}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{_, _}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state =>
:chunked | :file | :sent | :set | :set_chunked | :set_file | :unset | :upgraded,
:status => nil | non_neg_integer()
},
atom() | binary(),
atom() | binary() | [{_, _}] | map()
) :: %Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{binary() => binary() | [any()] | map()},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() => binary() | [any()] | map()
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{_, _}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{_, _}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state => :sent,
:status => nil | non_neg_integer()
}
and the contract is
(Plug.Conn.t(), binary() | atom(), Keyword.t() | map()) :: Plug.Conn.t()
________________________________________________________________________________
lib/pleroma/web/mastodon_api/controllers/media_controller.ex:48:call
The function call will not succeed.
Plug.Conn.put_status(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:file => _, _ => _},
_ => _
},
202
)
breaks the contract
(t(), status()) :: t()
________________________________________________________________________________
lib/pleroma/web/mastodon_api/controllers/media_controller.ex:63:call
The function call will not succeed.
Phoenix.Controller.render(
_conn :: %{
:assigns => %{:user => _, _ => _},
:body_params => %{:description => _, _ => _},
_ => _
},
<<97, 116, 116, 97, 99, 104, 109, 101, 110, 116, 46, 106, 115, 111, 110>>,
%{:attachment => map()}
)
will never return since the success typing is:
(
%Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{binary() => binary() | [any()] | map()},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() => binary() | [any()] | map()
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{_, _}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{_, _}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state =>
:chunked | :file | :sent | :set | :set_chunked | :set_file | :unset | :upgraded,
:status => nil | non_neg_integer()
},
atom() | binary(),
atom() | binary() | [{_, _}] | map()
) :: %Plug.Conn{
:adapter => {atom(), _},
:assigns => %{atom() => _},
:body_params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:halted => boolean(),
:host => binary(),
:method => binary(),
:owner => pid(),
:params => %Plug.Conn.Unfetched{:aspect => atom(), binary() => _},
:path_info => [binary()],
:path_params => %{binary() => binary() | [any()] | map()},
:port => char(),
:private => %{atom() => _},
:query_params => %Plug.Conn.Unfetched{
:aspect => atom(),
binary() => binary() | [any()] | map()
},
:query_string => binary(),
:remote_ip =>
{byte(), byte(), byte(), byte()}
| {char(), char(), char(), char(), char(), char(), char(), char()},
:req_cookies => %Plug.Conn.Unfetched{:aspect => atom(), binary() => binary()},
:req_headers => [{_, _}],
:request_path => binary(),
:resp_body =>
nil
| binary()
| maybe_improper_list(
binary() | maybe_improper_list(any(), binary() | []) | byte(),
binary() | []
),
:resp_cookies => %{binary() => map()},
:resp_headers => [{_, _}],
:scheme => :http | :https,
:script_name => [binary()],
:secret_key_base => nil | binary(),
:state => :sent,
:status => nil | non_neg_integer()
}
and the contract is
(Plug.Conn.t(), binary() | atom(), Keyword.t() | map()) :: Plug.Conn.t()
2024-01-29 23:11:03 +00:00
|
|
|
def update(%{assigns: %{user: user}, body_params: %{"description" => description}} = conn, %{
|
|
|
|
id: id
|
|
|
|
}) do
|
2019-10-01 07:36:35 +00:00
|
|
|
with %Object{} = object <- Object.get_by_id(id),
|
2020-05-18 06:51:53 +00:00
|
|
|
:ok <- Object.authorize_access(object, user),
|
2019-10-01 07:36:35 +00:00
|
|
|
{:ok, %Object{data: data}} <- Object.update_data(object, %{"name" => description}) do
|
|
|
|
attachment_data = Map.put(data, "id", object.id)
|
|
|
|
|
|
|
|
render(conn, "attachment.json", %{attachment: attachment_data})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-14 12:29:32 +00:00
|
|
|
def update(conn, data), do: show(conn, data)
|
2020-04-29 15:38:14 +00:00
|
|
|
|
|
|
|
@doc "GET /api/v1/media/:id"
|
2020-05-18 06:51:53 +00:00
|
|
|
def show(%{assigns: %{user: user}} = conn, %{id: id}) do
|
|
|
|
with %Object{data: data, id: object_id} = object <- Object.get_by_id(id),
|
|
|
|
:ok <- Object.authorize_access(object, user) do
|
2020-04-29 15:38:14 +00:00
|
|
|
attachment_data = Map.put(data, "id", object_id)
|
|
|
|
|
|
|
|
render(conn, "attachment.json", %{attachment: attachment_data})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-17 05:46:43 +00:00
|
|
|
def show(_conn, _data), do: {:error, :bad_request}
|
2019-10-01 07:36:35 +00:00
|
|
|
end
|