Files
Moonlight/Moonlight.ApiServer/Http/Controllers/FrontendController.cs

39 lines
1.2 KiB
C#

using System.Text.Json;
using Microsoft.AspNetCore.Mvc;
using MoonCore.Exceptions;
using MoonCore.Helpers;
using Moonlight.ApiServer.Configuration;
using Moonlight.ApiServer.Services;
using Moonlight.Shared.Misc;
namespace Moonlight.ApiServer.Http.Controllers;
[ApiController]
public class FrontendController : Controller
{
private readonly FrontendService FrontendService;
private readonly PluginService PluginService;
public FrontendController(FrontendService frontendService, PluginService pluginService)
{
FrontendService = frontendService;
PluginService = pluginService;
}
[HttpGet("frontend.json")]
public async Task<FrontendConfiguration> GetConfiguration()
=> await FrontendService.GetConfiguration();
[HttpGet("plugins/{assemblyName}")]
public async Task GetPluginAssembly(string assemblyName)
{
var assembliesMap = PluginService.GetAssemblies("client");
if (assembliesMap.ContainsKey(assemblyName))
throw new HttpApiException("The requested assembly could not be found", 404);
var path = assembliesMap[assemblyName];
await Results.File(path).ExecuteAsync(HttpContext);
}
}