pagination for remote emoji packs
This commit is contained in:
parent
9b6d89ff8c
commit
dbbc801667
@ -198,13 +198,13 @@ defmodule Pleroma.Emoji.Pack do
|
||||
end
|
||||
end
|
||||
|
||||
@spec list_remote(String.t()) :: {:ok, map()} | {:error, atom()}
|
||||
def list_remote(url) do
|
||||
uri = url |> String.trim() |> URI.parse()
|
||||
@spec list_remote(keyword()) :: {:ok, map()} | {:error, atom()}
|
||||
def list_remote(opts) do
|
||||
uri = opts[:url] |> String.trim() |> URI.parse()
|
||||
|
||||
with :ok <- validate_shareable_packs_available(uri) do
|
||||
uri
|
||||
|> URI.merge("/api/pleroma/emoji/packs")
|
||||
|> URI.merge("/api/pleroma/emoji/packs?page=#{opts[:page]}&page_size=#{opts[:page_size]}")
|
||||
|> http_get()
|
||||
end
|
||||
end
|
||||
|
@ -19,7 +19,21 @@ defmodule Pleroma.Web.ApiSpec.PleromaEmojiPackOperation do
|
||||
tags: ["Emoji Packs"],
|
||||
summary: "Make request to another instance for emoji packs list",
|
||||
security: [%{"oAuth" => ["write"]}],
|
||||
parameters: [url_param()],
|
||||
parameters: [
|
||||
url_param(),
|
||||
Operation.parameter(
|
||||
:page,
|
||||
:query,
|
||||
%Schema{type: :integer, default: 1},
|
||||
"Page"
|
||||
),
|
||||
Operation.parameter(
|
||||
:page_size,
|
||||
:query,
|
||||
%Schema{type: :integer, default: 30},
|
||||
"Number of emoji to return"
|
||||
)
|
||||
],
|
||||
operationId: "PleromaAPI.EmojiPackController.remote",
|
||||
responses: %{
|
||||
200 => emoji_packs_response(),
|
||||
|
@ -23,8 +23,9 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackController do
|
||||
|
||||
defdelegate open_api_operation(action), to: Pleroma.Web.ApiSpec.PleromaEmojiPackOperation
|
||||
|
||||
def remote(conn, %{url: url}) do
|
||||
with {:ok, packs} <- Pack.list_remote(url) do
|
||||
def remote(conn, params) do
|
||||
with {:ok, packs} <-
|
||||
Pack.list_remote(url: params.url, page_size: params.page_size, page: params.page) do
|
||||
json(conn, packs)
|
||||
else
|
||||
{:error, :not_shareable} ->
|
||||
|
@ -102,7 +102,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
|
||||
test "shareable instance", %{admin_conn: admin_conn, conn: conn} do
|
||||
resp =
|
||||
conn
|
||||
|> get("/api/pleroma/emoji/packs")
|
||||
|> get("/api/pleroma/emoji/packs?page=2&page_size=1")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
mock(fn
|
||||
@ -112,12 +112,12 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
|
||||
%{method: :get, url: "https://example.com/nodeinfo/2.1.json"} ->
|
||||
json(%{metadata: %{features: ["shareable_emoji_packs"]}})
|
||||
|
||||
%{method: :get, url: "https://example.com/api/pleroma/emoji/packs"} ->
|
||||
%{method: :get, url: "https://example.com/api/pleroma/emoji/packs?page=2&page_size=1"} ->
|
||||
json(resp)
|
||||
end)
|
||||
|
||||
assert admin_conn
|
||||
|> get("/api/pleroma/emoji/packs/remote?url=https://example.com")
|
||||
|> get("/api/pleroma/emoji/packs/remote?url=https://example.com&page=2&page_size=1")
|
||||
|> json_response_and_validate_schema(200) == resp
|
||||
end
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user