elemental_addon/builtins/liteloader/
source.rs1mod endpoints;
2mod rewrite;
3
4use elemental_core::http::{RequestBuilderExt, SwappableClient};
5
6use crate::error::Result;
7
8use super::manifest::{LiteLoaderManifest, collect_releases};
9
10pub use super::manifest::LiteLoaderRelease;
11pub use endpoints::{LiteLoaderEndpoints, LiteLoaderOrigin};
12
13#[derive(Debug, Clone)]
15pub struct LiteLoaderSource {
16 client: SwappableClient,
17 endpoints: LiteLoaderEndpoints,
18}
19
20impl Default for LiteLoaderSource {
21 fn default() -> Self {
22 Self::new(LiteLoaderEndpoints::default())
23 }
24}
25
26impl LiteLoaderSource {
27 pub fn new(endpoints: LiteLoaderEndpoints) -> Self {
29 Self {
30 client: SwappableClient::default(),
31 endpoints,
32 }
33 }
34
35 pub fn with_http_client(mut self, client: SwappableClient) -> Self {
37 self.client = client;
38 self
39 }
40
41 pub fn endpoints(&self) -> &LiteLoaderEndpoints {
43 &self.endpoints
44 }
45
46 pub(super) fn http_client(&self) -> &SwappableClient {
47 &self.client
48 }
49
50 pub async fn releases(&self) -> Result<Vec<LiteLoaderRelease>> {
52 let manifest = self.manifest().await?;
53 Ok(collect_releases(manifest))
54 }
55
56 pub(super) async fn manifest(&self) -> Result<LiteLoaderManifest> {
57 let url = self.endpoints.versions_manifest_url()?;
58 Ok(self.client.get(url.as_str()).send_json().await?)
59 }
60}