diff --git a/Moonlight/App/Http/Controllers/Api/Moonlight/ResourcesController.cs b/Moonlight/App/Http/Controllers/Api/Moonlight/ResourcesController.cs index 6632386c..d701a2c2 100644 --- a/Moonlight/App/Http/Controllers/Api/Moonlight/ResourcesController.cs +++ b/Moonlight/App/Http/Controllers/Api/Moonlight/ResourcesController.cs @@ -16,14 +16,12 @@ public class ResourcesController : Controller { private readonly SecurityLogService SecurityLogService; private readonly BucketService BucketService; - private readonly BundleService BundleService; public ResourcesController(SecurityLogService securityLogService, - BucketService bucketService, BundleService bundleService) + BucketService bucketService) { SecurityLogService = securityLogService; BucketService = bucketService; - BundleService = bundleService; } [HttpGet("images/{name}")] @@ -77,34 +75,4 @@ public class ResourcesController : Controller return Problem(); } } - - [HttpGet("bundle/js")] - public Task GetJs() - { - if (BundleService.BundledFinished) - { - return Task.FromResult( - File(Encoding.ASCII.GetBytes(BundleService.BundledJs), "text/javascript") - ); - } - - return Task.FromResult( - NotFound() - ); - } - - [HttpGet("bundle/css")] - public Task GetCss() - { - if (BundleService.BundledFinished) - { - return Task.FromResult( - File(Encoding.ASCII.GetBytes(BundleService.BundledCss), "text/css") - ); - } - - return Task.FromResult( - NotFound() - ); - } } \ No newline at end of file diff --git a/Moonlight/App/Services/Sessions/BundleService.cs b/Moonlight/App/Services/Sessions/BundleService.cs deleted file mode 100644 index 2b0cfbfc..00000000 --- a/Moonlight/App/Services/Sessions/BundleService.cs +++ /dev/null @@ -1,129 +0,0 @@ -using Logging.Net; - -namespace Moonlight.App.Services.Sessions; - -public class BundleService -{ - public BundleService(ConfigService configService) - { - var url = configService - .GetSection("Moonlight") - .GetValue("AppUrl"); - - #region JS - - JsFiles = new(); - - JsFiles.AddRange(new[] - { - url + "/_framework/blazor.server.js", - url + "/assets/plugins/global/plugins.bundle.js", - url + "/_content/XtermBlazor/XtermBlazor.min.js", - url + "/_content/BlazorTable/BlazorTable.min.js", - url + "/_content/CurrieTechnologies.Razor.SweetAlert2/sweetAlert2.min.js", - url + "/_content/Blazor.ContextMenu/blazorContextMenu.min.js", - "https://www.google.com/recaptcha/api.js", - "https://cdn.jsdelivr.net/npm/xterm-addon-fit@0.5.0/lib/xterm-addon-fit.min.js", - "https://cdn.jsdelivr.net/npm/xterm-addon-search@0.8.2/lib/xterm-addon-search.min.js", - "https://cdn.jsdelivr.net/npm/xterm-addon-web-links@0.5.0/lib/xterm-addon-web-links.min.js", - url + "/_content/BlazorMonaco/lib/monaco-editor/min/vs/loader.js", - "require.config({ paths: { 'vs': '/_content/BlazorMonaco/lib/monaco-editor/min/vs' } });", - url + "/_content/BlazorMonaco/lib/monaco-editor/min/vs/editor/editor.main.js", - url + "/_content/BlazorMonaco/jsInterop.js", - url + "/assets/js/scripts.bundle.js", - url + "/assets/js/moonlight.js", - "moonlight.loading.registerXterm();", - url + "/_content/Blazor-ApexCharts/js/apex-charts.min.js", - url + "/_content/Blazor-ApexCharts/js/blazor-apex-charts.js" - }); - - #endregion - - #region CSS - - CssFiles = new(); - - CssFiles.AddRange(new[] - { - "https://fonts.googleapis.com/css?family=Poppins:300,400,500,600,700", - url + "/assets/css/style.bundle.css", - url + "/assets/css/flashbang.css", - url + "/assets/css/snow.css", - url + "/assets/css/utils.css", - url + "/assets/css/blazor.css", - url + "/_content/XtermBlazor/XtermBlazor.css", - url + "/_content/BlazorMonaco/lib/monaco-editor/min/vs/editor/editor.main.css", - url + "/_content/Blazor.ContextMenu/blazorContextMenu.min.css", - url + "/assets/plugins/global/plugins.bundle.css" - }); - - #endregion - - CacheId = Guid.NewGuid().ToString(); - - Task.Run(Bundle); - } - - // Javascript - public string BundledJs { get; private set; } - public readonly List JsFiles; - - // CSS - public string BundledCss { get; private set; } - public readonly List CssFiles; - - // States - public string CacheId { get; private set; } - public bool BundledFinished { get; set; } = false; - private bool IsBundling { get; set; } = false; - - private async Task Bundle() - { - if (!IsBundling) - IsBundling = true; - - Logger.Info("Bundling js and css files"); - - BundledJs = ""; - BundledCss = ""; - - BundledJs = await BundleFiles( - JsFiles - ); - - BundledCss = await BundleFiles( - CssFiles - ); - - Logger.Info("Successfully bundled"); - BundledFinished = true; - } - - private async Task BundleFiles(IEnumerable items) - { - var bundled = ""; - - using HttpClient client = new HttpClient(); - foreach (string item in items) - { - // Item is a url, fetch it - if (item.StartsWith("http")) - { - try - { - var jsCode = await client.GetStringAsync(item); - bundled += jsCode + "\n"; - } - catch (Exception e) - { - Logger.Warn($"Error fetching '{item}' while bundling"); - Logger.Warn(e); - } - } - else // If not, it is probably a manual addition, so add it - bundled += item + "\n"; - } - - return bundled; - } -} \ No newline at end of file diff --git a/Moonlight/Pages/_Layout.cshtml b/Moonlight/Pages/_Layout.cshtml index 975533a9..73ba593c 100644 --- a/Moonlight/Pages/_Layout.cshtml +++ b/Moonlight/Pages/_Layout.cshtml @@ -7,7 +7,6 @@ @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers @inject ConfigService ConfigService -@inject BundleService BundleService @inject LoadingMessageRepository LoadingMessageRepository @{ @@ -38,29 +37,20 @@ - @*This import is not in the bundle because the files it references are linked relative to the current lath*@ + + + + + + - - @if (BundleService.BundledFinished) - { - - } - else - { - foreach (var cssFile in BundleService.CssFiles) - { - if (cssFile.StartsWith("http")) - { - - } - else - { - - } - } - } + + + + + + + @@ -106,24 +96,33 @@ -@if (BundleService.BundledFinished) -{ - -} -else -{ - foreach (var jsFile in BundleService.JsFiles) - { - if (jsFile.StartsWith("http")) - { - - } - else - { - @Html.Raw("") - } - } -} + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Moonlight/Program.cs b/Moonlight/Program.cs index 70466a08..a3795997 100644 --- a/Moonlight/Program.cs +++ b/Moonlight/Program.cs @@ -128,7 +128,6 @@ namespace Moonlight builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddSingleton(); - builder.Services.AddSingleton(); builder.Services.AddScoped(); builder.Services.AddScoped();