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 PluginItemInfo(Guid Id, string Name, string Version, string Author) : PluginInfo(Id, Name, Version);
|
||||
|
||||
public record FullPluginItemInfo(Guid Id, string Name, string Description, string Version, string Author) : PluginItemInfo(Id, Name, Version, Author);
|
||||
public record InstalledPluginInfo(Guid Id, string Name, string Version, string? SettingId) : PluginInfo(Id, Name, Version);
|
||||
|
||||
public record PluginItemInfo(
|
||||
[property: JsonPropertyName("guid")] Guid Id,
|
||||
string Name,
|
||||
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.WebApi;
|
||||
using Torch.API.WebAPI;
|
||||
@@ -7,27 +9,25 @@ using TorchRemote.Plugin.Utils;
|
||||
|
||||
namespace TorchRemote.Plugin.Controllers;
|
||||
|
||||
public record PluginsResponse(IReadOnlyList<PluginItemInfo> Plugins);
|
||||
|
||||
public class PluginDownloadsController : WebApiController
|
||||
{
|
||||
private const string RootPath = "/plugins/downloads";
|
||||
private const string BaseAddress = "https://torchapi.com/";
|
||||
|
||||
[Route(HttpVerbs.Get, RootPath)]
|
||||
public async Task<IEnumerable<PluginInfo>> GetAsync()
|
||||
public async Task<IEnumerable<PluginItemInfo>> GetAsync()
|
||||
{
|
||||
var response = await PluginQuery.Instance.QueryAll();
|
||||
return response.Plugins.Select(b => new PluginItemInfo(Guid.Parse(b.ID), b.Name, b.LatestVersion, b.Author));
|
||||
}
|
||||
using var client = new HttpClient()
|
||||
{
|
||||
BaseAddress = new(BaseAddress)
|
||||
};
|
||||
using var stream = await client.GetStreamAsync("api/plugins");
|
||||
|
||||
[Route(HttpVerbs.Get, $"{RootPath}/{{id}}")]
|
||||
public async Task<FullPluginItemInfo> GetFullAsync(Guid id)
|
||||
{
|
||||
var response = await PluginQuery.Instance.QueryOne(id);
|
||||
var response = await JsonSerializer.DeserializeAsync<PluginsResponse>(stream, Statics.SerializerOptions);
|
||||
|
||||
if (response is null)
|
||||
throw HttpException.NotFound("Plugin not found", id);
|
||||
|
||||
return new(Guid.Parse(response.ID), response.Name, response.Description, response.LatestVersion,
|
||||
response.Author);
|
||||
return response?.Plugins.Select(b => b with { Icon = BaseAddress + b.Icon }) ?? throw HttpException.InternalServerError("Torch site unavailable");
|
||||
}
|
||||
|
||||
[Route(HttpVerbs.Post, $"{RootPath}/{{id}}/install")]
|
||||
@@ -42,7 +42,7 @@ public class PluginDownloadsController : WebApiController
|
||||
throw HttpException.NotFound("Plugin not found", id);
|
||||
|
||||
if (!await PluginQuery.Instance.DownloadPlugin(response))
|
||||
throw HttpException.InternalServerError();
|
||||
throw HttpException.InternalServerError("Torch site unavailable");
|
||||
|
||||
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">
|
||||
<Name>Torch Remote</Name>
|
||||
<Guid>284017F3-9682-4841-A544-EB04DB8CB9BA</Guid>
|
||||
<Version>v1.0.3</Version>
|
||||
<Version>v1.0.4</Version>
|
||||
</PluginManifest>
|
Reference in New Issue
Block a user