2022-11-21 02:23:25 +01:00
|
|
|
using System;
|
2023-01-16 12:12:51 +01:00
|
|
|
using System.Collections.Generic;
|
2022-11-21 02:23:25 +01:00
|
|
|
using System.Net.Http;
|
2023-01-16 12:12:51 +01:00
|
|
|
using System.Text.RegularExpressions;
|
2022-11-21 02:23:25 +01:00
|
|
|
using System.Threading.Tasks;
|
2023-01-16 12:12:51 +01:00
|
|
|
using ExchangeSharp;
|
2022-11-21 02:23:25 +01:00
|
|
|
using Newtonsoft.Json;
|
|
|
|
using Newtonsoft.Json.Linq;
|
2023-01-16 12:12:51 +01:00
|
|
|
using static System.Net.WebRequestMethods;
|
2022-11-21 02:23:25 +01:00
|
|
|
|
|
|
|
namespace BTCPayServer.Plugins
|
|
|
|
{
|
|
|
|
public class PublishedVersion
|
|
|
|
{
|
2023-01-16 12:12:51 +01:00
|
|
|
public class BuildInfoClass
|
|
|
|
{
|
|
|
|
public string gitCommit { get; set; }
|
|
|
|
public string pluginDir { get; set; }
|
|
|
|
public string gitRepository { get; set; }
|
|
|
|
#nullable enable
|
|
|
|
static Regex GithubRepositoryRegex = new Regex("^https://(www\\.)?github\\.com/([^/]+)/([^/]+)/?");
|
|
|
|
public record GithubRepository(string Owner, string RepositoryName)
|
|
|
|
{
|
|
|
|
public string? GetSourceUrl(string commit, string pluginDir)
|
|
|
|
{
|
|
|
|
if (commit is null)
|
|
|
|
return null;
|
|
|
|
return $"https://github.com/{Owner}/{RepositoryName}/tree/{commit}/{pluginDir}";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
public GithubRepository? GetGithubRepository()
|
|
|
|
{
|
|
|
|
if (gitRepository is null)
|
|
|
|
return null;
|
|
|
|
var match = GithubRepositoryRegex.Match(gitRepository);
|
|
|
|
if (!match.Success)
|
|
|
|
return null;
|
|
|
|
return new GithubRepository(match.Groups[2].Value, match.Groups[3].Value);
|
|
|
|
}
|
|
|
|
#nullable restore
|
|
|
|
[JsonExtensionData]
|
|
|
|
public IDictionary<string, JToken> AdditionalData { get; set; }
|
|
|
|
}
|
2022-11-21 02:23:25 +01:00
|
|
|
public string ProjectSlug { get; set; }
|
|
|
|
public long BuildId { get; set; }
|
2023-01-16 12:12:51 +01:00
|
|
|
public BuildInfoClass BuildInfo { get; set; }
|
2022-11-21 02:23:25 +01:00
|
|
|
public JObject ManifestInfo { get; set; }
|
2022-11-22 11:06:23 +01:00
|
|
|
public string Documentation { get; set; }
|
2022-11-21 02:23:25 +01:00
|
|
|
}
|
|
|
|
public class PluginBuilderClient
|
|
|
|
{
|
|
|
|
HttpClient httpClient;
|
|
|
|
public HttpClient HttpClient => httpClient;
|
|
|
|
public PluginBuilderClient(HttpClient httpClient)
|
|
|
|
{
|
|
|
|
this.httpClient = httpClient;
|
|
|
|
}
|
|
|
|
static JsonSerializerSettings serializerSettings = new JsonSerializerSettings() { ContractResolver = new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver() };
|
|
|
|
public async Task<PublishedVersion[]> GetPublishedVersions(string btcpayVersion, bool includePreRelease)
|
|
|
|
{
|
|
|
|
var result = await httpClient.GetStringAsync($"api/v1/plugins?btcpayVersion={btcpayVersion}&includePreRelease={includePreRelease}");
|
|
|
|
return JsonConvert.DeserializeObject<PublishedVersion[]>(result, serializerSettings) ?? throw new InvalidOperationException();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|