pinakes-ui: add ApiClient plugin methods; depend on plugin API
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ica7f913a22d18e59e85f1959a5b336df6a6a6964
This commit is contained in:
parent
29ba24ae01
commit
5b204dceb5
3 changed files with 59 additions and 1 deletions
|
|
@ -26,6 +26,7 @@ dioxus-free-icons = { workspace = true }
|
|||
gloo-timers = { workspace = true }
|
||||
rand = { workspace = true }
|
||||
urlencoding = { workspace = true }
|
||||
pinakes-plugin-api = { workspace = true }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
|
|
|
|||
|
|
@ -19,12 +19,25 @@ pub struct MediaUpdateEvent {
|
|||
pub description: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ApiClient {
|
||||
client: Client,
|
||||
base_url: String,
|
||||
}
|
||||
|
||||
impl Clone for ApiClient {
|
||||
fn clone(&self) -> Self {
|
||||
Self::new(&self.base_url, None)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for ApiClient {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("ApiClient")
|
||||
.field("base_url", &self.base_url)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialEq for ApiClient {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.base_url == other.base_url
|
||||
|
|
@ -1598,6 +1611,49 @@ impl ApiClient {
|
|||
.build()
|
||||
.unwrap_or_else(|_| Client::new());
|
||||
}
|
||||
|
||||
/// List all UI pages provided by loaded plugins.
|
||||
///
|
||||
/// Returns a vector of `(plugin_id, page)` tuples.
|
||||
pub async fn get_plugin_ui_pages(
|
||||
&self,
|
||||
) -> Result<Vec<(String, pinakes_plugin_api::UiPage)>> {
|
||||
#[derive(Deserialize)]
|
||||
struct PageEntry {
|
||||
plugin_id: String,
|
||||
page: pinakes_plugin_api::UiPage,
|
||||
}
|
||||
|
||||
let entries: Vec<PageEntry> = self
|
||||
.client
|
||||
.get(self.url("/plugins/ui-pages"))
|
||||
.send()
|
||||
.await?
|
||||
.error_for_status()?
|
||||
.json()
|
||||
.await?;
|
||||
|
||||
Ok(entries.into_iter().map(|e| (e.plugin_id, e.page)).collect())
|
||||
}
|
||||
|
||||
/// Make a raw HTTP request to an API path.
|
||||
///
|
||||
/// The `path` is appended to the base URL without any prefix.
|
||||
/// Use this for plugin action endpoints that specify full API paths.
|
||||
pub fn raw_request(
|
||||
&self,
|
||||
method: reqwest::Method,
|
||||
path: &str,
|
||||
) -> reqwest::RequestBuilder {
|
||||
let url = format!("{}{}", self.base_url, path);
|
||||
self.client.request(method, url)
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ApiClient {
|
||||
fn default() -> Self {
|
||||
Self::new("", None)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue