From 9a262d139671d13c7ef84fc895ccd94840ecdc8f Mon Sep 17 00:00:00 2001 From: Marcel Baumgartner Date: Sun, 11 Jun 2023 20:59:20 +0200 Subject: [PATCH] Add new version and changelog system --- .gitignore | 1 + .../App/Services/Background/UptimeService.cs | 11 - Moonlight/App/Services/MoonlightService.cs | 101 +++++++ Moonlight/Dockerfile | 1 + Moonlight/Moonlight.csproj | 2 + Moonlight/Program.cs | 10 +- Moonlight/Properties/launchSettings.json | 24 +- Moonlight/Shared/Views/Admin/Sys/Index.razor | 170 +++++------ Moonlight/Shared/Views/Changelog.razor | 267 +----------------- 9 files changed, 210 insertions(+), 377 deletions(-) delete mode 100644 Moonlight/App/Services/Background/UptimeService.cs create mode 100644 Moonlight/App/Services/MoonlightService.cs diff --git a/.gitignore b/.gitignore index 9d00e10d..7afc561b 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,4 @@ Desktop.ini storage/ Moonlight/publish.ps1 +Moonlight/version diff --git a/Moonlight/App/Services/Background/UptimeService.cs b/Moonlight/App/Services/Background/UptimeService.cs deleted file mode 100644 index c55ceaf7..00000000 --- a/Moonlight/App/Services/Background/UptimeService.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Moonlight.App.Services.Background; - -public class UptimeService -{ - public DateTime StartTimestamp { get; private set; } - - public UptimeService() - { - StartTimestamp = DateTime.UtcNow; - } -} \ No newline at end of file diff --git a/Moonlight/App/Services/MoonlightService.cs b/Moonlight/App/Services/MoonlightService.cs new file mode 100644 index 00000000..9e571519 --- /dev/null +++ b/Moonlight/App/Services/MoonlightService.cs @@ -0,0 +1,101 @@ +using Logging.Net; +using Octokit; +using Repository = LibGit2Sharp.Repository; + +namespace Moonlight.App.Services; + +public class MoonlightService +{ + private readonly ConfigService ConfigService; + public readonly DateTime StartTimestamp; + public readonly string AppVersion; + public readonly List ChangeLog = new(); + + public MoonlightService(ConfigService configService) + { + ConfigService = configService; + StartTimestamp = DateTime.UtcNow; + + if (File.Exists("version") && !ConfigService.DebugMode) + AppVersion = File.ReadAllText("version"); + else if (ConfigService.DebugMode) + { + string repositoryPath = Path.GetFullPath(".."); + using var repo = new Repository(repositoryPath); + var commit = repo.Head.Tip; + AppVersion = commit.Sha; + } + else + AppVersion = "unknown"; + + Task.Run(FetchChangeLog); + } + + private async Task FetchChangeLog() + { + if(AppVersion == "unknown") + return; + + if (ConfigService.DebugMode) + { + ChangeLog.Add(new[] + { + "Disabled", + "Fetching changelog from github is disabled in debug mode" + }); + + return; + } + + try + { + var client = new GitHubClient(new ProductHeaderValue("Moonlight")); + + var pullRequests = await client.PullRequest.GetAllForRepository("Moonlight-Panel", "Moonlight", new PullRequestRequest + { + State = ItemStateFilter.Closed, + SortDirection = SortDirection.Ascending, + SortProperty = PullRequestSort.Created + }); + + var groupedPullRequests = new Dictionary>(); + + foreach (var pullRequest in pullRequests) + { + if (pullRequest.MergedAt != null) + { + var date = pullRequest.MergedAt.Value.Date; + + if (!groupedPullRequests.ContainsKey(date)) + { + groupedPullRequests[date] = new List(); + } + + groupedPullRequests[date].Add(pullRequest.Title); + } + } + + int i = 1; + foreach (var group in groupedPullRequests) + { + var pullRequestsList = new List(); + var date = group.Key.ToString("dd.MM.yyyy"); + + pullRequestsList.Add($"Patch {i}, {date}"); + + foreach (var pullRequest in group.Value) + { + pullRequestsList.Add(pullRequest); + } + + ChangeLog.Add(pullRequestsList.ToArray()); + i++; + } + } + catch (Exception e) + { + Logger.Warn("Error fetching changelog"); + Logger.Warn(e); + } + } +} \ No newline at end of file diff --git a/Moonlight/Dockerfile b/Moonlight/Dockerfile index caf1ab0b..ef27e867 100644 --- a/Moonlight/Dockerfile +++ b/Moonlight/Dockerfile @@ -22,5 +22,6 @@ COPY --from=publish /app/publish . RUN mkdir -p /app/storage RUN touch /app/storage/donttriggeranyerrors RUN rm -r /app/storage/* +COPY version /app/version COPY "Moonlight/defaultstorage" "/app/defaultstorage" ENTRYPOINT ["dotnet", "Moonlight.dll"] \ No newline at end of file diff --git a/Moonlight/Moonlight.csproj b/Moonlight/Moonlight.csproj index a3ea7a4f..3e10c132 100644 --- a/Moonlight/Moonlight.csproj +++ b/Moonlight/Moonlight.csproj @@ -24,6 +24,7 @@ + @@ -40,6 +41,7 @@ + diff --git a/Moonlight/Program.cs b/Moonlight/Program.cs index e5fa7179..5fd66bfb 100644 --- a/Moonlight/Program.cs +++ b/Moonlight/Program.cs @@ -34,9 +34,6 @@ namespace Moonlight { public class Program { - // App version. Change for release - public static readonly string AppVersion = $"InDev {Formatter.FormatDateOnly(DateTime.Now.Date)}"; - public static async Task Main(string[] args) { Logger.UsedLogger = new CacheLogger(); @@ -168,7 +165,9 @@ namespace Moonlight builder.Services.AddSingleton(); builder.Services.AddSingleton(); builder.Services.AddSingleton(); - builder.Services.AddSingleton(); + + // Other + builder.Services.AddSingleton(); // Third party services builder.Services.AddBlazorTable(); @@ -204,7 +203,8 @@ namespace Moonlight _ = app.Services.GetRequiredService(); _ = app.Services.GetRequiredService(); _ = app.Services.GetRequiredService(); - _ = app.Services.GetRequiredService(); + + _ = app.Services.GetRequiredService(); // Discord bot service //var discordBotService = app.Services.GetRequiredService(); diff --git a/Moonlight/Properties/launchSettings.json b/Moonlight/Properties/launchSettings.json index 2d733585..39b73b38 100644 --- a/Moonlight/Properties/launchSettings.json +++ b/Moonlight/Properties/launchSettings.json @@ -1,18 +1,11 @@ { - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:26548", - "sslPort": 44339 - } - }, "profiles": { "Moonlight": { "commandName": "Project", "launchBrowser": true, "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" + "ASPNETCORE_ENVIRONMENT": "Development", + "ML_DEBUG": "true" }, "applicationUrl": "http://moonlight.testy:5118;https://localhost:7118;http://localhost:5118", "dotnetRunMessages": true @@ -22,7 +15,8 @@ "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", - "ML_SQL_DEBUG": "true" + "ML_SQL_DEBUG": "true", + "ML_DEBUG": "true" }, "applicationUrl": "http://moonlight.testy:5118;https://localhost:7118;http://localhost:5118", "dotnetRunMessages": true @@ -32,17 +26,11 @@ "launchBrowser": false, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development", - "ML_SQL_DEBUG": "true" + "ML_SQL_DEBUG": "true", + "ML_DEBUG": "true" }, "applicationUrl": "http://moonlight.testy:5118;https://localhost:7118;http://localhost:5118", "dotnetRunMessages": true - }, - "Docker": { - "commandName": "Docker", - "launchBrowser": false, - "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}", - "publishAllPorts": true, - "useSSL": true } } } \ No newline at end of file diff --git a/Moonlight/Shared/Views/Admin/Sys/Index.razor b/Moonlight/Shared/Views/Admin/Sys/Index.razor index 6f54a54e..20af8f1f 100644 --- a/Moonlight/Shared/Views/Admin/Sys/Index.razor +++ b/Moonlight/Shared/Views/Admin/Sys/Index.razor @@ -2,92 +2,102 @@ @using Moonlight.Shared.Components.Navigations @using Moonlight.App.Helpers -@using Moonlight.App.Services.Background +@using Moonlight.App.Services @inject HostSystemHelper HostSystemHelper -@inject UptimeService UptimeService +@inject MoonlightService MoonlightService -
-
-
-
- - Version - + +
+
+
+
+ + Version + +
+
+ + You are running moonlight version + @(MoonlightService.AppVersion) + +
+
-
- - You are running moonlight version - @(Program.AppVersion) - +
+
+
+ + Operating system + +
+
+ + Moonlight is running on + @(HostSystemHelper.GetOsName()) + +
+
+
+
+
+
+ + Memory usage + +
+
+ + Moonlight is using + @(HostSystemHelper.GetMemoryUsage()) MB + of memory + +
+
+
+
+
+
+ + Cpu usage + +
+
+ + Moonlight is using + @(HostSystemHelper.GetCpuUsage()) % + +
+
+
+
+
+
+ + Uptime + +
+
+ + Moonlight is since + + @(Formatter.FormatUptime(DateTime.UtcNow - MoonlightService.StartTimestamp)) + + +
+
-
-
-
-
- - Operating system - -
-
- - Moonlight is running on - @(HostSystemHelper.GetOsName()) - -
-
-
-
-
-
- - Memory usage - -
-
- - Moonlight is using - @(HostSystemHelper.GetMemoryUsage()) MB - of memory - -
-
-
-
-
-
- - Cpu usage - -
-
- - Moonlight is using - @(HostSystemHelper.GetCpuUsage()) % - -
-
-
-
-
-
- - Uptime - -
-
- - Moonlight is since - - @(Formatter.FormatUptime(DateTime.UtcNow - UptimeService.StartTimestamp)) - - -
-
-
-
- \ No newline at end of file + + + +@code +{ + private Task Load(LazyLoader arg) + { + return Task.CompletedTask; + } +} diff --git a/Moonlight/Shared/Views/Changelog.razor b/Moonlight/Shared/Views/Changelog.razor index 704ba144..a9cf102c 100644 --- a/Moonlight/Shared/Views/Changelog.razor +++ b/Moonlight/Shared/Views/Changelog.razor @@ -1,275 +1,16 @@ @page "/changelog" +@using Moonlight.App.Services + +@inject MoonlightService MoonlightService @{ - List changelog = new List - { - new[] - { - "Patch 1, 13.03.2023", - "Service manager" - }, - new[] - { - "Patch 2, 14.03.2023", - "Added new image manager. CRUD implemeted" - }, - new[] - { - "Patch 3, 20.03.2023", - "Ddos detection", - "Implemented server manager" - }, - new[] - { - "Patch 4, 21.03.2023", - "Added user edit form. Fixed edit link" - }, - new[] - { - "Patch 5, 24.03.2023", - "Update Discord Bot Branche", - "Removed discord id and discriminator. Fixed oauth2.", - "Updated discord bot branch", - "Updated smart form branch", - "Added smart form", - "Updating PleskIntegration branch", - "Revert \"Updating PleskIntegration branch\"" - }, - new[] - { - "Patch 6, 27.03.2023", - "Update Index.razor", - "User settings" - }, - new[] - { - "Patch 7, 28.03.2023", - "Added form proccessing screen (not finished). Some ui changes. User m." - }, - new[] - { - "Patch 8, 02.04.2023", - "Server manage enhancements", - "Cleanup system", - "Update WingsServerConverter.cs", - "Added quick create dropdown", - "fixed login form", - "Login form fix" - }, - new[] - { - "Patch 9, 03.04.2023", - "Fixed cleanup", - "Added server reset setting", - "Totp", - "Update from upstream because of database models", - "Audit log", - "Audit log", - "Force password change", - "Support chat redesign", - "Subscriptions", - "Added server rename setting" - }, - new[] - { - "Patch 10, 04.04.2023", - "Added server delete. Tweaked setting names", - "Added server node status screen check thingy", - "Update CacheLogger.cs", - "Update to upstream branch", - "Update View.razor", - "Update to upstream branch", - "Removed legacy aaPanel stuff", - "Update DesignFixes", - "Design fixes", - "Create Changelog.razor" - }, - new[] - { - "Patch 11, 05.04.2023", - "Ftp file manager", - "Update to upstream branch", - "Added ActivityStatus" - }, - new[] - { - "Patch 12, 06.04.2023", - "Domain overview", - "Plesk integration", - "Add websites to statistics branch", - "Removed legacy database ui", - "Replaced legacy dependency resolve with server service function for w.", - "masu is too stupid to use ulong", - "Statistic system", - "host file access + use in admin resource manager" - }, - new[] - { - "Patch 13, 10.04.2023", - "Removed old typeahead. Added own solution. Lang file, notes", - "Implemented website order" - }, - new[] - { - "Patch 14, 11.04.2023", - "Implemented domain order. Fixed some bugs" - }, - new[] - { - "Patch 15, 12.04.2023", - "Implemented new soft error boundary crash handler", - "Added ip locate. Fixed oauth2 mail send. Fixed mail send when generat.", - "Implemented multi allocation", - "register", - "Fixed server lists", - "News page", - "Improved news system" - }, - new[] - { - "Patch 16, 13.04.2023", - "domain view redesigned | fixed some masu at midnight", - "Persistent storage", - "Removed old file manager stuff", - "fixed design of delete button", - "redesigned shared domains screen | split in view/add" - }, - new[] - { - "Patch 17, 14.04.2023", - "Removed legacy image tags", - "Fixed server deletion and creation allocation bugs" - }, - new[] - { - "Patch 18, 15.04.2023", - "Update DiscordBot branch", - "Fix backup delete", - "Implemented default subscription", - "Implemented random loading message", - "Recode frontend js" - }, - new[] - { - "Patch 19, 16.04.2023", - "Optimized allocation search. Added sql command log interception", - "Fixed my stupid mistakes", - "Implemented file view loading animation" - }, - new[] - { - "Patch 20, 19.04.2023", - "Cloud panel interation" - }, - new[] - { - "Patch 21, 20.04.2023", - "Removed legacy website", - "Added user change status try catch, implement logout. password change", - "Added admin check to sftp login system", - "Implemented new event system", - "Rewritten support chat backend. Added discord notifications" - }, - new[] - { - "Patch 22, 21.04.2023", - "Removed old support system", - "Deleted old message system. Replaced it with new event system", - "Update ServerNavigation.razor", - "Switched from internal smtp client to MailKit. Added ssl config" - }, - new[] - { - "Patch 23, 23.04.2023", - "Added missing refresh call", - "Added better reconnect screens", - "Removed useless logging. Switched to cache mode for support chat", - "Fixed statistics system" - }, - new[] - { - "Patch 24, 24.04.2023", - "Add checking user status to login sequence where login form is currently", - "Added config reload button" - }, - new[] - { - "Patch 25, 25.04.2023", - "Update Create.razor", - "Added server count for image overview", - "Implemented owner change option in admin ui" - }, - new[] - { - "Patch 26, 26.04.2023", - "Image import export", - "Fixed import and export", - "Prevent message duplication with sender check", - "Implemented forge version switcher" - }, - new[] - { - "Patch 27, 28.04.2023", - "Improved user details profile page", - "Implemented fabric version setting" - }, - new[] - { - "Patch 28, 29.04.2023", - "update my DiscordBot branch", - "Revert \"update my DiscordBot branch\"", - "Discord bot", - "Update to upstream branch" - }, - new[] - { - "Patch 29, 02.05.2023", - "Update Index.razor", - "Added multi line feature and file upload in the support chat" - }, - new[] - { - "Patch 30, 04.05.2023", - "Implemented new rating system" - }, - new[] - { - "Patch 31, 05.05.2023", - "Code cleanup", - "added version and main jar setting", - "fixed server settings design", - "dotnet runtime settings" - }, - new[] - { - "Patch 32, 06.05.2023", - "file create" - }, - new[] - { - "Patch 33, 17.05.2023", - "Added node selector for server create screen", - "Added website directory limit for website file manager", - "Added new screenhot service", - "Added node and image view to manager. Made the data handling smoother" - }, - new[] - { - "Patch 34, 19.05.2023", - "Added recaptcha. Added recaptcha to register page", - "Implemented ip ban" - } - }; - - changelog.Reverse(); - int i = 0; }
- @foreach (var prt in changelog) + @foreach (var prt in MoonlightService.ChangeLog.ToArray().Reverse()) { i++;