mirror of
https://github.com/MaaAssistantArknights/MaaAssistantArknights.git
synced 2026-07-16 01:40:46 +08:00
perf: add some mirror for resource updates
This commit is contained in:
@@ -144,6 +144,7 @@ namespace MaaWpfGui.Constants
|
||||
public const string VersionType = "VersionUpdate.VersionType";
|
||||
public const string UpdateCheck = "VersionUpdate.UpdateCheck";
|
||||
public const string UpdateAutoCheck = "VersionUpdate.ScheduledUpdateCheck";
|
||||
public const string ResourceApi = "VersionUpdate.ResourceApi";
|
||||
|
||||
// 这个已经废弃了,还要留着吗?
|
||||
// ReSharper disable once UnusedMember.Global
|
||||
|
||||
@@ -44,6 +44,8 @@ namespace MaaWpfGui.Constants
|
||||
|
||||
public const string MaaResourceApi = "https://ota.maa.plus/MaaAssistantArknights/MaaAssistantArknights/";
|
||||
public const string AnnMirrorResourceApi = "https://maa-ota.annangela.cn/MaaAssistantArknights/MaaAssistantArknights/";
|
||||
public const string S3ResourceApi = "https://s3.maa-org.net:25240/maa-resources/MaaAssistantArknights/MaaAssistantArknights/";
|
||||
public const string R2ResourceApi = "https://maa.r2.imgg.dev/MaaAssistantArknights/MaaAssistantArknights/";
|
||||
|
||||
public const string QqGroups = "https://ota.maa.plus/MaaAssistantArknights/api/qqgroup/index.html";
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Documents;
|
||||
using MaaWpfGui.Constants;
|
||||
using MaaWpfGui.Helper;
|
||||
using Stylet;
|
||||
@@ -88,10 +89,42 @@ namespace MaaWpfGui.Models
|
||||
|
||||
private static async Task<string> GetResourceApi()
|
||||
{
|
||||
var response = await Instances.HttpService.GetAsync(new Uri(MaaUrls.AnnMirrorResourceApi), httpCompletionOption: HttpCompletionOption.ResponseHeadersRead);
|
||||
return response is { StatusCode: System.Net.HttpStatusCode.OK }
|
||||
? MaaUrls.AnnMirrorResourceApi
|
||||
: MaaUrls.MaaResourceApi;
|
||||
string mirror = ConfigurationHelper.GetValue(ConfigurationKeys.ResourceApi, string.Empty);
|
||||
if (!string.IsNullOrEmpty(mirror))
|
||||
{
|
||||
return mirror;
|
||||
}
|
||||
|
||||
var mirrorList = new List<string>
|
||||
{
|
||||
MaaUrls.S3ResourceApi,
|
||||
MaaUrls.R2ResourceApi,
|
||||
MaaUrls.AnnMirrorResourceApi,
|
||||
};
|
||||
|
||||
while (mirrorList.Count != 0)
|
||||
{
|
||||
// random select a mirror
|
||||
var index = new Random().Next(0, mirrorList.Count);
|
||||
var mirrorUrl = mirrorList[index];
|
||||
|
||||
var response = await Instances.HttpService.GetAsync(new Uri(mirrorUrl + MaaResourceVersion), httpCompletionOption: HttpCompletionOption.ResponseHeadersRead);
|
||||
if (response is { StatusCode: System.Net.HttpStatusCode.OK })
|
||||
{
|
||||
mirror = mirrorUrl;
|
||||
break;
|
||||
}
|
||||
|
||||
mirrorList.RemoveAt(index);
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(mirror))
|
||||
{
|
||||
mirror = MaaUrls.MaaResourceApi;
|
||||
}
|
||||
|
||||
ConfigurationHelper.SetValue(ConfigurationKeys.ResourceApi, mirror);
|
||||
return mirror;
|
||||
}
|
||||
|
||||
private static async Task<bool> CheckUpdate(string baseUrl)
|
||||
|
||||
Reference in New Issue
Block a user