mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-23 00:26:30 +00:00
Revert "Pleroma.Web.PleromaAPI.EmojiFileController: dialyzer errors"
This reverts commit dc912dc590
.
This commit is contained in:
parent
b709fc4dfe
commit
4a9ed4682a
2 changed files with 18 additions and 18 deletions
|
@ -36,9 +36,9 @@ defmodule Pleroma.Web.ApiSpec.PleromaEmojiFileOperation do
|
|||
defp create_request do
|
||||
%Schema{
|
||||
type: :object,
|
||||
required: ["file"],
|
||||
required: [:file],
|
||||
properties: %{
|
||||
"file" => %Schema{
|
||||
file: %Schema{
|
||||
description:
|
||||
"File needs to be uploaded with the multipart request or link to remote file",
|
||||
anyOf: [
|
||||
|
@ -46,12 +46,12 @@ defmodule Pleroma.Web.ApiSpec.PleromaEmojiFileOperation do
|
|||
%Schema{type: :string, format: :uri}
|
||||
]
|
||||
},
|
||||
"shortcode" => %Schema{
|
||||
shortcode: %Schema{
|
||||
type: :string,
|
||||
description:
|
||||
"Shortcode for new emoji, must be unique for all emoji. If not sended, shortcode will be taken from original filename."
|
||||
},
|
||||
"filename" => %Schema{
|
||||
filename: %Schema{
|
||||
type: :string,
|
||||
description:
|
||||
"New emoji file name. If not specified will be taken from original filename."
|
||||
|
@ -81,21 +81,21 @@ defmodule Pleroma.Web.ApiSpec.PleromaEmojiFileOperation do
|
|||
defp update_request do
|
||||
%Schema{
|
||||
type: :object,
|
||||
required: ["shortcode", "new_shortcode", "new_filename"],
|
||||
required: [:shortcode, :new_shortcode, :new_filename],
|
||||
properties: %{
|
||||
"shortcode" => %Schema{
|
||||
shortcode: %Schema{
|
||||
type: :string,
|
||||
description: "Emoji file shortcode"
|
||||
},
|
||||
"new_shortcode" => %Schema{
|
||||
new_shortcode: %Schema{
|
||||
type: :string,
|
||||
description: "New emoji file shortcode"
|
||||
},
|
||||
"new_filename" => %Schema{
|
||||
new_filename: %Schema{
|
||||
type: :string,
|
||||
description: "New filename for emoji file"
|
||||
},
|
||||
"force" => %Schema{
|
||||
force: %Schema{
|
||||
type: :boolean,
|
||||
description: "With true value to overwrite existing emoji with new shortcode",
|
||||
default: false
|
||||
|
|
|
@ -23,11 +23,11 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileController do
|
|||
defdelegate open_api_operation(action), to: ApiSpec.PleromaEmojiFileOperation
|
||||
|
||||
def create(%{body_params: params} = conn, %{name: pack_name}) do
|
||||
filename = params["filename"] || get_filename(params["file"])
|
||||
shortcode = params["shortcode"] || Path.basename(filename, Path.extname(filename))
|
||||
filename = params[:filename] || get_filename(params[:file])
|
||||
shortcode = params[:shortcode] || Path.basename(filename, Path.extname(filename))
|
||||
|
||||
with {:ok, pack} <- Pack.load_pack(pack_name),
|
||||
{:ok, file} <- get_file(params["file"]),
|
||||
{:ok, file} <- get_file(params[:file]),
|
||||
{:ok, pack} <- Pack.add_file(pack, shortcode, filename, file) do
|
||||
json(conn, pack.files)
|
||||
else
|
||||
|
@ -49,10 +49,10 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileController do
|
|||
end
|
||||
end
|
||||
|
||||
def update(%{body_params: %{"shortcode" => shortcode} = params} = conn, %{name: pack_name}) do
|
||||
new_shortcode = params["new_shortcode"]
|
||||
new_filename = params["new_filename"]
|
||||
force = params["force"]
|
||||
def update(%{body_params: %{shortcode: shortcode} = params} = conn, %{name: pack_name}) do
|
||||
new_shortcode = params[:new_shortcode]
|
||||
new_filename = params[:new_filename]
|
||||
force = params[:force]
|
||||
|
||||
with {:ok, pack} <- Pack.load_pack(pack_name),
|
||||
{:ok, pack} <- Pack.update_file(pack, shortcode, new_shortcode, new_filename, force) do
|
||||
|
@ -128,9 +128,9 @@ defmodule Pleroma.Web.PleromaAPI.EmojiFileController do
|
|||
defp get_filename(%Plug.Upload{filename: filename}), do: filename
|
||||
defp get_filename(url) when is_binary(url), do: Path.basename(url)
|
||||
|
||||
defp get_file(%Plug.Upload{} = file), do: {:ok, file}
|
||||
def get_file(%Plug.Upload{} = file), do: {:ok, file}
|
||||
|
||||
defp get_file(url) when is_binary(url) do
|
||||
def get_file(url) when is_binary(url) do
|
||||
with {:ok, %Tesla.Env{body: body, status: code, headers: headers}}
|
||||
when code in 200..299 <- Pleroma.HTTP.get(url) do
|
||||
path = Plug.Upload.random_file!("emoji")
|
||||
|
|
Loading…
Reference in a new issue