mirror of
https://github.com/jie65535/GrasscutterCommandGenerator.git
synced 2025-12-08 08:38:23 +08:00
Update page navigation
Add Achievement page
This commit is contained in:
@@ -6,9 +6,9 @@ using Newtonsoft.Json;
|
||||
|
||||
namespace GrasscutterTools.Utils
|
||||
{
|
||||
internal class ReleaseAPI
|
||||
internal class GithubHelper
|
||||
{
|
||||
public static async Task<ReleaseInfo> GetReleasesLastest(string username, string repo)
|
||||
public static async Task<ReleaseInfo> GetReleasesLatest(string username, string repo)
|
||||
{
|
||||
var headerValue = new ProductInfoHeaderValue("GrasscutterTools", "1");
|
||||
try
|
||||
@@ -29,6 +29,23 @@ namespace GrasscutterTools.Utils
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<byte[]> DownloadRepo(string username, string repo, string branch)
|
||||
{
|
||||
byte[] zipBytes;
|
||||
try
|
||||
{
|
||||
zipBytes = await HttpHelper.GetDataAsync(
|
||||
$"https://github.com/{username}/{repo}/archive/refs/heads/{branch}.zip");
|
||||
}
|
||||
catch
|
||||
{
|
||||
zipBytes = await HttpHelper.GetDataAsync(
|
||||
$"https://hub.fastgit.org/{username}/{repo}/archive/refs/heads/{branch}.zip");
|
||||
}
|
||||
|
||||
return zipBytes;
|
||||
}
|
||||
|
||||
public class ReleaseInfo
|
||||
{
|
||||
[JsonProperty("tag_name")]
|
||||
@@ -38,7 +55,7 @@ namespace GrasscutterTools.Utils
|
||||
public string Url { get; set; }
|
||||
|
||||
[JsonProperty("created_at")]
|
||||
public DateTimeOffset CraeteTime { get; set; }
|
||||
public DateTimeOffset CreateTime { get; set; }
|
||||
|
||||
[JsonProperty("name")]
|
||||
public string Name { get; set; }
|
||||
@@ -44,15 +44,27 @@ namespace GrasscutterTools.Utils
|
||||
try
|
||||
{
|
||||
var responseMessage = await HttpClient.GetAsync(url);
|
||||
if (responseMessage.IsSuccessStatusCode)
|
||||
{
|
||||
var responseString = await responseMessage.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<T>(responseString);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!responseMessage.IsSuccessStatusCode)
|
||||
throw new HttpRequestException(responseMessage.ReasonPhrase);
|
||||
}
|
||||
var responseString = await responseMessage.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<T>(responseString);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (ex.InnerException != null)
|
||||
throw ex.InnerException;
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<byte[]> GetDataAsync(string url)
|
||||
{
|
||||
try
|
||||
{
|
||||
var responseMessage = await HttpClient.GetAsync(url);
|
||||
if (!responseMessage.IsSuccessStatusCode)
|
||||
throw new HttpRequestException(responseMessage.ReasonPhrase);
|
||||
return await responseMessage.Content.ReadAsByteArrayAsync();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -68,15 +80,10 @@ namespace GrasscutterTools.Utils
|
||||
{
|
||||
var content = new StringContent(JsonConvert.SerializeObject(obj), Encoding.UTF8, "application/json");
|
||||
var responseMessage = await HttpClient.PostAsync(url, content);
|
||||
if (responseMessage.IsSuccessStatusCode)
|
||||
{
|
||||
var responseString = await responseMessage.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<T>(responseString);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!responseMessage.IsSuccessStatusCode)
|
||||
throw new HttpRequestException(responseMessage.ReasonPhrase);
|
||||
}
|
||||
var responseString = await responseMessage.Content.ReadAsStringAsync();
|
||||
return JsonConvert.DeserializeObject<T>(responseString);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user