pagination for remote emoji packs

This commit is contained in:
Alexander Strizhakov 2020-06-27 14:33:49 +03:00
parent 9b6d89ff8c
commit dbbc801667
No known key found for this signature in database
GPG Key ID: 022896A53AEF1381
4 changed files with 25 additions and 10 deletions

View File

@ -198,13 +198,13 @@ def import_from_filesystem 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

View File

@ -19,7 +19,21 @@ def remote_operation 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(),

View File

@ -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} ->

View File

@ -102,7 +102,7 @@ test "GET /api/pleroma/emoji/packs", %{conn: conn} 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 @@ test "shareable instance", %{admin_conn: admin_conn, conn: conn} 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