* Params:
* `page`: page number for packs (default 1)
* `page_size`: page size for packs (default 50)
-* Response: JSON, "ok" and 200 status and the JSON hashmap of pack name to pack contents
+* Response: `packs` key with JSON hashmap of pack name to pack contents and `count` key for count of packs.
+
+```json
+{
+ "packs": {
+ "pack_name": {...}, // pack contents
+ ...
+ },
+ "count": 0 // packs count
+}
+```
## `GET /api/pleroma/emoji/packs/:name`
* Params:
* `page`: page number for files (default 1)
* `page_size`: page size for files (default 50)
-* Response: JSON, pack json with `files` and `pack` keys with 200 status or 404 if the pack does not exist
+* Response: JSON, pack json with `files`, `files_count` and `pack` keys with 200 status or 404 if the pack does not exist.
+
+```json
+{
+ "files": {...},
+ "files_count": 0, // emoji count in pack
+ "pack": {...}
+}
+```
## `GET /api/pleroma/emoji/packs/:name/archive`
### Requests a local pack archive from the instance
defmodule Pleroma.Emoji.Pack do
- @derive {Jason.Encoder, only: [:files, :pack]}
+ @derive {Jason.Encoder, only: [:files, :pack, :files_count]}
defstruct files: %{},
+ files_count: 0,
pack_file: nil,
path: nil,
pack: %{},
@type t() :: %__MODULE__{
files: %{String.t() => Path.t()},
+ files_count: non_neg_integer(),
pack_file: Path.t(),
path: Path.t(),
pack: map(),
end
end
- @spec list_local(keyword()) :: {:ok, map()}
+ @spec list_local(keyword()) :: {:ok, map(), non_neg_integer()}
def list_local(opts) do
with {:ok, results} <- list_packs_dir() do
- packs =
+ all_packs =
results
|> Enum.map(fn name ->
case load_pack(name) do
end
end)
|> Enum.reject(&is_nil/1)
+
+ packs =
+ all_packs
|> paginate(opts[:page], opts[:page_size])
|> Map.new(fn pack -> {pack.name, validate_pack(pack)} end)
- {:ok, packs}
+ {:ok, packs, length(all_packs)}
end
end
|> Map.put(:path, Path.dirname(pack_file))
|> Map.put(:name, name)
- {:ok, pack}
+ files_count =
+ pack.files
+ |> Map.keys()
+ |> length()
+
+ {:ok, Map.put(pack, :files_count, files_count)}
else
{:error, :not_found}
end
test "GET /api/pleroma/emoji/packs", %{conn: conn} do
resp = conn |> get("/api/pleroma/emoji/packs") |> json_response_and_validate_schema(200)
- shared = resp["test_pack"]
+ assert resp["count"] == 3
+ shared = resp["packs"]["test_pack"]
assert shared["files"] == %{"blank" => "blank.png", "blank2" => "blank2.png"}
assert Map.has_key?(shared["pack"], "download-sha256")
assert shared["pack"]["can-download"]
assert shared["pack"]["share-files"]
- non_shared = resp["test_pack_nonshared"]
+ non_shared = resp["packs"]["test_pack_nonshared"]
assert non_shared["pack"]["share-files"] == false
assert non_shared["pack"]["can-download"] == false
|> get("/api/pleroma/emoji/packs?page_size=1")
|> json_response_and_validate_schema(200)
- [pack1] = Map.keys(resp)
+ assert resp["count"] == 3
+ [pack1] = Map.keys(resp["packs"])
resp =
conn
|> get("/api/pleroma/emoji/packs?page_size=1&page=2")
|> json_response_and_validate_schema(200)
- [pack2] = Map.keys(resp)
+ assert resp["count"] == 3
+ [pack2] = Map.keys(resp["packs"])
resp =
conn
|> get("/api/pleroma/emoji/packs?page_size=1&page=3")
|> json_response_and_validate_schema(200)
- [pack3] = Map.keys(resp)
+ assert resp["count"] == 3
+ [pack3] = Map.keys(resp["packs"])
assert [pack1, pack2, pack3] |> Enum.uniq() |> length() == 3
end
assert Jason.decode!(File.read!("#{@emoji_path}/test_created/pack.json")) == %{
"pack" => %{},
- "files" => %{}
+ "files" => %{},
+ "files_count" => 0
}
assert admin_conn
resp = conn |> get("/api/pleroma/emoji/packs") |> json_response_and_validate_schema(200)
- refute Map.has_key?(resp, "test_pack_for_import")
+ refute Map.has_key?(resp["packs"], "test_pack_for_import")
assert admin_conn
|> get("/api/pleroma/emoji/packs/import")
|> json_response_and_validate_schema(200) == ["test_pack_for_import"]
resp = conn |> get("/api/pleroma/emoji/packs") |> json_response_and_validate_schema(200)
- assert resp["test_pack_for_import"]["files"] == %{"blank" => "blank.png"}
+ assert resp["packs"]["test_pack_for_import"]["files"] == %{"blank" => "blank.png"}
File.rm!("#{@emoji_path}/test_pack_for_import/pack.json")
refute File.exists?("#{@emoji_path}/test_pack_for_import/pack.json")
resp = conn |> get("/api/pleroma/emoji/packs") |> json_response_and_validate_schema(200)
- assert resp["test_pack_for_import"]["files"] == %{
+ assert resp["packs"]["test_pack_for_import"]["files"] == %{
"blank" => "blank.png",
"blank2" => "blank.png",
"foo" => "blank.png"
test "shows pack.json", %{conn: conn} do
assert %{
"files" => files,
+ "files_count" => 2,
"pack" => %{
"can-download" => true,
"description" => "Test description",
assert files == %{"blank" => "blank.png", "blank2" => "blank2.png"}
assert %{
- "files" => files
+ "files" => files,
+ "files_count" => 2
} =
conn
|> get("/api/pleroma/emoji/packs/test_pack?page_size=1")
assert files |> Map.keys() |> length() == 1
assert %{
- "files" => files
+ "files" => files,
+ "files_count" => 2
} =
conn
|> get("/api/pleroma/emoji/packs/test_pack?page_size=1&page=2")