Packages

Gleam SDK for Rockbox Zig — pipe-friendly client for the rockboxd GraphQL API

Current section

Files

Jump to
rockbox src rockbox@browse.erl
Raw

src/rockbox@browse.erl

-module(rockbox@browse).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/rockbox/browse.gleam").
-export([entries/2, directories/2, files/2]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(" File-tree browsing for both the local filesystem and UPnP servers.\n").
-file("src/rockbox/browse.gleam", 13).
?DOC(" Both directories and files at `path`. Pass `option.None` to read the root.\n").
-spec entries(rockbox:client(), gleam@option:option(binary())) -> {ok,
list(rockbox@types:entry())} |
{error, rockbox@error:error()}.
entries(Client, Path) ->
Decoder = begin
gleam@dynamic@decode:field(
<<"treeGetEntries"/utf8>>,
gleam@dynamic@decode:list(rockbox@types:entry_decoder()),
fun(Entries) -> gleam@dynamic@decode:success(Entries) end
)
end,
Vars = rockbox@internal@transport:variables(
[{<<"path"/utf8>>, gleam@option:map(Path, fun gleam@json:string/1)}]
),
rockbox:'query'(
Client,
<<"query Browse($path: String) {
treeGetEntries(path: $path) { name attr timeWrite customaction displayName }
}"/utf8>>,
Vars,
Decoder
).
-file("src/rockbox/browse.gleam", 36).
?DOC(" Subdirectories only.\n").
-spec directories(rockbox:client(), gleam@option:option(binary())) -> {ok,
list(rockbox@types:entry())} |
{error, rockbox@error:error()}.
directories(Client, Path) ->
case entries(Client, Path) of
{ok, All} ->
{ok, gleam@list:filter(All, fun rockbox@types:is_directory/1)};
{error, Err} ->
{error, Err}
end.
-file("src/rockbox/browse.gleam", 47).
?DOC(" Files only (everything that isn't a directory).\n").
-spec files(rockbox:client(), gleam@option:option(binary())) -> {ok,
list(rockbox@types:entry())} |
{error, rockbox@error:error()}.
files(Client, Path) ->
case entries(Client, Path) of
{ok, All} ->
{ok,
gleam@list:filter(
All,
fun(E) -> not rockbox@types:is_directory(E) end
)};
{error, Err} ->
{error, Err}
end.