From 136204584f16c5abc5e8dede8b68e1c162d2febc Mon Sep 17 00:00:00 2001 From: JP Dillingham Date: Sat, 19 Feb 2022 16:52:02 -0600 Subject: check user privileges prior to upload --- src/slskd/Application.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src') diff --git a/src/slskd/Application.cs b/src/slskd/Application.cs index 83f18a52..840ed1ba 100644 --- a/src/slskd/Application.cs +++ b/src/slskd/Application.cs @@ -82,6 +82,7 @@ namespace slskd IConversationTracker conversationTracker, IRoomTracker roomTracker, IRoomService roomService, + IUserService userService, ISharedFileCache sharedFileCache, IPushbulletService pushbulletService, IHubContext applicationHub, @@ -107,6 +108,7 @@ namespace slskd Pushbullet = pushbulletService; RoomService = roomService; + Users = userService; ApplicationHub = applicationHub; LogHub = logHub; @@ -157,6 +159,7 @@ namespace slskd private ITransferService Transfers { get; init; } private IHubContext ApplicationHub { get; set; } private IHubContext LogHub { get; set; } + private IUserService Users { get; set; } public void CollectGarbage() { @@ -587,6 +590,14 @@ namespace slskd // uploads would be handled separately. Task.Run(async () => { + // prime the privileges cache for this user + // this must be done prior to each upload, or we risk not correctly categorizing + // privileged users as such. + if (await Users.IsPrivilegedAsync(username)) + { + Log.Debug("User {Username} is privileged; upload will be prioritized", username); + } + using var stream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read); await Client.UploadAsync(username, filename, fileInfo.FullName, options: topts, cancellationToken: cts.Token); }).ContinueWith(t => -- cgit v1.2.3