refactor downloader full plugins list\
bump version
This commit is contained in:
@@ -1,8 +1,19 @@
|
|||||||
namespace TorchRemote.Models.Responses;
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace TorchRemote.Models.Responses;
|
||||||
|
|
||||||
public record PluginInfo(Guid Id, string Name, string Version);
|
public record PluginInfo(Guid Id, string Name, string Version);
|
||||||
|
public record InstalledPluginInfo(Guid Id, string Name, string Version, string? SettingId) : PluginInfo(Id, Name, Version);
|
||||||
|
|
||||||
public record PluginItemInfo(Guid Id, string Name, string Version, string Author) : PluginInfo(Id, Name, Version);
|
public record PluginItemInfo(
|
||||||
|
[property: JsonPropertyName("guid")] Guid Id,
|
||||||
public record FullPluginItemInfo(Guid Id, string Name, string Description, string Version, string Author) : PluginItemInfo(Id, Name, Version, Author);
|
string Name,
|
||||||
public record InstalledPluginInfo(Guid Id, string Name, string Version, string? SettingId) : PluginInfo(Id, Name, Version);
|
string Author,
|
||||||
|
string Description,
|
||||||
|
int Downloads,
|
||||||
|
bool Archived,
|
||||||
|
bool Private,
|
||||||
|
string LatestVersion,
|
||||||
|
IReadOnlyList<string> Versions,
|
||||||
|
string Icon
|
||||||
|
);
|
@@ -1,4 +1,6 @@
|
|||||||
using EmbedIO;
|
using System.Net.Http;
|
||||||
|
using System.Text.Json;
|
||||||
|
using EmbedIO;
|
||||||
using EmbedIO.Routing;
|
using EmbedIO.Routing;
|
||||||
using EmbedIO.WebApi;
|
using EmbedIO.WebApi;
|
||||||
using Torch.API.WebAPI;
|
using Torch.API.WebAPI;
|
||||||
@@ -7,27 +9,25 @@ using TorchRemote.Plugin.Utils;
|
|||||||
|
|
||||||
namespace TorchRemote.Plugin.Controllers;
|
namespace TorchRemote.Plugin.Controllers;
|
||||||
|
|
||||||
|
public record PluginsResponse(IReadOnlyList<PluginItemInfo> Plugins);
|
||||||
|
|
||||||
public class PluginDownloadsController : WebApiController
|
public class PluginDownloadsController : WebApiController
|
||||||
{
|
{
|
||||||
private const string RootPath = "/plugins/downloads";
|
private const string RootPath = "/plugins/downloads";
|
||||||
|
private const string BaseAddress = "https://torchapi.com/";
|
||||||
|
|
||||||
[Route(HttpVerbs.Get, RootPath)]
|
[Route(HttpVerbs.Get, RootPath)]
|
||||||
public async Task<IEnumerable<PluginInfo>> GetAsync()
|
public async Task<IEnumerable<PluginItemInfo>> GetAsync()
|
||||||
{
|
{
|
||||||
var response = await PluginQuery.Instance.QueryAll();
|
using var client = new HttpClient()
|
||||||
return response.Plugins.Select(b => new PluginItemInfo(Guid.Parse(b.ID), b.Name, b.LatestVersion, b.Author));
|
{
|
||||||
}
|
BaseAddress = new(BaseAddress)
|
||||||
|
};
|
||||||
[Route(HttpVerbs.Get, $"{RootPath}/{{id}}")]
|
using var stream = await client.GetStreamAsync("api/plugins");
|
||||||
public async Task<FullPluginItemInfo> GetFullAsync(Guid id)
|
|
||||||
{
|
|
||||||
var response = await PluginQuery.Instance.QueryOne(id);
|
|
||||||
|
|
||||||
if (response is null)
|
var response = await JsonSerializer.DeserializeAsync<PluginsResponse>(stream, Statics.SerializerOptions);
|
||||||
throw HttpException.NotFound("Plugin not found", id);
|
|
||||||
|
|
||||||
return new(Guid.Parse(response.ID), response.Name, response.Description, response.LatestVersion,
|
return response?.Plugins.Select(b => b with { Icon = BaseAddress + b.Icon }) ?? throw HttpException.InternalServerError("Torch site unavailable");
|
||||||
response.Author);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Route(HttpVerbs.Post, $"{RootPath}/{{id}}/install")]
|
[Route(HttpVerbs.Post, $"{RootPath}/{{id}}/install")]
|
||||||
@@ -42,7 +42,7 @@ public class PluginDownloadsController : WebApiController
|
|||||||
throw HttpException.NotFound("Plugin not found", id);
|
throw HttpException.NotFound("Plugin not found", id);
|
||||||
|
|
||||||
if (!await PluginQuery.Instance.DownloadPlugin(response))
|
if (!await PluginQuery.Instance.DownloadPlugin(response))
|
||||||
throw HttpException.InternalServerError();
|
throw HttpException.InternalServerError("Torch site unavailable");
|
||||||
|
|
||||||
Statics.Torch.Config.Plugins.Add(id);
|
Statics.Torch.Config.Plugins.Add(id);
|
||||||
}
|
}
|
||||||
|
@@ -2,5 +2,5 @@
|
|||||||
<PluginManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
<PluginManifest xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
||||||
<Name>Torch Remote</Name>
|
<Name>Torch Remote</Name>
|
||||||
<Guid>284017F3-9682-4841-A544-EB04DB8CB9BA</Guid>
|
<Guid>284017F3-9682-4841-A544-EB04DB8CB9BA</Guid>
|
||||||
<Version>v1.0.3</Version>
|
<Version>v1.0.4</Version>
|
||||||
</PluginManifest>
|
</PluginManifest>
|
Reference in New Issue
Block a user