aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2023-09-17 16:01:36 -0500
committerJP Dillingham <jp@dillingham.me>2023-09-17 16:01:36 -0500
commit3920f14a70107f67831d09934861badbc1fc70cf (patch)
tree50dd61bf02cbd5276c7213903bc2de9f33112e5b /src
parent132de2917d3d43b902387f44ef7baf8f49637fe0 (diff)
downloadslskd-3920f14a70107f67831d09934861badbc1fc70cf.tar.gz
consolidate I/UploadService
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Transfers/Uploads/IUploadService.cs90
-rw-r--r--src/slskd/Transfers/Uploads/UploadService.cs74
2 files changed, 74 insertions, 90 deletions
diff --git a/src/slskd/Transfers/Uploads/IUploadService.cs b/src/slskd/Transfers/Uploads/IUploadService.cs
deleted file mode 100644
index 8fa0b194..00000000
--- a/src/slskd/Transfers/Uploads/IUploadService.cs
+++ /dev/null
@@ -1,90 +0,0 @@
-// <copyright file="IUploadService.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.Transfers.Uploads
-{
- using System;
- using System.Collections.Generic;
- using System.Linq.Expressions;
- using System.Threading.Tasks;
-
- /// <summary>
- /// Manages uploads.
- /// </summary>
- public interface IUploadService
- {
- /// <summary>
- /// Gets the upload governor.
- /// </summary>
- IUploadGovernor Governor { get; }
-
- /// <summary>
- /// Gets the upload queue.
- /// </summary>
- IUploadQueue Queue { get; }
-
- /// <summary>
- /// Adds the specified <paramref name="transfer"/>. Supersedes any existing record for the same file and username.
- /// </summary>
- /// <remarks>This should generally not be called; use <see cref="EnqueueAsync(string, string)"/> instead.</remarks>
- /// <param name="transfer"></param>
- void AddOrSupersede(Transfer transfer);
-
- /// <summary>
- /// Enqueues the requested file.
- /// </summary>
- /// <param name="username">The username of the requesting user.</param>
- /// <param name="filename">The local filename of the requested file.</param>
- /// <returns>The operation context.</returns>
- Task EnqueueAsync(string username, string filename);
-
- /// <summary>
- /// Finds a single upload matching the specified <paramref name="expression"/>.
- /// </summary>
- /// <param name="expression">The expression to use to match uploads.</param>
- /// <returns>The found transfer, or default if not found.</returns>
- Transfer Find(Expression<Func<Transfer, bool>> expression);
-
- /// <summary>
- /// Returns a list of all uploads matching the optional <paramref name="expression"/>.
- /// </summary>
- /// <param name="expression">An optional expression used to match uploads.</param>
- /// <param name="includeRemoved">Optionally include uploads that have been removed previously.</param>
- /// <returns>The list of uploads matching the specified expression, or all uploads if no expression is specified.</returns>
- List<Transfer> List(Expression<Func<Transfer, bool>> expression = null, bool includeRemoved = false);
-
- /// <summary>
- /// Removes the upload matching the specified <paramref name="id"/>.
- /// </summary>
- /// <remarks>This is a soft delete; the record is retained for historical retrieval.</remarks>
- /// <param name="id">The unique identifier of the upload.</param>
- void Remove(Guid id);
-
- /// <summary>
- /// Cancels the upload matching the specified <paramref name="id"/>, if it is in progress.
- /// </summary>
- /// <param name="id">The unique identifier for the upload.</param>
- /// <returns>A value indicating whether the upload was successfully cancelled.</returns>
- bool TryCancel(Guid id);
-
- /// <summary>
- /// Synchronously updates the specified <paramref name="transfer"/>.
- /// </summary>
- /// <param name="transfer">The transfer to update.</param>
- void Update(Transfer transfer);
- }
-} \ No newline at end of file
diff --git a/src/slskd/Transfers/Uploads/UploadService.cs b/src/slskd/Transfers/Uploads/UploadService.cs
index cfbeeb8b..b9f74dac 100644
--- a/src/slskd/Transfers/Uploads/UploadService.cs
+++ b/src/slskd/Transfers/Uploads/UploadService.cs
@@ -37,6 +37,80 @@ namespace slskd.Transfers.Uploads
/// <summary>
/// Manages uploads.
/// </summary>
+ public interface IUploadService
+ {
+ /// <summary>
+ /// Gets the upload governor.
+ /// </summary>
+ IUploadGovernor Governor { get; }
+
+ /// <summary>
+ /// Gets the upload queue.
+ /// </summary>
+ IUploadQueue Queue { get; }
+
+ /// <summary>
+ /// Adds the specified <paramref name="transfer"/>. Supersedes any existing record for the same file and username.
+ /// </summary>
+ /// <remarks>This should generally not be called; use <see cref="EnqueueAsync(string, string)"/> instead.</remarks>
+ /// <param name="transfer"></param>
+ void AddOrSupersede(Transfer transfer);
+
+ /// <summary>
+ /// Enqueues the requested file.
+ /// </summary>
+ /// <param name="username">The username of the requesting user.</param>
+ /// <param name="filename">The local filename of the requested file.</param>
+ /// <returns>The operation context.</returns>
+ Task EnqueueAsync(string username, string filename);
+
+ /// <summary>
+ /// Finds a single upload matching the specified <paramref name="expression"/>.
+ /// </summary>
+ /// <param name="expression">The expression to use to match uploads.</param>
+ /// <returns>The found transfer, or default if not found.</returns>
+ Transfer Find(Expression<Func<Transfer, bool>> expression);
+
+ /// <summary>
+ /// Returns a list of all uploads matching the optional <paramref name="expression"/>.
+ /// </summary>
+ /// <param name="expression">An optional expression used to match uploads.</param>
+ /// <param name="includeRemoved">Optionally include uploads that have been removed previously.</param>
+ /// <returns>The list of uploads matching the specified expression, or all uploads if no expression is specified.</returns>
+ List<Transfer> List(Expression<Func<Transfer, bool>> expression = null, bool includeRemoved = false);
+
+ /// <summary>
+ /// Removes <see cref="TransferStates.Completed"/> uploads older than the specified <paramref name="age"/>.
+ /// </summary>
+ /// <param name="age">The age after which uploads are eligible for pruning, in hours.</param>
+ /// <param name="state">An optional, additional state by which uploads are filtered for pruning.</param>
+ /// <returns>The number of pruned uploads.</returns>
+ int Prune(int age, TransferStates state = TransferStates.Completed);
+
+ /// <summary>
+ /// Removes the upload matching the specified <paramref name="id"/>.
+ /// </summary>
+ /// <remarks>This is a soft delete; the record is retained for historical retrieval.</remarks>
+ /// <param name="id">The unique identifier of the upload.</param>
+ void Remove(Guid id);
+
+ /// <summary>
+ /// Cancels the upload matching the specified <paramref name="id"/>, if it is in progress.
+ /// </summary>
+ /// <param name="id">The unique identifier for the upload.</param>
+ /// <returns>A value indicating whether the upload was successfully cancelled.</returns>
+ bool TryCancel(Guid id);
+
+ /// <summary>
+ /// Synchronously updates the specified <paramref name="transfer"/>.
+ /// </summary>
+ /// <param name="transfer">The transfer to update.</param>
+ void Update(Transfer transfer);
+ }
+
+ /// <summary>
+ /// Manages uploads.
+ /// </summary>
public class UploadService : IUploadService
{
public UploadService(