@@ -24,6 +24,8 @@ public static class ModrinthAPIHelper
2424{
2525 const string BaseUrl = "https://api.modrinth.com/v2" ;
2626
27+ public static string ? ApiBaseUrl { get ; set ; }
28+
2729 static async Task < HttpResponseMessage > Get ( string reqUrl , CancellationToken ct = default )
2830 {
2931 var req = await HttpHelper . Get ( reqUrl , ct : ct ) ;
@@ -34,7 +36,7 @@ static async Task<HttpResponseMessage> Get(string reqUrl, CancellationToken ct =
3436
3537 public static async Task < ModrinthCategoryInfo [ ] ? > GetCategories ( )
3638 {
37- const string reqUrl = $ "{ BaseUrl } /tag/category";
39+ var reqUrl = $ "{ ApiBaseUrl ?? BaseUrl } /tag/category";
3840
3941 using var res = await Get ( reqUrl ) ;
4042 var resModel =
@@ -45,7 +47,7 @@ static async Task<HttpResponseMessage> Get(string reqUrl, CancellationToken ct =
4547
4648 public static async Task < ModrinthProjectDependencyInfo ? > GetProjectDependenciesInfo ( string projectId )
4749 {
48- var reqUrl = $ "{ BaseUrl } /project/{ projectId } /dependencies";
50+ var reqUrl = $ "{ ApiBaseUrl ?? BaseUrl } /project/{ projectId } /dependencies";
4951
5052 using var res = await Get ( reqUrl ) ;
5153 var resModel =
@@ -57,7 +59,7 @@ await res.Content.ReadFromJsonAsync(ModrinthProjectDependencyInfoContext.Default
5759
5860 public static async Task < ModrinthProjectInfo ? > GetProject ( string projectId , CancellationToken ct )
5961 {
60- var reqUrl = $ "{ BaseUrl } /project/{ projectId } ";
62+ var reqUrl = $ "{ ApiBaseUrl ?? BaseUrl } /project/{ projectId } ";
6163
6264 using var res = await Get ( reqUrl , ct ) ;
6365 var resModel = await res . Content . ReadFromJsonAsync ( ModrinthProjectInfoContext . Default . ModrinthProjectInfo , ct ) ;
@@ -67,7 +69,7 @@ await res.Content.ReadFromJsonAsync(ModrinthProjectDependencyInfoContext.Default
6769
6870 public static async Task < ModrinthSearchResult ? > GetFeaturedMods ( )
6971 {
70- const string reqUrl = $ "{ BaseUrl } /search";
72+ var reqUrl = $ "{ ApiBaseUrl ?? BaseUrl } /search";
7173
7274 using var res = await Get ( reqUrl ) ;
7375 var resModel = await res . Content . ReadFromJsonAsync ( ModrinthSearchResultContext . Default . ModrinthSearchResult ) ;
@@ -77,7 +79,7 @@ await res.Content.ReadFromJsonAsync(ModrinthProjectDependencyInfoContext.Default
7779
7880 public static async Task < ModrinthSearchResult ? > SearchMod ( ModrinthSearchOptions searchOptions , CancellationToken ct )
7981 {
80- var reqUrl = $ "{ BaseUrl } /search{ searchOptions } ";
82+ var reqUrl = $ "{ ApiBaseUrl ?? BaseUrl } /search{ searchOptions } ";
8183
8284 using var res = await Get ( reqUrl , ct ) ;
8385 var resModel = await res . Content . ReadFromJsonAsync ( ModrinthSearchResultContext . Default . ModrinthSearchResult , ct ) ;
@@ -87,7 +89,7 @@ await res.Content.ReadFromJsonAsync(ModrinthProjectDependencyInfoContext.Default
8789
8890 public static async Task < ModrinthVersionInfo [ ] ? > GetProjectVersions ( string projectId )
8991 {
90- var reqUrl = $ "{ BaseUrl } /project/{ projectId } /version";
92+ var reqUrl = $ "{ ApiBaseUrl ?? BaseUrl } /project/{ projectId } /version";
9193
9294 using var res = await Get ( reqUrl ) ;
9395 var resModel = await res . Content . ReadFromJsonAsync ( ModrinthVersionInfoContext . Default . ModrinthVersionInfoArray ) ;
@@ -105,7 +107,7 @@ await res.Content.ReadFromJsonAsync(ModrinthProjectDependencyInfoContext.Default
105107 HashType . SHA512 => "?algorithm=sha512" ,
106108 _ => throw new ArgumentOutOfRangeException ( nameof ( hashType ) , hashType , null )
107109 } ;
108- var reqUrl = $ "{ BaseUrl } /version_file/{ hash } { para } ";
110+ var reqUrl = $ "{ ApiBaseUrl ?? BaseUrl } /version_file/{ hash } { para } ";
109111
110112 using var res = await Get ( reqUrl ) ;
111113 var resModel = await res . Content . ReadFromJsonAsync ( ModrinthVersionInfoContext . Default . ModrinthVersionInfo ) ;
@@ -115,7 +117,7 @@ await res.Content.ReadFromJsonAsync(ModrinthProjectDependencyInfoContext.Default
115117
116118 public static async Task < ModrinthVersionInfo ? > GetVersionInfo ( string projectId , string versionId )
117119 {
118- var reqUrl = $ "{ BaseUrl } /project/{ projectId } /version/{ versionId } ";
120+ var reqUrl = $ "{ ApiBaseUrl ?? BaseUrl } /project/{ projectId } /version/{ versionId } ";
119121
120122 using var res = await Get ( reqUrl ) ;
121123 var resModel = await res . Content . ReadFromJsonAsync ( ModrinthVersionInfoContext . Default . ModrinthVersionInfo ) ;
@@ -125,7 +127,7 @@ await res.Content.ReadFromJsonAsync(ModrinthProjectDependencyInfoContext.Default
125127
126128 public static async Task < ModrinthVersionInfo ? > GetVersionInfo ( string versionId )
127129 {
128- var reqUrl = $ "{ BaseUrl } /version/{ versionId } ";
130+ var reqUrl = $ "{ ApiBaseUrl ?? BaseUrl } /version/{ versionId } ";
129131
130132 using var res = await Get ( reqUrl ) ;
131133 var resModel = await res . Content . ReadFromJsonAsync ( ModrinthVersionInfoContext . Default . ModrinthVersionInfo ) ;
@@ -139,7 +141,7 @@ await res.Content.ReadFromJsonAsync(ModrinthProjectDependencyInfoContext.Default
139141 string [ ] loaders ,
140142 string [ ] gameVersions )
141143 {
142- const string reqUrl = $ "{ BaseUrl } /version_files/update";
144+ var reqUrl = $ "{ ApiBaseUrl ?? BaseUrl } /version_files/update";
143145
144146 var data = JsonSerializer . Serialize ( new FileMatchRequestModel ( hashes , algorithm , loaders , gameVersions ) ,
145147 ModrinthModelContext . Default . FileMatchRequestModel ) ;
0 commit comments