Improved asset service. Removed now unused plugin asset streaming endpoint

This commit is contained in:
2024-12-01 20:04:29 +01:00
parent 0a76e64d2f
commit 62fe6089f7
6 changed files with 83 additions and 54 deletions

View File

@@ -0,0 +1,27 @@
using Microsoft.AspNetCore.Mvc;
using Moonlight.ApiServer.Services;
using Moonlight.Shared.Http.Responses.Assets;
namespace Moonlight.ApiServer.Http.Controllers.Assets;
[ApiController]
[Route("api/assets")]
public class AssetsController : Controller
{
private readonly AssetService AssetService;
public AssetsController(AssetService assetService)
{
AssetService = assetService;
}
[HttpGet]
public async Task<FrontendAssetResponse> Get()
{
return new FrontendAssetResponse()
{
CssFiles = AssetService.GetCssAssets(),
JavascriptFiles = AssetService.GetJavascriptAssets(),
};
}
}

View File

@@ -0,0 +1,37 @@
using Microsoft.AspNetCore.Mvc;
using MoonCore.Exceptions;
using MoonCore.Models;
using Moonlight.ApiServer.Services;
namespace Moonlight.ApiServer.Http.Controllers.Assets;
[ApiController]
[Route("api/assets/plugins")]
public class AssetsPluginsController : Controller
{
private readonly PluginService PluginService;
public AssetsPluginsController(PluginService pluginService)
{
PluginService = pluginService;
}
[HttpGet]
public Task<HostedPluginsManifest> GetManifest()
{
return Task.FromResult(PluginService.HostedPluginsManifest);
}
[HttpGet("stream")]
public async Task GetAssembly([FromQuery(Name = "assembly")] string assembly)
{
var assembliesMap = PluginService.ClientAssemblyMap;
if (assembliesMap.ContainsKey(assembly))
throw new HttpApiException("The requested assembly could not be found", 404);
var path = assembliesMap[assembly];
await Results.File(path).ExecuteAsync(HttpContext);
}
}