diff --git a/Moonlight.ApiServer/Http/Controllers/FrontendController.cs b/Moonlight.ApiServer/Http/Controllers/FrontendController.cs new file mode 100644 index 00000000..fb53d9ed --- /dev/null +++ b/Moonlight.ApiServer/Http/Controllers/FrontendController.cs @@ -0,0 +1,57 @@ +using Microsoft.AspNetCore.Mvc; +using MoonCore.Exceptions; +using Moonlight.ApiServer.Configuration; +using Moonlight.ApiServer.Services; +using Moonlight.Shared.Misc; + +namespace Moonlight.ApiServer.Http.Controllers; + +[ApiController] +public class FrontendController : Controller +{ + private readonly AppConfiguration Configuration; + private readonly PluginService PluginService; + private readonly AssetService AssetService; + + public FrontendController( + AppConfiguration configuration, + PluginService pluginService, + AssetService assetService + ) + { + Configuration = configuration; + PluginService = pluginService; + AssetService = assetService; + } + + [HttpGet("frontend.json")] + public async Task GetConfiguration() + { + var configuration = new FrontendConfiguration() + { + Title = "Moonlight", + ApiUrl = Configuration.PublicUrl, + HostEnvironment = "ApiServer" + }; + + configuration.Plugins.Entrypoints = PluginService.HostedPluginsManifest.Entrypoints; + configuration.Plugins.Assemblies = PluginService.HostedPluginsManifest.Assemblies; + + configuration.Scripts = AssetService.GetJavascriptAssets(); + + return configuration; + } + + [HttpGet("plugins/{assemblyName}")] + public async Task GetPluginAssembly(string assemblyName) + { + var assembliesMap = PluginService.ClientAssemblyMap; + + 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); + } +} \ No newline at end of file diff --git a/Moonlight.ApiServer/Http/Controllers/OAuth2/Pages/Login.razor b/Moonlight.ApiServer/Http/Controllers/OAuth2/Pages/Login.razor deleted file mode 100644 index ce39a655..00000000 --- a/Moonlight.ApiServer/Http/Controllers/OAuth2/Pages/Login.razor +++ /dev/null @@ -1,66 +0,0 @@ - - - Login to your moonlight account - - - - - - -
-
- Your Company -

Sign in to your account

-
- -
-
-
- -
- -
-
- -
-
- - -
-
- -
-
- -
- -
-
- -

- Not a member? - - @{ - var registerUrl = $"?response_type={ResponseType}&client_id={ClientId}&redirect_uri={RedirectUri}&action=register"; - } - - Register now -

-
-
- - - -@code -{ - [Parameter] - public string ClientId { get; set; } - - [Parameter] - public string RedirectUri { get; set; } - - [Parameter] - public string ResponseType { get; set; } -} diff --git a/Moonlight.ApiServer/Http/Controllers/OAuth2/Pages/Register.razor b/Moonlight.ApiServer/Http/Controllers/OAuth2/Pages/Register.razor deleted file mode 100644 index ca8a9ba0..00000000 --- a/Moonlight.ApiServer/Http/Controllers/OAuth2/Pages/Register.razor +++ /dev/null @@ -1,74 +0,0 @@ - - - Register your moonlight account - - - - - - -
-
- Your Company -

Create your account

-
- -
-
- -
- -
- -
-
- -
- -
- -
-
- -
-
- - -
-
- -
-
- -
- -
-
- -

- Already a member? - - @{ - var loginUrl = $"?response_type={ResponseType}&client_id={ClientId}&redirect_uri={RedirectUri}&action=login"; - } - - Login now -

-
-
- - - -@code -{ - [Parameter] - public string ClientId { get; set; } - - [Parameter] - public string RedirectUri { get; set; } - - [Parameter] - public string ResponseType { get; set; } -} diff --git a/Moonlight.ApiServer/Implementations/OAuth2/LocalOAuth2Provider.cs b/Moonlight.ApiServer/Implementations/OAuth2/LocalOAuth2Provider.cs index d4c43d92..8c48018e 100644 --- a/Moonlight.ApiServer/Implementations/OAuth2/LocalOAuth2Provider.cs +++ b/Moonlight.ApiServer/Implementations/OAuth2/LocalOAuth2Provider.cs @@ -1,3 +1,4 @@ +using Microsoft.EntityFrameworkCore; using MoonCore.Exceptions; using MoonCore.Extended.Abstractions; using MoonCore.Extended.Helpers; @@ -15,17 +16,18 @@ public class LocalOAuth2Provider : ILocalProviderImplementation UserRepository = userRepository; } - public Task SaveChanges(User model) + public async Task SaveChanges(User model) { - UserRepository.Update(model); - return Task.CompletedTask; + await UserRepository.Update(model); } - public Task LoadById(int id) + public async Task LoadById(int id) { - var res = UserRepository.Get().FirstOrDefault(x => x.Id == id); + var res = await UserRepository + .Get() + .FirstOrDefaultAsync(x => x.Id == id); - return Task.FromResult(res); + return res; } public Task Login(string email, string password) diff --git a/Moonlight.ApiServer/Moonlight.ApiServer.csproj b/Moonlight.ApiServer/Moonlight.ApiServer.csproj index a50dfe2d..92e6e958 100644 --- a/Moonlight.ApiServer/Moonlight.ApiServer.csproj +++ b/Moonlight.ApiServer/Moonlight.ApiServer.csproj @@ -25,7 +25,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive - + @@ -39,6 +39,7 @@ + @@ -47,4 +48,9 @@ + + <_ContentIncludedByDefault Remove="Http\Controllers\OAuth2\Pages\Login.razor" /> + <_ContentIncludedByDefault Remove="Http\Controllers\OAuth2\Pages\Register.razor" /> + + diff --git a/Moonlight.Client/Implementations/RemotePluginSource.cs b/Moonlight.Client/Implementations/RemotePluginSource.cs new file mode 100644 index 00000000..eba47421 --- /dev/null +++ b/Moonlight.Client/Implementations/RemotePluginSource.cs @@ -0,0 +1,41 @@ +using System.Runtime.Loader; +using MoonCore.Plugins; +using Moonlight.Shared.Misc; + +namespace Moonlight.Client.Implementations; + +public class RemotePluginSource : IPluginSource +{ + private readonly FrontendConfiguration Configuration; + private readonly ILogger Logger; + private readonly HttpClient HttpClient; + + public RemotePluginSource( + FrontendConfiguration configuration, + ILogger logger, + HttpClient httpClient + ) + { + Configuration = configuration; + Logger = logger; + HttpClient = httpClient; + } + + public async Task Load(AssemblyLoadContext loadContext, List entrypoints) + { + entrypoints.AddRange(Configuration.Plugins.Entrypoints); + + foreach (var assembly in Configuration.Plugins.Assemblies) + { + try + { + var fileStream = await HttpClient.GetStreamAsync($"plugins/{assembly}"); + loadContext.LoadFromStream(fileStream); + } + catch (Exception e) + { + Logger.LogCritical("Unable to load plugin assembly '{assembly}': {e}", assembly, e); + } + } + } +} \ No newline at end of file diff --git a/Moonlight.Client/Moonlight.Client.csproj b/Moonlight.Client/Moonlight.Client.csproj index 3e5e257b..76868a2b 100644 --- a/Moonlight.Client/Moonlight.Client.csproj +++ b/Moonlight.Client/Moonlight.Client.csproj @@ -27,7 +27,7 @@ - +