mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-06-09 00:39:27 +00:00
8cd5279857
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()
136 lines
4.6 KiB
Elixir
136 lines
4.6 KiB
Elixir
# Pleroma: A lightweight social networking server
|
|
# Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
defmodule Pleroma.Web.ApiSpec.MediaOperation do
|
|
alias OpenApiSpex.Operation
|
|
alias OpenApiSpex.Schema
|
|
alias Pleroma.Web.ApiSpec.Helpers
|
|
alias Pleroma.Web.ApiSpec.Schemas.ApiError
|
|
alias Pleroma.Web.ApiSpec.Schemas.Attachment
|
|
|
|
def open_api_operation(action) do
|
|
operation = String.to_existing_atom("#{action}_operation")
|
|
apply(__MODULE__, operation, [])
|
|
end
|
|
|
|
def create_operation do
|
|
%Operation{
|
|
tags: ["Media attachments"],
|
|
summary: "Upload media as attachment",
|
|
description: "Creates an attachment to be used with a new status.",
|
|
operationId: "MediaController.create",
|
|
security: [%{"oAuth" => ["write:media"]}],
|
|
requestBody: Helpers.request_body("Parameters", create_request()),
|
|
responses: %{
|
|
200 => Operation.response("Media", "application/json", Attachment),
|
|
400 => Operation.response("Media", "application/json", ApiError),
|
|
401 => Operation.response("Media", "application/json", ApiError),
|
|
422 => Operation.response("Media", "application/json", ApiError)
|
|
}
|
|
}
|
|
end
|
|
|
|
defp create_request do
|
|
%Schema{
|
|
title: "MediaCreateRequest",
|
|
description: "POST body for creating an attachment",
|
|
type: :object,
|
|
required: ["file"],
|
|
properties: %{
|
|
"file" => %Schema{
|
|
type: :string,
|
|
format: :binary,
|
|
description: "The file to be attached, using multipart form data."
|
|
},
|
|
"description" => %Schema{
|
|
type: :string,
|
|
description: "A plain-text description of the media, for accessibility purposes."
|
|
},
|
|
"focus" => %Schema{
|
|
type: :string,
|
|
description: "Two floating points (x,y), comma-delimited, ranging from -1.0 to 1.0."
|
|
}
|
|
}
|
|
}
|
|
end
|
|
|
|
def update_operation do
|
|
%Operation{
|
|
tags: ["Media attachments"],
|
|
summary: "Update attachment",
|
|
description: "Creates an attachment to be used with a new status.",
|
|
operationId: "MediaController.update",
|
|
security: [%{"oAuth" => ["write:media"]}],
|
|
parameters: [id_param()],
|
|
requestBody: Helpers.request_body("Parameters", update_request()),
|
|
responses: %{
|
|
200 => Operation.response("Media", "application/json", Attachment),
|
|
400 => Operation.response("Media", "application/json", ApiError),
|
|
401 => Operation.response("Media", "application/json", ApiError),
|
|
422 => Operation.response("Media", "application/json", ApiError)
|
|
}
|
|
}
|
|
end
|
|
|
|
defp update_request do
|
|
%Schema{
|
|
title: "MediaUpdateRequest",
|
|
description: "POST body for updating an attachment",
|
|
type: :object,
|
|
properties: %{
|
|
"file" => %Schema{
|
|
type: :string,
|
|
format: :binary,
|
|
description: "The file to be attached, using multipart form data."
|
|
},
|
|
"description" => %Schema{
|
|
type: :string,
|
|
description: "A plain-text description of the media, for accessibility purposes."
|
|
},
|
|
"focus" => %Schema{
|
|
type: :string,
|
|
description: "Two floating points (x,y), comma-delimited, ranging from -1.0 to 1.0."
|
|
}
|
|
}
|
|
}
|
|
end
|
|
|
|
def show_operation do
|
|
%Operation{
|
|
tags: ["Media attachments"],
|
|
summary: "Attachment",
|
|
operationId: "MediaController.show",
|
|
parameters: [id_param()],
|
|
security: [%{"oAuth" => ["read:media"]}],
|
|
responses: %{
|
|
200 => Operation.response("Media", "application/json", Attachment),
|
|
401 => Operation.response("Media", "application/json", ApiError),
|
|
403 => Operation.response("Media", "application/json", ApiError),
|
|
422 => Operation.response("Media", "application/json", ApiError)
|
|
}
|
|
}
|
|
end
|
|
|
|
def create2_operation do
|
|
%Operation{
|
|
tags: ["Media attachments"],
|
|
summary: "Upload media as attachment (v2)",
|
|
description: "Creates an attachment to be used with a new status.",
|
|
operationId: "MediaController.create2",
|
|
security: [%{"oAuth" => ["write:media"]}],
|
|
requestBody: Helpers.request_body("Parameters", create_request()),
|
|
responses: %{
|
|
202 => Operation.response("Media", "application/json", Attachment),
|
|
400 => Operation.response("Media", "application/json", ApiError),
|
|
422 => Operation.response("Media", "application/json", ApiError),
|
|
500 => Operation.response("Media", "application/json", ApiError)
|
|
}
|
|
}
|
|
end
|
|
|
|
defp id_param do
|
|
Operation.parameter(:id, :path, :string, "The ID of the Attachment entity")
|
|
end
|
|
end
|