Skip to main content

elemental_addon/builtins/liteloader/source/
endpoints.rs

1use elemental_core::url::{Origin, OriginPolicy};
2
3use crate::error::Result;
4
5pub(super) const KNOWN_LITELOADER_ORIGINS: &[&str] = &[
6    "https://dl.liteloader.com/versions",
7    "https://repo.mumfrey.com/content/repositories/snapshots",
8    "https://repo.spongepowered.org/maven",
9    "https://libraries.minecraft.net",
10    "https://repo.maven.apache.org/maven2",
11];
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
14pub enum LiteLoaderOrigin {
15    Downloads,
16    Snapshots,
17    SpongeMaven,
18    MojangLibraries,
19    MavenCentral,
20}
21
22#[derive(Debug, Clone)]
23pub struct LiteLoaderEndpoints {
24    pub(super) origin_policy: OriginPolicy,
25}
26
27impl Default for LiteLoaderEndpoints {
28    fn default() -> Self {
29        Self::official()
30    }
31}
32
33impl Origin for LiteLoaderOrigin {
34    fn canonical(self) -> &'static str {
35        match self {
36            Self::Downloads => "https://dl.liteloader.com/versions",
37            Self::Snapshots => "https://repo.mumfrey.com/content/repositories/snapshots",
38            Self::SpongeMaven => "https://repo.spongepowered.org/maven",
39            Self::MojangLibraries => "https://libraries.minecraft.net",
40            Self::MavenCentral => "https://repo.maven.apache.org/maven2",
41        }
42    }
43
44    fn all() -> &'static [Self] {
45        const ALL: &[LiteLoaderOrigin] = &[
46            LiteLoaderOrigin::Downloads,
47            LiteLoaderOrigin::Snapshots,
48            LiteLoaderOrigin::SpongeMaven,
49            LiteLoaderOrigin::MojangLibraries,
50            LiteLoaderOrigin::MavenCentral,
51        ];
52        ALL
53    }
54}
55
56impl AsRef<str> for LiteLoaderOrigin {
57    fn as_ref(&self) -> &str {
58        self.canonical()
59    }
60}
61
62impl LiteLoaderEndpoints {
63    pub fn new(origin_policy: OriginPolicy) -> Self {
64        Self { origin_policy }
65    }
66
67    pub fn official() -> Self {
68        Self::new(OriginPolicy::default())
69    }
70
71    pub fn versions_manifest_url(&self) -> Result<String> {
72        Ok(self
73            .origin_policy
74            .resolve(LiteLoaderOrigin::Downloads, "versions.json")?)
75    }
76
77    pub fn downloads_url(&self) -> Result<String> {
78        Ok(self
79            .origin_policy
80            .resolve(LiteLoaderOrigin::Downloads, "")?)
81    }
82
83    pub fn snapshots_url(&self) -> Result<String> {
84        Ok(self
85            .origin_policy
86            .resolve(LiteLoaderOrigin::Snapshots, "")?)
87    }
88
89    pub fn sponge_maven_url(&self) -> Result<String> {
90        Ok(self
91            .origin_policy
92            .resolve(LiteLoaderOrigin::SpongeMaven, "")?)
93    }
94
95    pub fn mojang_libraries_url(&self) -> Result<String> {
96        Ok(self
97            .origin_policy
98            .resolve(LiteLoaderOrigin::MojangLibraries, "")?)
99    }
100
101    pub fn maven_central_url(&self) -> Result<String> {
102        Ok(self
103            .origin_policy
104            .resolve(LiteLoaderOrigin::MavenCentral, "")?)
105    }
106}