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