1use strum_macros::EnumIter;
2
3use crate::proxy::Proxy;
4
5#[cfg_attr(feature = "wasm", wasm_bindgen::prelude::wasm_bindgen)]
7#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
8#[derive(EnumIter, Debug, PartialEq, Hash, Eq, Clone)]
9pub enum GitHubResource {
10 File {
14 owner: String,
15 repo: String,
16 reference: String,
17 path: String,
18 },
19 Release {
22 owner: String,
23 repo: String,
24 tag: String,
25 name: String,
26 },
27}
28
29impl GitHubResource {
30 pub fn file(owner: String, repo: String, reference: String, path: String) -> Self {
38 GitHubResource::File {
39 owner,
40 repo,
41 reference,
42 path,
43 }
44 }
45
46 pub fn release(owner: String, repo: String, tag: String, name: String) -> Self {
48 GitHubResource::Release {
49 owner,
50 repo,
51 tag,
52 name,
53 }
54 }
55
56 pub fn url(&self, proxy_type: &Proxy) -> String {
58 match self {
59 GitHubResource::File {
60 owner,
61 repo,
62 reference,
63 path,
64 } => match proxy_type {
65 Proxy::GitHub => {
66 format!(
67 "https://github.com/{}/{}/raw/{}/{}",
68 owner, repo, reference, path
69 )
70 }
71 Proxy::Xget => {
72 format!(
73 "https://xget.xi-xu.me/gh/{}/{}/raw/{}/{}",
74 owner, repo, reference, path
75 )
76 }
77 Proxy::GhProxy => {
78 format!(
79 "https://gh-proxy.com/https://github.com/{}/{}/raw/{}/{}",
80 owner, repo, reference, path
81 )
82 }
83 Proxy::Jsdelivr => {
84 format!(
85 "https://cdn.jsdelivr.net/gh/{}/{}@{}/{}",
86 owner, repo, reference, path
87 )
88 }
89 },
90 GitHubResource::Release {
91 owner,
92 repo,
93 tag,
94 name,
95 } => match proxy_type {
96 Proxy::GitHub => {
97 format!(
98 "https://github.com/{}/{}/releases/download/{}/{}",
99 owner, repo, tag, name
100 )
101 }
102 Proxy::Xget => {
103 format!(
104 "https://xget.xi-xu.me/gh/{}/{}/releases/download/{}/{}",
105 owner, repo, tag, name
106 )
107 }
108 Proxy::GhProxy => {
109 format!(
110 "https://gh-proxy.com/https://github.com/{}/{}/releases/download/{}/{}",
111 owner, repo, tag, name
112 )
113 }
114 Proxy::Jsdelivr => {
115 format!(
116 "https://cdn.jsdelivr.net/gh/{}/{}@{}/{}",
117 owner, repo, tag, name
118 )
119 }
120 },
121 }
122 }
123}