mirror of
https://github.com/wwiinnddyy/LanMountainDesktop.git
synced 2026-06-22 00:54:26 +08:00
feat.在线安装器,更好的Issue与pull request模板。
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
namespace LanDesktopPLONDS.Installer.Services;
|
||||
|
||||
internal static class InstallerPlondsUrlResolver
|
||||
{
|
||||
public static IReadOnlyList<Uri> ResolveFilesZipUrls(
|
||||
InstallerPlondsManifest manifest,
|
||||
InstallerPlondsSource source)
|
||||
{
|
||||
var urls = new List<string?>();
|
||||
var sourceKind = source.Kind.Trim().ToLowerInvariant();
|
||||
|
||||
if (sourceKind is "s3")
|
||||
{
|
||||
urls.Add(manifest.Downloads?.S3?.FilesZipUrl);
|
||||
}
|
||||
else if (sourceKind is "github")
|
||||
{
|
||||
urls.Add(manifest.Downloads?.GitHub?.FilesZipUrl);
|
||||
}
|
||||
|
||||
urls.Add(DerivePackageUrl(source.ManifestUrl));
|
||||
urls.Add(manifest.Downloads?.S3?.FilesZipUrl);
|
||||
urls.Add(manifest.Downloads?.GitHub?.FilesZipUrl);
|
||||
|
||||
return urls
|
||||
.Where(url => !string.IsNullOrWhiteSpace(url))
|
||||
.Select(url => Uri.TryCreate(url, UriKind.Absolute, out var uri) ? uri : null)
|
||||
.OfType<Uri>()
|
||||
.Where(uri => uri.Scheme is "http" or "https")
|
||||
.DistinctBy(uri => uri.AbsoluteUri, StringComparer.OrdinalIgnoreCase)
|
||||
.ToArray();
|
||||
}
|
||||
|
||||
private static string? DerivePackageUrl(string manifestUrl)
|
||||
{
|
||||
if (!Uri.TryCreate(manifestUrl, UriKind.Absolute, out var uri) ||
|
||||
uri.Scheme is not ("http" or "https"))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var builder = new UriBuilder(uri);
|
||||
var lastSlash = builder.Path.LastIndexOf('/');
|
||||
builder.Path = lastSlash >= 0
|
||||
? $"{builder.Path[..(lastSlash + 1)]}Files.zip"
|
||||
: "Files.zip";
|
||||
builder.Query = string.Empty;
|
||||
builder.Fragment = string.Empty;
|
||||
return builder.Uri.AbsoluteUri;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user