aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSanskar Pandey <sanskarpandey0@gmail.com>2022-10-10 15:00:03 +0530
committerGitHub <noreply@github.com>2022-10-10 15:00:03 +0530
commit9c84200a25ee590e30b5e10d5b9a648ae105730e (patch)
treeaec47cc2bf04ae5ba47be6f6071aaa7c4eef1e6f /src
parent56bfdfc22b7a2cb9f7270f83498548f93ab4a04e (diff)
parent7c00e16196cb4e21467e6f94f9098de9e48a1219 (diff)
downloadslskd-9c84200a25ee590e30b5e10d5b9a648ae105730e.tar.gz
Merge branch 'master' into contentPath-relative-path
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Common/Authentication/AuthPolicy.cs28
-rw-r--r--src/slskd/Common/Exceptions/ShareInitializationException.cs72
-rw-r--r--src/slskd/Core/API/Controllers/ApplicationController.cs14
-rw-r--r--src/slskd/Core/API/Controllers/LogsController.cs2
-rw-r--r--src/slskd/Core/API/Controllers/MetricsController.cs2
-rw-r--r--src/slskd/Core/API/Controllers/OptionsController.cs14
-rw-r--r--src/slskd/Core/API/Controllers/ServerController.cs6
-rw-r--r--src/slskd/Core/API/Controllers/SessionController.cs2
-rw-r--r--src/slskd/Core/API/Hubs/ApplicationHub.cs2
-rw-r--r--src/slskd/Core/API/Hubs/LogsHub.cs2
-rw-r--r--src/slskd/Messaging/API/Controllers/ConversationsController.cs12
-rw-r--r--src/slskd/Messaging/API/Controllers/PublicChatController.cs4
-rw-r--r--src/slskd/Messaging/API/Controllers/RoomsController.cs20
-rw-r--r--src/slskd/Program.cs37
-rw-r--r--src/slskd/Search/API/Controllers/SearchesController.cs12
-rw-r--r--src/slskd/Search/API/Hubs/SearchHub.cs2
-rw-r--r--src/slskd/Shares/API/Controllers/SharesController.cs12
-rw-r--r--src/slskd/Shares/ShareRepository.cs61
-rw-r--r--src/slskd/Shares/ShareScanner.cs16
-rw-r--r--src/slskd/Shares/ShareService.cs59
-rw-r--r--src/slskd/Transfers/API/Controllers/TransfersController.cs20
-rw-r--r--src/slskd/Transfers/Downloads/DownloadService.cs12
-rw-r--r--src/slskd/Users/API/Controllers/UsersController.cs10
23 files changed, 322 insertions, 99 deletions
diff --git a/src/slskd/Common/Authentication/AuthPolicy.cs b/src/slskd/Common/Authentication/AuthPolicy.cs
new file mode 100644
index 00000000..e355b2e6
--- /dev/null
+++ b/src/slskd/Common/Authentication/AuthPolicy.cs
@@ -0,0 +1,28 @@
+// <copyright file="AuthPolicy.cs" company="slskd Team">
+// 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/.
+// </copyright>
+
+namespace slskd
+{
+ /// <summary>
+ /// Authentication policies.
+ /// </summary>
+ public static class AuthPolicy
+ {
+ public const string JwtOnly = "Jwt";
+ public const string Any = "Any";
+ }
+}
diff --git a/src/slskd/Common/Exceptions/ShareInitializationException.cs b/src/slskd/Common/Exceptions/ShareInitializationException.cs
new file mode 100644
index 00000000..31e45b91
--- /dev/null
+++ b/src/slskd/Common/Exceptions/ShareInitializationException.cs
@@ -0,0 +1,72 @@
+// <copyright file="ShareInitializationException.cs" company="slskd Team">
+// 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/.
+// </copyright>
+
+namespace slskd
+{
+ using System;
+ using System.Diagnostics.CodeAnalysis;
+ using System.Runtime.Serialization;
+
+ /// <summary>
+ /// Represents an error that occurs when multiple share scans are attempted concurrently.
+ /// </summary>
+ [ExcludeFromCodeCoverage]
+ [Serializable]
+ public class ShareInitializationException : SlskdException
+ {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ShareInitializationException"/> class.
+ /// </summary>
+ public ShareInitializationException()
+ : base()
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ShareInitializationException"/> class with a specified error message.
+ /// </summary>
+ /// <param name="message">The message that describes the error.</param>
+ public ShareInitializationException(string message)
+ : base(message)
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ShareInitializationException"/> class with a specified error message and a
+ /// reference to the inner exception that is the cause of this exception.
+ /// </summary>
+ /// <param name="message">The message that describes the error.</param>
+ /// <param name="innerException">
+ /// The exception that is the cause of the current exception, or a null reference (Nothing in Visual Basic) if no
+ /// inner exception is specified.
+ /// </param>
+ public ShareInitializationException(string message, Exception innerException)
+ : base(message, innerException)
+ {
+ }
+
+ /// <summary>
+ /// Initializes a new instance of the <see cref="ShareInitializationException"/> class with serialized data.
+ /// </summary>
+ /// <param name="info">The SerializationInfo that holds the serialized object data about the exception being thrown.</param>
+ /// <param name="context">The StreamingContext that contains contextual information about the source or destination.</param>
+ protected ShareInitializationException(SerializationInfo info, StreamingContext context)
+ : base(info, context)
+ {
+ }
+ }
+} \ No newline at end of file
diff --git a/src/slskd/Core/API/Controllers/ApplicationController.cs b/src/slskd/Core/API/Controllers/ApplicationController.cs
index 7fb914e9..c09b5513 100644
--- a/src/slskd/Core/API/Controllers/ApplicationController.cs
+++ b/src/slskd/Core/API/Controllers/ApplicationController.cs
@@ -58,7 +58,7 @@ namespace slskd.Core.API
/// </summary>
/// <returns></returns>
[HttpGet]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
public IActionResult State()
{
return Ok(ApplicationStateMonitor.CurrentValue);
@@ -69,7 +69,7 @@ namespace slskd.Core.API
/// </summary>
/// <returns></returns>
[HttpDelete]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.JwtOnly)]
public IActionResult Shutdown()
{
Program.MasterCancellationTokenSource.Cancel();
@@ -89,7 +89,7 @@ namespace slskd.Core.API
/// </summary>
/// <returns></returns>
[HttpPut]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.JwtOnly)]
public IActionResult Restart()
{
Program.MasterCancellationTokenSource.Cancel();
@@ -104,7 +104,7 @@ namespace slskd.Core.API
/// </summary>
/// <returns></returns>
[HttpGet("version")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
public IActionResult GetVersion()
{
return Ok(Program.SemanticVersion);
@@ -115,7 +115,7 @@ namespace slskd.Core.API
/// </summary>
/// <returns></returns>
[HttpGet("version/latest")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
public async Task<IActionResult> CheckVersion([FromQuery] bool forceCheck = false)
{
if (forceCheck)
@@ -131,7 +131,7 @@ namespace slskd.Core.API
/// </summary>
/// <returns></returns>
[HttpPost("gc")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
public IActionResult CollectGarbage()
{
Application.CollectGarbage();
@@ -140,7 +140,7 @@ namespace slskd.Core.API
}
[HttpGet("dump")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
public async Task<IActionResult> DumpMemory()
{
using var dumper = new Dumper();
diff --git a/src/slskd/Core/API/Controllers/LogsController.cs b/src/slskd/Core/API/Controllers/LogsController.cs
index 57366867..2beaf279 100644
--- a/src/slskd/Core/API/Controllers/LogsController.cs
+++ b/src/slskd/Core/API/Controllers/LogsController.cs
@@ -35,7 +35,7 @@ namespace slskd.Core.API
/// </summary>
/// <returns></returns>
[HttpGet]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
public IActionResult Logs()
{
return Ok(Program.LogBuffer);
diff --git a/src/slskd/Core/API/Controllers/MetricsController.cs b/src/slskd/Core/API/Controllers/MetricsController.cs
index da2707c1..886f1f05 100644
--- a/src/slskd/Core/API/Controllers/MetricsController.cs
+++ b/src/slskd/Core/API/Controllers/MetricsController.cs
@@ -36,7 +36,7 @@ namespace slskd.Core.API
/// </summary>
/// <returns></returns>
[HttpGet]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
public async Task<IActionResult> Get()
{
var response = await Metrics.BuildAsync();
diff --git a/src/slskd/Core/API/Controllers/OptionsController.cs b/src/slskd/Core/API/Controllers/OptionsController.cs
index b0856ed3..f621b37a 100644
--- a/src/slskd/Core/API/Controllers/OptionsController.cs
+++ b/src/slskd/Core/API/Controllers/OptionsController.cs
@@ -56,7 +56,7 @@ namespace slskd.Core.API
/// </summary>
/// <returns></returns>
[HttpGet]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(typeof(Options), 200)]
public IActionResult Current()
{
@@ -69,7 +69,7 @@ namespace slskd.Core.API
/// <returns></returns>
[HttpGet]
[Route("startup")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(typeof(Options), 200)]
public IActionResult Startup()
{
@@ -82,7 +82,7 @@ namespace slskd.Core.API
/// <returns></returns>
[HttpGet]
[Route("debug")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.JwtOnly)]
[ProducesResponseType(typeof(string), 200)]
public IActionResult Debug()
{
@@ -95,7 +95,7 @@ namespace slskd.Core.API
}
[HttpGet]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.JwtOnly)]
[Route("yaml/location")]
public IActionResult GetYamlFileLocation()
{
@@ -103,7 +103,7 @@ namespace slskd.Core.API
}
[HttpGet]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.JwtOnly)]
[Route("yaml")]
public IActionResult GetYamlFile()
{
@@ -117,7 +117,7 @@ namespace slskd.Core.API
}
[HttpPost]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.JwtOnly)]
[Route("yaml")]
public IActionResult UpdateYamlFile([FromBody] string yaml)
{
@@ -144,7 +144,7 @@ namespace slskd.Core.API
}
[HttpPost]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[Route("yaml/validate")]
public IActionResult ValidateYamlFile([FromBody] string yaml)
{
diff --git a/src/slskd/Core/API/Controllers/ServerController.cs b/src/slskd/Core/API/Controllers/ServerController.cs
index 172333ec..a725c978 100644
--- a/src/slskd/Core/API/Controllers/ServerController.cs
+++ b/src/slskd/Core/API/Controllers/ServerController.cs
@@ -54,7 +54,7 @@ namespace slskd.Core.API
/// <returns></returns>
[HttpPut]
[Route("")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(200)]
[ProducesResponseType(403)]
public async Task<IActionResult> Connect()
@@ -74,7 +74,7 @@ namespace slskd.Core.API
/// <returns></returns>
[HttpDelete]
[Route("")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(204)]
[ProducesResponseType(403)]
public IActionResult Disconnect([FromBody] string message)
@@ -94,7 +94,7 @@ namespace slskd.Core.API
/// <response code="200"></response>
[HttpGet]
[Route("")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(typeof(ServerState), 200)]
[ProducesResponseType(403)]
public IActionResult Get()
diff --git a/src/slskd/Core/API/Controllers/SessionController.cs b/src/slskd/Core/API/Controllers/SessionController.cs
index 5f20aa9f..65a43e72 100644
--- a/src/slskd/Core/API/Controllers/SessionController.cs
+++ b/src/slskd/Core/API/Controllers/SessionController.cs
@@ -61,7 +61,7 @@ namespace slskd.Core.API
/// <response code="403">The authentication is is invalid.</response>
[HttpGet]
[Route("")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(200)]
[ProducesResponseType(401)]
public IActionResult Check()
diff --git a/src/slskd/Core/API/Hubs/ApplicationHub.cs b/src/slskd/Core/API/Hubs/ApplicationHub.cs
index 9861d0f9..063dfd2b 100644
--- a/src/slskd/Core/API/Hubs/ApplicationHub.cs
+++ b/src/slskd/Core/API/Hubs/ApplicationHub.cs
@@ -60,7 +60,7 @@ namespace slskd.Core.API
/// <summary>
/// The application SignalR hub.
/// </summary>
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
public class ApplicationHub : Hub
{
public ApplicationHub(
diff --git a/src/slskd/Core/API/Hubs/LogsHub.cs b/src/slskd/Core/API/Hubs/LogsHub.cs
index 7c14cc17..2bd30192 100644
--- a/src/slskd/Core/API/Hubs/LogsHub.cs
+++ b/src/slskd/Core/API/Hubs/LogsHub.cs
@@ -47,7 +47,7 @@ namespace slskd.Core.API
/// <summary>
/// The logs SignalR hub.
/// </summary>
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
public class LogsHub : Hub
{
public override async Task OnConnectedAsync()
diff --git a/src/slskd/Messaging/API/Controllers/ConversationsController.cs b/src/slskd/Messaging/API/Controllers/ConversationsController.cs
index 492340f0..17c55a10 100644
--- a/src/slskd/Messaging/API/Controllers/ConversationsController.cs
+++ b/src/slskd/Messaging/API/Controllers/ConversationsController.cs
@@ -66,7 +66,7 @@ namespace slskd.Messaging.API
/// A conversation with the specified username, or a message matching the specified id could not be found.
/// </response>
[HttpPut("{username}/{id}")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(200)]
[ProducesResponseType(404)]
public async Task<IActionResult> Acknowledge([FromRoute]string username, [FromRoute]int id)
@@ -90,7 +90,7 @@ namespace slskd.Messaging.API
/// <response code="200">The request completed successfully.</response>
/// <response code="404">A conversation with the specified username could not be found.</response>
[HttpPut("{username}")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(200)]
[ProducesResponseType(404)]
public async Task<IActionResult> AcknowledgeAll([FromRoute]string username)
@@ -124,7 +124,7 @@ namespace slskd.Messaging.API
/// <response code="204">The request completed successfully.</response>
/// <response code="404">A conversation with the specified username could not be found.</response>
[HttpDelete("{username}")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(404)]
[ProducesResponseType(204)]
public IActionResult Delete([FromRoute]string username)
@@ -145,7 +145,7 @@ namespace slskd.Messaging.API
/// <returns></returns>
/// <response code="200">The request completed successfully.</response>
[HttpGet("")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(typeof(Dictionary<string, List<PrivateMessageResponse>>), 200)]
public IActionResult GetAll()
{
@@ -166,7 +166,7 @@ namespace slskd.Messaging.API
/// <response code="200">The request completed successfully.</response>
/// <response code="404">A matching search was not found.</response>
[HttpGet("{username}")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(typeof(List<PrivateMessageResponse>), 200)]
[ProducesResponseType(404)]
public IActionResult GetByUsername([FromRoute]string username)
@@ -192,7 +192,7 @@ namespace slskd.Messaging.API
/// <response code="201">The request completed successfully.</response>
/// <response code="400">The specified message is null or empty.</response>
[HttpPost("{username}")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(201)]
[ProducesResponseType(400)]
public async Task<IActionResult> Send([FromRoute]string username, [FromBody]string message)
diff --git a/src/slskd/Messaging/API/Controllers/PublicChatController.cs b/src/slskd/Messaging/API/Controllers/PublicChatController.cs
index c30e08a8..83f7ede7 100644
--- a/src/slskd/Messaging/API/Controllers/PublicChatController.cs
+++ b/src/slskd/Messaging/API/Controllers/PublicChatController.cs
@@ -45,7 +45,7 @@ namespace slskd.Messaging.API
/// </summary>
/// <returns></returns>
[HttpPost]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
public async Task<IActionResult> Start()
{
await Client.StartPublicChatAsync();
@@ -57,7 +57,7 @@ namespace slskd.Messaging.API
/// </summary>
/// <returns></returns>
[HttpDelete]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
public async Task<IActionResult> Stop()
{
await Client.StopPublicChatAsync();
diff --git a/src/slskd/Messaging/API/Controllers/RoomsController.cs b/src/slskd/Messaging/API/Controllers/RoomsController.cs
index 8a3e5f3f..66993630 100644
--- a/src/slskd/Messaging/API/Controllers/RoomsController.cs
+++ b/src/slskd/Messaging/API/Controllers/RoomsController.cs
@@ -59,7 +59,7 @@ namespace slskd.Messaging.API
/// <returns></returns>
/// <response code="200">The request completed successfully.</response>
[HttpGet("joined")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(typeof(Dictionary<string, Dictionary<string, Room>>), 200)]
public IActionResult GetAll()
{
@@ -74,7 +74,7 @@ namespace slskd.Messaging.API
/// <response code="200">The request completed successfully.</response>
/// <response code="404">The specified roomName could not be found.</response>
[HttpGet("joined/{roomName}")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(typeof(Room), 200)]
[ProducesResponseType(404)]
public IActionResult GetByRoomName([FromRoute]string roomName)
@@ -96,7 +96,7 @@ namespace slskd.Messaging.API
/// <response code="201">The request completed successfully.</response>
/// <response code="404">The specified roomName could not be found.</response>
[HttpPost("joined/{roomName}/messages")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(201)]
[ProducesResponseType(404)]
public async Task<IActionResult> SendMessage([FromRoute]string roomName, [FromBody]string message)
@@ -119,7 +119,7 @@ namespace slskd.Messaging.API
/// <response code="201">The request completed successfully.</response>
/// <response code="404">The specified roomName could not be found.</response>
[HttpPost("joined/{roomName}/ticker")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(201)]
[ProducesResponseType(404)]
public async Task<IActionResult> SetTicker([FromRoute] string roomName, [FromBody] string message)
@@ -142,7 +142,7 @@ namespace slskd.Messaging.API
/// <response code="201">The request completed successfully.</response>
/// <response code="404">The specified roomName could not be found.</response>
[HttpPost("joined/{roomName}/members")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(201)]
[ProducesResponseType(404)]
public async Task<IActionResult> AddRoomMember([FromRoute]string roomName, [FromBody]string username)
@@ -164,7 +164,7 @@ namespace slskd.Messaging.API
/// <response code="200">The request completed successfully.</response>
/// <response code="404">The specified roomName could not be found.</response>
[HttpGet("joined/{roomName}/users")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(typeof(IList<UserData>), 200)]
[ProducesResponseType(404)]
public IActionResult GetUsersByRoomName([FromRoute]string roomName)
@@ -188,7 +188,7 @@ namespace slskd.Messaging.API
/// <response code="200">The request completed successfully.</response>
/// <response code="404">The specified roomName could not be found.</response>
[HttpGet("joined/{roomName}/messages")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(typeof(IList<RoomMessage>), 200)]
[ProducesResponseType(404)]
public IActionResult GetMessagesByRoomName([FromRoute]string roomName)
@@ -209,7 +209,7 @@ namespace slskd.Messaging.API
/// </summary>
/// <returns></returns>
[HttpGet("available")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(typeof(List<RoomInfo>), 200)]
public async Task<IActionResult> GetRooms()
{
@@ -237,7 +237,7 @@ namespace slskd.Messaging.API
/// <response code="201">The request completed successfully.</response>
/// <response code="304">The room has already been joined.</response>
[HttpPost("joined")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(typeof(Room), 201)]
[ProducesResponseType(304)]
public async Task<IActionResult> JoinRoom([FromBody]string roomName)
@@ -273,7 +273,7 @@ namespace slskd.Messaging.API
/// <response code="204">The request completed successfully.</response>
/// <response code="404">The room has not been joined.</response>
[HttpDelete("joined/{roomName}")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(204)]
[ProducesResponseType(404)]
public async Task<IActionResult> LeaveRoom([FromRoute]string roomName)
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index 7a1e636f..56ab6317 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -132,7 +132,7 @@ namespace slskd
/// <summary>
/// Gets the semantic application version.
/// </summary>
- public static string SemanticVersion { get; } = InformationalVersion.Split('-').First();
+ public static string SemanticVersion { get; } = InformationalVersion.Split('+').First();
/// <summary>
/// Gets the full application version, including both assembly and informational versions.
@@ -602,6 +602,22 @@ namespace slskd
if (!OptionsAtStartup.Web.Authentication.Disabled)
{
+ services.AddAuthorization(options =>
+ {
+ options.AddPolicy(AuthPolicy.JwtOnly, policy =>
+ {
+ policy.AuthenticationSchemes.Add(JwtBearerDefaults.AuthenticationScheme);
+ policy.RequireAuthenticatedUser();
+ });
+
+ options.AddPolicy(AuthPolicy.Any, policy =>
+ {
+ policy.AuthenticationSchemes.Add(ApiKeyAuthentication.AuthenticationScheme);
+ policy.AuthenticationSchemes.Add(JwtBearerDefaults.AuthenticationScheme);
+ policy.RequireAuthenticatedUser();
+ });
+ });
+
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
@@ -633,9 +649,7 @@ namespace slskd
return Task.CompletedTask;
},
};
- });
-
- services.AddAuthentication(ApiKeyAuthentication.AuthenticationScheme)
+ })
.AddScheme<ApiKeyAuthenticationOptions, ApiKeyAuthenticationHandler>(ApiKeyAuthentication.AuthenticationScheme, options =>
{
options.EnableSignalRSupport = true;
@@ -647,6 +661,21 @@ namespace slskd
{
Log.Warning("Authentication of web requests is DISABLED");
+ services.AddAuthorization(options =>
+ {
+ options.AddPolicy(AuthPolicy.Any, policy =>
+ {
+ policy.AuthenticationSchemes.Add(PassthroughAuthentication.AuthenticationScheme);
+ policy.RequireAuthenticatedUser();
+ });
+
+ options.AddPolicy(AuthPolicy.JwtOnly, policy =>
+ {
+ policy.AuthenticationSchemes.Add(PassthroughAuthentication.AuthenticationScheme);
+ policy.RequireAuthenticatedUser();
+ });
+ });
+
services.AddAuthentication(PassthroughAuthentication.AuthenticationScheme)
.AddScheme<PassthroughAuthenticationOptions, PassthroughAuthenticationHandler>(PassthroughAuthentication.AuthenticationScheme, options =>
{
diff --git a/src/slskd/Search/API/Controllers/SearchesController.cs b/src/slskd/Search/API/Controllers/SearchesController.cs
index acae18e0..aadf01b2 100644
--- a/src/slskd/Search/API/Controllers/SearchesController.cs
+++ b/src/slskd/Search/API/Controllers/SearchesController.cs
@@ -54,7 +54,7 @@ namespace slskd.Search.API
/// <response code="400">The specified <paramref name="request"/> was malformed.</response>
/// <response code="500">The search terminated abnormally.</response>
[HttpPost("")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
public async Task<IActionResult> Post([FromBody] SearchRequest request)
{
if (string.IsNullOrWhiteSpace(request.SearchText))
@@ -91,7 +91,7 @@ namespace slskd.Search.API
/// <response code="200">The request completed successfully.</response>
/// <response code="404">A matching search was not found.</response>
[HttpGet("{id}")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
public async Task<IActionResult> GetById([FromRoute] Guid id, [FromQuery] bool includeResponses = false)
{
var search = await Searches.FindAsync(search => search.Id == id, includeResponses);
@@ -112,7 +112,7 @@ namespace slskd.Search.API
/// <response code="200">The request completed successfully.</response>
/// <response code="404">A matching search was not found.</response>
[HttpGet("{id}/responses")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
public async Task<IActionResult> GetResponsesById([FromRoute] Guid id)
{
var search = await Searches.FindAsync(search => search.Id == id, includeResponses: true);
@@ -130,7 +130,7 @@ namespace slskd.Search.API
/// </summary>
/// <returns></returns>
[HttpGet("")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
public async Task<IActionResult> GetAll()
{
var searches = await Searches.ListAsync();
@@ -145,7 +145,7 @@ namespace slskd.Search.API
/// <response code="304">The search was not in progress.</response>
/// <returns></returns>
[HttpPut("{id}")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(200)]
[ProducesResponseType(304)]
public async Task<IActionResult> Cancel([FromRoute] Guid id)
@@ -173,7 +173,7 @@ namespace slskd.Search.API
/// <response code="404">A search with the specified id could not be found.</response>
/// <returns></returns>
[HttpDelete("{id}")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(204)]
[ProducesResponseType(404)]
public async Task<IActionResult> Delete([FromRoute] Guid id)
diff --git a/src/slskd/Search/API/Hubs/SearchHub.cs b/src/slskd/Search/API/Hubs/SearchHub.cs
index aaf9a287..b1fbf725 100644
--- a/src/slskd/Search/API/Hubs/SearchHub.cs
+++ b/src/slskd/Search/API/Hubs/SearchHub.cs
@@ -73,7 +73,7 @@ namespace slskd.Search.API
/// <summary>
/// The search SignalR hub.
/// </summary>
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
public class SearchHub : Hub
{
public SearchHub(
diff --git a/src/slskd/Shares/API/Controllers/SharesController.cs b/src/slskd/Shares/API/Controllers/SharesController.cs
index 5f87f900..d07e8eed 100644
--- a/src/slskd/Shares/API/Controllers/SharesController.cs
+++ b/src/slskd/Shares/API/Controllers/SharesController.cs
@@ -32,7 +32,6 @@ namespace slskd.Shares.API
[Produces("application/json")]
[Consumes("application/json")]
[Route("api/v{version:apiVersion}/[controller]")]
- [Authorize]
public class SharesController : ControllerBase
{
/// <summary>
@@ -53,7 +52,7 @@ namespace slskd.Shares.API
/// <response code="200">The request completed successfully.</response>
/// <returns></returns>
[HttpGet("")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(typeof(IEnumerable<SummarizedShare>), 200)]
public async Task<IActionResult> List()
{
@@ -87,7 +86,7 @@ namespace slskd.Shares.API
/// <response code="404">The requested share could not be found.</response>
/// <returns></returns>
[HttpGet("{id}")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(typeof(SummarizedShare), 200)]
[ProducesResponseType(404)]
public async Task<IActionResult> Get(string id)
@@ -122,7 +121,7 @@ namespace slskd.Shares.API
/// <returns></returns>
/// <response code="200">The request completed successfully.</response>
[HttpGet("contents")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(typeof(IEnumerable<Directory>), 200)]
public async Task<IActionResult> BrowseAll()
{
@@ -137,6 +136,7 @@ namespace slskd.Shares.API
/// <response code="200">The request completed successfully.</response>
/// <response code="404">The requested share could not be found.</response>
[HttpGet("{id}/contents")]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(typeof(IEnumerable<Directory>), 200)]
[ProducesResponseType(404)]
public async Task<IActionResult> BrowseShare(string id)
@@ -161,7 +161,7 @@ namespace slskd.Shares.API
/// <response code="409">A share scan is already in progress.</response>
[HttpPut]
[Route("")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(204)]
[ProducesResponseType(409)]
public IActionResult RescanSharesAsync()
@@ -186,7 +186,7 @@ namespace slskd.Shares.API
/// <response code="409">A share scan was not in progress.</response>
[HttpDelete]
[Route("")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(204)]
[ProducesResponseType(404)]
public IActionResult CancelShareScan()
diff --git a/src/slskd/Shares/ShareRepository.cs b/src/slskd/Shares/ShareRepository.cs
index b8ecd2be..7b723ac6 100644
--- a/src/slskd/Shares/ShareRepository.cs
+++ b/src/slskd/Shares/ShareRepository.cs
@@ -23,7 +23,6 @@ namespace slskd.Shares
using System.Linq;
using Microsoft.Data.Sqlite;
using Serilog;
- using slskd.Transfers.Uploads;
using Soulseek;
/// <summary>
@@ -86,6 +85,13 @@ namespace slskd.Shares
void InsertFile(string maskedFilename, string originalFilename, DateTime touchedAt, Soulseek.File file, long timestamp);
/// <summary>
+ /// Inserts a scan record at the specified <paramref name="timestamp"/>.
+ /// </summary>
+ /// <param name="timestamp">The timestamp associated with the scan.</param>
+ /// <param name="options">The options snapshot at the start of the scan.</param>
+ void InsertScan(long timestamp, Options.SharesOptions options);
+
+ /// <summary>
/// Lists all directories.
/// </summary>
/// <param name="parentDirectory">The optional directory prefix used for listing subdirectories.</param>
@@ -126,6 +132,13 @@ namespace slskd.Shares
/// <param name="query">The search query.</param>
/// <returns>The list of matching files.</returns>
IEnumerable<Soulseek.File> Search(SearchQuery query);
+
+ /// <summary>
+ /// Updates the scan started at the specified <paramref name="timestamp"/> to set the <paramref name="end"/>.
+ /// </summary>
+ /// <param name="timestamp">The timestamp associated with the scan.</param>
+ /// <param name="end">The timestamp at the conclusion of the scan.</param>
+ void UpdateScan(long timestamp, long end);
}
/// <summary>
@@ -160,10 +173,18 @@ namespace slskd.Shares
var log = Serilog.Log.ForContext<ShareRepository>();
+ // to update this schema map, run the following query against a valid, up-to-date database and paste the output below:
+ // select '{ "' || name || '", "' || sql || '" },' from sqlite_master where type = 'table'
var schema = new Dictionary<string, string>()
{
+ { "scans", "CREATE TABLE scans (timestamp INTEGER PRIMARY KEY, options TEXT NOT NULL, end INTEGER DEFAULT NULL)" },
{ "directories", "CREATE TABLE directories (name TEXT PRIMARY KEY, timestamp INTEGER NOT NULL)" },
{ "filenames", "CREATE VIRTUAL TABLE filenames USING fts5(maskedFilename)" },
+ { "filenames_data", "CREATE TABLE 'filenames_data'(id INTEGER PRIMARY KEY, block BLOB)" },
+ { "filenames_idx", "CREATE TABLE 'filenames_idx'(segid, term, pgno, PRIMARY KEY(segid, term)) WITHOUT ROWID" },
+ { "filenames_content", "CREATE TABLE 'filenames_content'(id INTEGER PRIMARY KEY, c0)" },
+ { "filenames_docsize", "CREATE TABLE 'filenames_docsize'(id INTEGER PRIMARY KEY, sz BLOB)" },
+ { "filenames_config", "CREATE TABLE 'filenames_config'(k PRIMARY KEY, v) WITHOUT ROWID" },
{ "files", "CREATE TABLE files (maskedFilename TEXT PRIMARY KEY, originalFilename TEXT NOT NULL, size BIGINT NOT NULL, touchedAt TEXT NOT NULL, code INTEGER DEFAULT 1 NOT NULL, extension TEXT, attributeJson TEXT NOT NULL, timestamp INTEGER NOT NULL)" },
};
@@ -174,7 +195,7 @@ namespace slskd.Shares
using var conn = new SqliteConnection(connectionString);
conn.Open();
- using var cmd = new SqliteCommand("SELECT name, sql from sqlite_master WHERE type = 'table' AND name IN ('directories', 'filenames', 'files');", conn);
+ using var cmd = new SqliteCommand("SELECT name, sql from sqlite_master WHERE type = 'table';", conn);
var reader = cmd.ExecuteReader();
var rows = 0;
@@ -306,9 +327,11 @@ namespace slskd.Shares
if (discardExisting)
{
- conn.ExecuteNonQuery("DROP TABLE IF EXISTS directories; DROP TABLE IF EXISTS filenames; DROP TABLE IF EXISTS files;");
+ conn.ExecuteNonQuery("DROP TABLE IF EXISTS scans; DROP TABLE IF EXISTS directories; DROP TABLE IF EXISTS filenames; DROP TABLE IF EXISTS files;");
}
+ conn.ExecuteNonQuery("CREATE TABLE IF NOT EXISTS scans (timestamp INTEGER PRIMARY KEY, options TEXT NOT NULL, end INTEGER DEFAULT NULL);");
+
conn.ExecuteNonQuery("CREATE TABLE IF NOT EXISTS directories (name TEXT PRIMARY KEY, timestamp INTEGER NOT NULL);");
conn.ExecuteNonQuery("CREATE VIRTUAL TABLE IF NOT EXISTS filenames USING fts5(maskedFilename);");
@@ -392,6 +415,22 @@ namespace slskd.Shares
}
/// <summary>
+ /// Inserts a scan record at the specified <paramref name="timestamp"/>.
+ /// </summary>
+ /// <param name="timestamp">The timestamp associated with the scan.</param>
+ /// <param name="options">The options snapshot at the start of the scan.</param>
+ public void InsertScan(long timestamp, Options.SharesOptions options)
+ {
+ using var conn = GetConnection();
+
+ conn.ExecuteNonQuery("INSERT INTO scans (timestamp, options) VALUES(@timestamp, @options)", cmd =>
+ {
+ cmd.Parameters.AddWithValue("timestamp", timestamp);
+ cmd.Parameters.AddWithValue("options", options.ToJson());
+ });
+ }
+
+ /// <summary>
/// Lists all directories.
/// </summary>
/// <param name="parentDirectory">The optional directory prefix used for listing subdirectories.</param>
@@ -583,6 +622,22 @@ namespace slskd.Shares
}
}
+ /// <summary>
+ /// Updates the scan started at the specified <paramref name="timestamp"/> to set the <paramref name="end"/>.
+ /// </summary>
+ /// <param name="timestamp">The timestamp associated with the scan.</param>
+ /// <param name="end">The timestamp at the conclusion of the scan.</param>
+ public void UpdateScan(long timestamp, long end)
+ {
+ using var conn = GetConnection();
+
+ conn.ExecuteNonQuery("UPDATE scans SET end = @end WHERE timestamp = @timestamp;", cmd =>
+ {
+ cmd.Parameters.AddWithValue("end", end);
+ cmd.Parameters.AddWithValue("timestamp", timestamp);
+ });
+ }
+
private SqliteConnection GetConnection(string connectionString = null)
{
connectionString ??= ConnectionString;
diff --git a/src/slskd/Shares/ShareScanner.cs b/src/slskd/Shares/ShareScanner.cs
index 369e4981..74f0d131 100644
--- a/src/slskd/Shares/ShareScanner.cs
+++ b/src/slskd/Shares/ShareScanner.cs
@@ -44,9 +44,9 @@ namespace slskd.Shares
/// Scans the configured shares and fills the cache.
/// </summary>
/// <param name="shares">The list of shares from which to fill the cache.</param>
- /// <param name="filters">The list of regular expressions used to exclude files or paths from scanning.</param>
+ /// <param name="options">The current options snapshot.</param>
/// <returns>The operation context.</returns>
- Task ScanAsync(IEnumerable<Share> shares, IEnumerable<Regex> filters);
+ Task ScanAsync(IEnumerable<Share> shares, Options.SharesOptions options);
/// <summary>
/// Cancels the currently running fill operation, if one is running.
@@ -90,9 +90,9 @@ namespace slskd.Shares
/// Scans the configured shares and fills the cache.
/// </summary>
/// <param name="shares">The list of shares from which to fill the cache.</param>
- /// <param name="filters">The list of regular expressions used to exclude files or paths from scanning.</param>
+ /// <param name="options">The current options snapshot.</param>
/// <returns>The operation context.</returns>
- public async Task ScanAsync(IEnumerable<Share> shares, IEnumerable<Regex> filters)
+ public async Task ScanAsync(IEnumerable<Share> shares, Options.SharesOptions options)
{
// obtain the semaphore, or fail if it can't be obtained immediately, indicating that a scan is running.
if (!await SyncRoot.WaitAsync(millisecondsTimeout: 0))
@@ -130,10 +130,16 @@ namespace slskd.Shares
Log.Information("Shared file cache re-created and ready for scan.");
}
+ var filters = options.Filters
+ .Select(filter => new Regex(filter, RegexOptions.Compiled))
+ .ToList();
+
Log.Information("Starting shared file scan");
var timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
+ Repository.InsertScan(timestamp, options);
+
var sw = new Stopwatch();
var swSnapshot = 0L;
sw.Start();
@@ -316,6 +322,8 @@ namespace slskd.Shares
State.SetValue(state => state with { Cancelled = true });
}
+ Repository.UpdateScan(timestamp, DateTimeOffset.UtcNow.ToUnixTimeMilliseconds());
+
Log.Debug("Backing up shared file cache database...");
Repository.BackupTo(Program.ConnectionStrings.SharesBackup);
Log.Debug("Shared file cache database backup complete");
diff --git a/src/slskd/Shares/ShareService.cs b/src/slskd/Shares/ShareService.cs
index 09085b72..a9c8c629 100644
--- a/src/slskd/Shares/ShareService.cs
+++ b/src/slskd/Shares/ShareService.cs
@@ -94,7 +94,6 @@ namespace slskd.Shares
private List<Share> SharesList { get; set; } = new List<Share>();
private IManagedState<ShareState> State { get; } = new ManagedState<ShareState>();
private SemaphoreSlim SyncRoot { get; } = new SemaphoreSlim(1, 1);
- private List<Regex> FilterRegexes { get; set; } = new List<Regex>();
private StorageMode CacheStorageMode { get; }
private ILogger Log { get; } = Serilog.Log.ForContext<ShareService>();
@@ -218,7 +217,7 @@ namespace slskd.Shares
/// <exception cref="ShareScanInProgressException">Thrown when a scan is already in progress.</exception>
public Task ScanAsync()
{
- return Scanner.ScanAsync(Shares, FilterRegexes);
+ return Scanner.ScanAsync(Shares, OptionsMonitor.CurrentValue.Shares);
}
/// <summary>
@@ -251,6 +250,8 @@ namespace slskd.Shares
/// <returns>The operation context.</returns>
public async Task InitializeAsync(bool forceRescan = false)
{
+ Log.Information("Initializing shares");
+
try
{
if (forceRescan)
@@ -258,31 +259,54 @@ namespace slskd.Shares
Log.Warning("Performing a forced re-scan of shares");
await ScanAsync();
}
- else if (CacheStorageMode == StorageMode.Memory || (CacheStorageMode == StorageMode.Disk && !ShareRepository.TryValidateDatabase(Program.ConnectionStrings.Shares)))
+ else if (CacheStorageMode == StorageMode.Memory)
{
- Log.Debug($"Share cache {(CacheStorageMode == StorageMode.Memory ? "StorageMode is 'Memory'" : "database is missing from disk")}. Attempting to load from backup...");
+ Log.Information("Share cache StorageMode is 'Memory'. Attempting to load from backup...");
- // the backup is missing; we can't do anything but recreate it from scratch
- if (!ShareRepository.TryValidateDatabase(Program.ConnectionStrings.SharesBackup))
+ if (ShareRepository.TryValidateDatabase(Program.ConnectionStrings.SharesBackup))
{
- Log.Warning("Share cache couldn't be loaded from backup");
- await InitializeAsync(forceRescan: true);
- }
- else
- {
- Log.Debug("Share cache backup located. Attempting to restore...");
+ Log.Information("Share cache backup validated. Attempting to restore...");
Repository.RestoreFrom(connectionString: Program.ConnectionStrings.SharesBackup);
Log.Information("Share cache successfully restored from backup");
}
+ else
+ {
+ Log.Warning("Share cache backup is missing, corrupt, or is out of date");
+ throw new ShareInitializationException("Share cache backup is missing, corrupt, or is out of date");
+ }
}
- else
+ else if (CacheStorageMode == StorageMode.Disk)
{
- // the cache mode is disk and the existing db is valid. nothing to do.
+ Log.Information("Share cache StorageMode is 'Disk'. Attempting to validate...");
+
+ if (ShareRepository.TryValidateDatabase(Program.ConnectionStrings.Shares))
+ {
+ // no-op
+ }
+ else
+ {
+ Log.Warning("Share cache is missing, corrupt, or is out of date. Attempting to load from backup...");
+
+ if (ShareRepository.TryValidateDatabase(Program.ConnectionStrings.SharesBackup))
+ {
+ Log.Information("Share cache backup validated. Attempting to restore...");
+
+ Repository.RestoreFrom(connectionString: Program.ConnectionStrings.SharesBackup);
+
+ Log.Information("Share cache successfully restored from backup");
+ }
+ else
+ {
+ Log.Warning("Share cache and backup are both missing, corrupt, or is out of date");
+ throw new ShareInitializationException("Share cache and backup are both missing, corrupt, or is out of date");
+ }
+ }
}
// one of several thigns happened above before we got here:
+ // this method was called with forceRescan = true
// the storage mode is memory, and we loaded the in-memory db from a valid backup
// the storage mode is disk, and the file is there and valid
// the storage mode is disk but either missing or invalid, and we restored from a valid backup
@@ -335,13 +359,8 @@ namespace slskd.Shares
.OrderByDescending(share => share.LocalPath.Length) // process subdirectories first. this allows them to be aliased separately from their parent
.ToList();
- var regexes = options.Shares.Filters
- .Select(filter => new Regex(filter, RegexOptions.Compiled))
- .ToList();
-
SharesList = shares;
- FilterRegexes = regexes;
-
+
State.SetValue(state => state with { ScanPending = true });
LastOptionsHash = optionsHash;
diff --git a/src/slskd/Transfers/API/Controllers/TransfersController.cs b/src/slskd/Transfers/API/Controllers/TransfersController.cs
index bdab6582..45896c2e 100644
--- a/src/slskd/Transfers/API/Controllers/TransfersController.cs
+++ b/src/slskd/Transfers/API/Controllers/TransfersController.cs
@@ -57,7 +57,7 @@ namespace slskd.Transfers.API
/// <response code="204">The download was cancelled successfully.</response>
/// <response code="404">The specified download was not found.</response>
[HttpDelete("downloads/{username}/{id}")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(204)]
[ProducesResponseType(404)]
public async Task<IActionResult> CancelDownloadAsync([FromRoute, Required] string username, [FromRoute, Required]string id, [FromQuery]bool remove = false)
@@ -94,7 +94,7 @@ namespace slskd.Transfers.API
/// <response code="204">The upload was cancelled successfully.</response>
/// <response code="404">The specified upload was not found.</response>
[HttpDelete("uploads/{username}/{id}")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(204)]
[ProducesResponseType(404)]
public async Task<IActionResult> CancelUpload([FromRoute, Required] string username, [FromRoute, Required]string id, [FromQuery]bool remove = false)
@@ -131,7 +131,7 @@ namespace slskd.Transfers.API
/// <response code="403">The download was rejected.</response>
/// <response code="500">An unexpected error was encountered.</response>
[HttpPost("downloads/{username}")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(201)]
[ProducesResponseType(typeof(string), 403)]
[ProducesResponseType(typeof(string), 500)]
@@ -154,7 +154,7 @@ namespace slskd.Transfers.API
/// <returns></returns>
/// <response code="200">The request completed successfully.</response>
[HttpGet("downloads")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(200)]
public async Task<IActionResult> GetDownloadsAsync([FromQuery]bool includeRemoved = false)
{
@@ -181,7 +181,7 @@ namespace slskd.Transfers.API
/// <returns></returns>
/// <response code="200">The request completed successfully.</response>
[HttpGet("downloads/{username}")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(200)]
public async Task<IActionResult> GetDownloadsAsync([FromRoute, Required] string username)
{
@@ -207,7 +207,7 @@ namespace slskd.Transfers.API
}
[HttpGet("downloads/{username}/{id}")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(typeof(API.Transfer), 200)]
[ProducesResponseType(404)]
public async Task<IActionResult> GetDownload([FromRoute, Required] string username, [FromRoute, Required] string id)
@@ -237,7 +237,7 @@ namespace slskd.Transfers.API
/// <response code="200">The request completed successfully.</response>
/// <response code="404">The specified download was not found.</response>
[HttpGet("downloads/{username}/{id}/position")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(typeof(API.Transfer), 200)]
[ProducesResponseType(404)]
public async Task<IActionResult> GetPlaceInQueueAsync([FromRoute, Required] string username, [FromRoute, Required] string id)
@@ -268,7 +268,7 @@ namespace slskd.Transfers.API
/// <returns></returns>
/// <response code="200">The request completed successfully.</response>
[HttpGet("uploads")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(200)]
public async Task<IActionResult> GetUploads([FromQuery] bool includeRemoved = false)
{
@@ -295,7 +295,7 @@ namespace slskd.Transfers.API
/// <returns></returns>
/// <response code="200">The request completed successfully.</response>
[HttpGet("uploads/{username}")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(200)]
public async Task<IActionResult> GetUploads([FromRoute, Required] string username)
{
@@ -328,7 +328,7 @@ namespace slskd.Transfers.API
/// <returns></returns>
/// <response code="200">The request completed successfully.</response>
[HttpGet("uploads/{username}/{id}")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(200)]
public async Task<IActionResult> GetUploads([FromRoute, Required] string username, [FromRoute, Required] string id)
{
diff --git a/src/slskd/Transfers/Downloads/DownloadService.cs b/src/slskd/Transfers/Downloads/DownloadService.cs
index 9b4d14fc..4e037f38 100644
--- a/src/slskd/Transfers/Downloads/DownloadService.cs
+++ b/src/slskd/Transfers/Downloads/DownloadService.cs
@@ -493,6 +493,18 @@ namespace slskd.Transfers.Downloads
Directory.CreateDirectory(destinationPath);
}
+ if (File.Exists(destinationFilename))
+ {
+ string extensionlessFilename = Path.GetFileNameWithoutExtension(filename);
+ string extension = Path.GetExtension(filename);
+
+ while (File.Exists(destinationFilename))
+ {
+ string filenameUTC = $"{extensionlessFilename}_{DateTime.UtcNow.Ticks}.{extension}";
+ destinationFilename = filenameUTC.ToLocalFilename(destinationDirectory);
+ }
+ }
+
File.Move(sourceFilename, destinationFilename, overwrite: true);
if (!Directory.EnumerateFileSystemEntries(Path.GetDirectoryName(sourceFilename)).Any())
diff --git a/src/slskd/Users/API/Controllers/UsersController.cs b/src/slskd/Users/API/Controllers/UsersController.cs
index 2439785e..0f06a677 100644
--- a/src/slskd/Users/API/Controllers/UsersController.cs
+++ b/src/slskd/Users/API/Controllers/UsersController.cs
@@ -59,7 +59,7 @@ namespace slskd.Users.API
/// <returns></returns>
/// <response code="200">The request completed successfully.</response>
[HttpGet("{username}/endpoint")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(typeof(IPEndPoint), 200)]
[ProducesResponseType(404)]
public async Task<IActionResult> Endpoint([FromRoute, Required] string username)
@@ -81,7 +81,7 @@ namespace slskd.Users.API
/// <param name="username">The username of the user.</param>
/// <returns></returns>
[HttpGet("{username}/browse")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(typeof(IEnumerable<Directory>), 200)]
[ProducesResponseType(404)]
public async Task<IActionResult> Browse([FromRoute, Required] string username)
@@ -110,7 +110,7 @@ namespace slskd.Users.API
/// <param name="username">The username of the user.</param>
/// <returns></returns>
[HttpGet("{username}/browse/status")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(typeof(decimal), 200)]
[ProducesResponseType(404)]
public IActionResult BrowseStatus([FromRoute, Required] string username)
@@ -129,7 +129,7 @@ namespace slskd.Users.API
/// <param name="username">The username of the user.</param>
/// <returns></returns>
[HttpGet("{username}/info")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(typeof(Info), 200)]
[ProducesResponseType(404)]
public async Task<IActionResult> Info([FromRoute, Required] string username)
@@ -151,7 +151,7 @@ namespace slskd.Users.API
/// <param name="username">The username of the user.</param>
/// <returns></returns>
[HttpGet("{username}/status")]
- [Authorize]
+ [Authorize(Policy = AuthPolicy.Any)]
[ProducesResponseType(typeof(Status), 200)]
[ProducesResponseType(404)]
public async Task<IActionResult> Status([FromRoute, Required] string username)