From f7f3f51aa9dc33a2ed3642dacb534b58d769cdab Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 6 Dec 2021 19:11:23 -0600 Subject: consolidate options controllers --- .../Core/API/Controllers/ApplicationController.cs | 22 +++++++ .../API/Controllers/ConfigurationController.cs | 76 ---------------------- 2 files changed, 22 insertions(+), 76 deletions(-) delete mode 100644 src/slskd/Core/API/Controllers/ConfigurationController.cs (limited to 'src/slskd') diff --git a/src/slskd/Core/API/Controllers/ApplicationController.cs b/src/slskd/Core/API/Controllers/ApplicationController.cs index 82b1d6c5..d7beed6a 100644 --- a/src/slskd/Core/API/Controllers/ApplicationController.cs +++ b/src/slskd/Core/API/Controllers/ApplicationController.cs @@ -69,6 +69,13 @@ namespace slskd.Core.API public IActionResult Shutdown() { Lifetime.StopApplication(); + + Task.Run(async () => + { + await Task.Delay(500); + Environment.Exit(0); + }); + return NoContent(); } @@ -126,5 +133,20 @@ namespace slskd.Core.API return Ok(); } + + [HttpPut] + [Route("shares")] + [Authorize] + public IActionResult RescanSharesAsync() + { + if (ApplicationStateMonitor.CurrentValue.SharedFileCache.Filling) + { + return Conflict("A share scan is already in progress."); + } + + _ = Application.RescanSharesAsync(); + + return Ok(); + } } } diff --git a/src/slskd/Core/API/Controllers/ConfigurationController.cs b/src/slskd/Core/API/Controllers/ConfigurationController.cs deleted file mode 100644 index a7925174..00000000 --- a/src/slskd/Core/API/Controllers/ConfigurationController.cs +++ /dev/null @@ -1,76 +0,0 @@ -// -// Copyright (c) slskd Team. All rights reserved. -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU Affero General Public License as published -// by the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Affero General Public License for more details. -// -// You should have received a copy of the GNU Affero General Public License -// along with this program. If not, see https://www.gnu.org/licenses/. -// - -using Microsoft.Extensions.Options; - -namespace slskd.Core.API -{ - using System; - using Microsoft.AspNetCore.Authorization; - using Microsoft.AspNetCore.Mvc; - using Serilog; - using IOFile = System.IO.File; - - /// - /// Configuration. - /// - [Route("api/v{version:apiVersion}/[controller]")] - [ApiVersion("0")] - [ApiController] - [Produces("application/json")] - [Consumes("application/json")] - public class ConfigurationController : ControllerBase - { - public ConfigurationController( - IApplication application, - IOptionsSnapshot optionsShapshot, - IStateMonitor applicationStateMonitor) - { - Application = application; - OptionsSnapshot = optionsShapshot; - ApplicationStateMonitor = applicationStateMonitor; - } - - private IApplication Application { get; } - private IOptionsSnapshot OptionsSnapshot { get; } - private IStateMonitor ApplicationStateMonitor { get; } - private ILogger Logger { get; set; } = Log.ForContext(typeof(Program)); - - [HttpGet] - [Route("")] - [Authorize] - public IActionResult GetOptions() - { - return Ok(OptionsSnapshot.Value); - } - - [HttpPut] - [Route("shares")] - [Authorize] - public IActionResult RescanSharesAsync() - { - if (ApplicationStateMonitor.CurrentValue.SharedFileCache.Filling) - { - return Conflict("A share scan is already in progress."); - } - - _ = Application.RescanSharesAsync(); - - return Ok(); - } - } -} -- cgit v1.2.3 From 943016bc9fcdd47721bb3eb0e40b8bbf2359acbc Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 6 Dec 2021 19:42:12 -0600 Subject: add semantic version --- src/slskd/Program.cs | 16 ++++++++++------ src/slskd/State.cs | 3 ++- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'src/slskd') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index e4257037..79c012bb 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -92,7 +92,12 @@ namespace slskd /// /// Gets the full application version, including both assembly and informational versions. /// - public static readonly string Version = $"{AssemblyVersion} ({InformationalVersion})"; + public static readonly string FullVersion = $"{AssemblyVersion} ({InformationalVersion})"; + + /// + /// Gets the semantic application version. + /// + public static readonly string SemanticVersion = InformationalVersion.Split('-').First(); /// /// Gets a value indicating whether the current version is a Canary build. @@ -172,7 +177,7 @@ namespace slskd if (ShowVersion) { - Console.WriteLine(Version); + Console.WriteLine(FullVersion); return; } @@ -180,7 +185,7 @@ namespace slskd { if (!NoLogo) { - PrintLogo(Version); + PrintLogo(FullVersion); } if (ShowHelp) @@ -249,7 +254,6 @@ namespace slskd .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) .MinimumLevel.Override("System.Net.Http.HttpClient", OptionsAtStartup.Debug ? LogEventLevel.Warning : LogEventLevel.Fatal) .MinimumLevel.Override("slskd.Authentication.PassthroughAuthenticationHandler", LogEventLevel.Warning) - .Enrich.WithProperty("Version", Version) .Enrich.WithProperty("InstanceName", OptionsAtStartup.InstanceName) .Enrich.WithProperty("InvocationId", InvocationId) .Enrich.WithProperty("ProcessId", ProcessId) @@ -285,10 +289,10 @@ namespace slskd if (!OptionsAtStartup.NoLogo) { - PrintLogo(Version); + PrintLogo(FullVersion); } - logger.Information("Version: {Version}", Version); + logger.Information("Version: {Version}", FullVersion); if (IsCanary) { diff --git a/src/slskd/State.cs b/src/slskd/State.cs index bff2dc5b..afe9b0b1 100644 --- a/src/slskd/State.cs +++ b/src/slskd/State.cs @@ -38,7 +38,8 @@ namespace slskd public record VersionState { - public string Current { get; init; } = Program.InformationalVersion; + public string Full { get; init; } = Program.FullVersion; + public string Current { get; init; } = Program.SemanticVersion; public string Latest { get; init; } = null; public bool? IsUpdateAvailable { get; init; } = null; public bool IsCanary { get; init; } = Program.IsCanary; -- cgit v1.2.3 From 63be411f989425a3ecfbba83ad7e706841fdc224 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 6 Dec 2021 22:20:22 -0600 Subject: switch to FullVersion and SemanticVersion --- src/slskd/Program.cs | 40 +++++++++++++++++----------------------- 1 file changed, 17 insertions(+), 23 deletions(-) (limited to 'src/slskd') diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 79c012bb..5d81c5a5 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -74,50 +74,44 @@ namespace slskd public static readonly string DefaultAppDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData, Environment.SpecialFolderOption.DoNotVerify), AppName); /// - /// Gets the assembly version of the application. + /// Gets the unique Id of this application invocation. /// + public static readonly Guid InvocationId = Guid.NewGuid(); + + /// + /// Gets the Id of the current application process. + /// + public static readonly int ProcessId = Environment.ProcessId; + /// /// Inaccurate when running locally. /// - public static readonly Version AssemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.Equals(new Version(1, 0, 0, 0)) ? new Version(0, 0, 0, 0) : Assembly.GetExecutingAssembly().GetName().Version; + private static readonly Version AssemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.Equals(new Version(1, 0, 0, 0)) ? new Version(0, 0, 0, 0) : Assembly.GetExecutingAssembly().GetName().Version; - /// - /// Gets the informational version of the application, including the git sha at the latest commit. - /// /// /// Inaccurate when running locally. /// - public static readonly string InformationalVersion = Assembly.GetExecutingAssembly().GetCustomAttribute().InformationalVersion == "1.0.0" ? "0.0.0" : Assembly.GetExecutingAssembly().GetCustomAttribute().InformationalVersion; + private static readonly string InformationalVersion = Assembly.GetExecutingAssembly().GetCustomAttribute().InformationalVersion == "1.0.0" ? "0.0.0" : Assembly.GetExecutingAssembly().GetCustomAttribute().InformationalVersion; /// - /// Gets the full application version, including both assembly and informational versions. + /// Occurs when a new log event is emitted. /// - public static readonly string FullVersion = $"{AssemblyVersion} ({InformationalVersion})"; + public static event EventHandler LogEmitted; /// /// Gets the semantic application version. /// - public static readonly string SemanticVersion = InformationalVersion.Split('-').First(); - - /// - /// Gets a value indicating whether the current version is a Canary build. - /// - public static readonly bool IsCanary = AssemblyVersion.Revision == 65534; - - /// - /// Gets the unique Id of this application invocation. - /// - public static readonly Guid InvocationId = Guid.NewGuid(); + public static string SemanticVersion => InformationalVersion.Split('-').First(); /// - /// Gets the Id of the current application process. + /// Gets the full application version, including both assembly and informational versions. /// - public static readonly int ProcessId = Environment.ProcessId; + public static string FullVersion => $"{SemanticVersion} ({InformationalVersion})"; /// - /// Occurs when a new log event is emitted. + /// Gets a value indicating whether the current version is a Canary build. /// - public static event EventHandler LogEmitted; + public static bool IsCanary => AssemblyVersion.Revision == 65534; /// /// Gets the path where application data is saved. -- cgit v1.2.3 From 0c2ba2651bed499a6421087345dbd84823fcbc24 Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Mon, 6 Dec 2021 22:21:02 -0600 Subject: use semantic version --- src/slskd/Application.cs | 13 +++++++------ src/slskd/Core/API/Controllers/ApplicationController.cs | 2 +- src/slskd/Integrations/Pushbullet/PushbulletService.cs | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) (limited to 'src/slskd') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index d0cbe361..856b898d 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -141,10 +141,11 @@ namespace slskd /// The operation context. public async Task CheckVersionAsync() { - if (Program.InformationalVersion.EndsWith("65534")) + if (Program.IsCanary) { // todo: use the docker hub API to find the latest canary tag Logger.Information("Skipping version check for Canary build; check for updates manually."); + return; } Logger.Information("Checking GitHub Releases for latest version"); @@ -154,17 +155,17 @@ namespace slskd var latestVersion = await GitHub.GetLatestReleaseVersion( organization: Program.AppName, repository: Program.AppName, - userAgent: $"{Program.AppName} v{Program.InformationalVersion}"); + userAgent: $"{Program.AppName} v{Program.FullVersion}"); - if (latestVersion > Version.Parse(Program.InformationalVersion)) + if (latestVersion > Version.Parse(Program.SemanticVersion)) { State.SetValue(state => state with { Version = state.Version with { Latest = latestVersion.ToString(), IsUpdateAvailable = true } }); - Logger.Information("A new version is available! {CurrentVersion} -> {LatestVersion}", Program.InformationalVersion, latestVersion); + Logger.Information("A new version is available! {CurrentVersion} -> {LatestVersion}", Program.SemanticVersion, latestVersion); } else { - State.SetValue(state => state with { Version = state.Version with { Latest = Program.InformationalVersion, IsUpdateAvailable = false } }); - Logger.Information("Version {CurrentVersion} is up to date.", Program.InformationalVersion); + State.SetValue(state => state with { Version = state.Version with { Latest = Program.SemanticVersion, IsUpdateAvailable = false } }); + Logger.Information("Version {CurrentVersion} is up to date.", Program.SemanticVersion); } } catch (Exception ex) diff --git a/src/slskd/Core/API/Controllers/ApplicationController.cs b/src/slskd/Core/API/Controllers/ApplicationController.cs index d7beed6a..501f8a9c 100644 --- a/src/slskd/Core/API/Controllers/ApplicationController.cs +++ b/src/slskd/Core/API/Controllers/ApplicationController.cs @@ -101,7 +101,7 @@ namespace slskd.Core.API [Authorize] public IActionResult GetVersion() { - return Ok(Program.InformationalVersion); + return Ok(Program.SemanticVersion); } /// diff --git a/src/slskd/Integrations/Pushbullet/PushbulletService.cs b/src/slskd/Integrations/Pushbullet/PushbulletService.cs index 1ec092eb..5328f4d6 100644 --- a/src/slskd/Integrations/Pushbullet/PushbulletService.cs +++ b/src/slskd/Integrations/Pushbullet/PushbulletService.cs @@ -140,7 +140,7 @@ namespace slskd.Integrations.Pushbullet using var http = HttpClientFactory.CreateClient(); - http.DefaultRequestHeaders.UserAgent.TryParseAdd($"{Program.AppName} v{Program.Version}"); + http.DefaultRequestHeaders.UserAgent.TryParseAdd($"{Program.AppName} v{Program.FullVersion}"); Log.LogDebug("Sending Pushbullet notification {Title} {Body}", title, body); -- cgit v1.2.3 From f6818c2e2f8511cdd59e6254ce1936d2d82727df Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Tue, 7 Dec 2021 09:18:07 -0600 Subject: add flag and behavior for development builds --- src/slskd/Application.cs | 6 ++++++ src/slskd/Program.cs | 15 +++++++++++++++ src/slskd/State.cs | 1 + 3 files changed, 22 insertions(+) (limited to 'src/slskd') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 856b898d..021a6c40 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -141,6 +141,12 @@ namespace slskd /// The operation context. public async Task CheckVersionAsync() { + if (Program.IsDevelopment) + { + Logger.Information("Skipping version check for Development build"); + return; + } + if (Program.IsCanary) { // todo: use the docker hub API to find the latest canary tag diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs index 5d81c5a5..b109c76b 100644 --- a/src/slskd/Program.cs +++ b/src/slskd/Program.cs @@ -113,6 +113,11 @@ namespace slskd /// public static bool IsCanary => AssemblyVersion.Revision == 65534; + /// + /// Gets a value indicating whether the current version is a Development build. + /// + public static bool IsDevelopment => new Version(0, 0, 0, 0) == AssemblyVersion; + /// /// Gets the path where application data is saved. /// @@ -288,6 +293,11 @@ namespace slskd logger.Information("Version: {Version}", FullVersion); + if (IsDevelopment) + { + logger.Warning("This is a Development build; YMMV"); + } + if (IsCanary) { logger.Warning("This is a canary build"); @@ -556,6 +566,11 @@ namespace slskd │ │ │{centeredVersion}│"; + if (IsDevelopment) + { + banner += "\n│■■■■■■■■■■■■■■■■■■■■► DEVELOPMENT ◄■■■■■■■■■■■■■■■■■■■■■│"; + } + if (IsCanary) { banner += "\n│■■■■■■■■■■■■■■■■■■■■■■■► CANARY ◄■■■■■■■■■■■■■■■■■■■■■■■│"; diff --git a/src/slskd/State.cs b/src/slskd/State.cs index afe9b0b1..d07c603a 100644 --- a/src/slskd/State.cs +++ b/src/slskd/State.cs @@ -43,6 +43,7 @@ namespace slskd public string Latest { get; init; } = null; public bool? IsUpdateAvailable { get; init; } = null; public bool IsCanary { get; init; } = Program.IsCanary; + public bool IsDevelopment { get; init; } = Program.IsDevelopment; } public record ServerState -- cgit v1.2.3