GUI plugins #9
3 changed files with 59 additions and 1 deletions
pinakes-ui: add ApiClient plugin methods; depend on plugin API
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ica7f913a22d18e59e85f1959a5b336df6a6a6964
commit
5b204dceb5
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -5516,6 +5516,7 @@ dependencies = [
|
||||||
"gloo-timers",
|
"gloo-timers",
|
||||||
"grass",
|
"grass",
|
||||||
"gray_matter",
|
"gray_matter",
|
||||||
|
"pinakes-plugin-api",
|
||||||
"pulldown-cmark",
|
"pulldown-cmark",
|
||||||
"rand 0.10.0",
|
"rand 0.10.0",
|
||||||
"regex",
|
"regex",
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ dioxus-free-icons = { workspace = true }
|
||||||
gloo-timers = { workspace = true }
|
gloo-timers = { workspace = true }
|
||||||
rand = { workspace = true }
|
rand = { workspace = true }
|
||||||
urlencoding = { workspace = true }
|
urlencoding = { workspace = true }
|
||||||
|
pinakes-plugin-api = { workspace = true }
|
||||||
|
|
||||||
[lints]
|
[lints]
|
||||||
workspace = true
|
workspace = true
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,25 @@ pub struct MediaUpdateEvent {
|
||||||
pub description: Option<String>,
|
pub description: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct ApiClient {
|
pub struct ApiClient {
|
||||||
client: Client,
|
client: Client,
|
||||||
base_url: String,
|
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 {
|
impl PartialEq for ApiClient {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
self.base_url == other.base_url
|
self.base_url == other.base_url
|
||||||
|
|
@ -1598,6 +1611,49 @@ impl ApiClient {
|
||||||
.build()
|
.build()
|
||||||
.unwrap_or_else(|_| Client::new());
|
.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)]
|
#[cfg(test)]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue