aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2026-05-16 17:40:44 -0500
committerJP Dillingham <jp@dillingham.me>2026-05-16 17:40:44 -0500
commit147aad8cca088734587c144434044a02d9ec7a96 (patch)
tree1dfd8f93f5b871ee405c6891e648cc6ecb653341 /src
parentd8bebbbe1ead96b99246c88816f846747eed5bb7 (diff)
downloadslskd-147aad8cca088734587c144434044a02d9ec7a96.tar.gz
tweak endpoint, docs, annotation. obsolete StateDescription to avoid usage
Diffstat (limited to 'src')
-rw-r--r--src/slskd/Core/Data/Migrations/Z2025_04_01_TransferStateMigration.cs3
-rw-r--r--src/slskd/Transfers/API/DTO/QueueDownloadBatchRequest.cs13
-rw-r--r--src/slskd/Transfers/API/DTO/Transfer.cs169
-rw-r--r--src/slskd/Transfers/TransfersDbContext.cs6
-rw-r--r--src/slskd/Transfers/Types/Transfer.cs3
5 files changed, 23 insertions, 171 deletions
diff --git a/src/slskd/Core/Data/Migrations/Z2025_04_01_TransferStateMigration.cs b/src/slskd/Core/Data/Migrations/Z2025_04_01_TransferStateMigration.cs
index 6c5810c5..1a155f18 100644
--- a/src/slskd/Core/Data/Migrations/Z2025_04_01_TransferStateMigration.cs
+++ b/src/slskd/Core/Data/Migrations/Z2025_04_01_TransferStateMigration.cs
@@ -69,7 +69,10 @@ public class Z2025_04_01_TransferStateMigration : IMigration
var schema = SchemaInspector.GetDatabaseSchema(ConnectionString);
var txfers = schema["Transfers"];
+#pragma warning disable CS0618 // Type or member is obsolete
return !txfers.Any(c => c.Name == nameof(Transfer.StateDescription));
+#pragma warning restore CS0618 // Type or member is obsolete
+
}
public void Apply()
diff --git a/src/slskd/Transfers/API/DTO/QueueDownloadBatchRequest.cs b/src/slskd/Transfers/API/DTO/QueueDownloadBatchRequest.cs
index 05a913bd..77f7e7a9 100644
--- a/src/slskd/Transfers/API/DTO/QueueDownloadBatchRequest.cs
+++ b/src/slskd/Transfers/API/DTO/QueueDownloadBatchRequest.cs
@@ -37,6 +37,9 @@ using slskd.Validation;
namespace slskd.Transfers.API;
+/// <summary>
+/// Enqueue a batch of downloads.
+/// </summary>
public record QueueDownloadBatchRequest
{
/// <summary>
@@ -75,6 +78,9 @@ public record QueueDownloadBatchRequest
public EnqueueDownloadBatchOptions Options { get; init; } = new();
}
+/// <summary>
+/// An item in a download batch.
+/// </summary>
public record EnqueueDownloadBatchItem
{
/// <summary>
@@ -88,10 +94,14 @@ public record EnqueueDownloadBatchItem
/// <summary>
/// The file size.
/// </summary>
+ [Required]
[Range(0, long.MaxValue)]
- public long Size { get; init; }
+ public long? Size { get; init; }
}
+/// <summary>
+/// Download batch options.
+/// </summary>
public record EnqueueDownloadBatchOptions
{
/// <summary>
@@ -99,5 +109,6 @@ public record EnqueueDownloadBatchOptions
/// </summary>
[RelativePath]
[NonTraversingPath]
+ [MinLength(1)]
public string Destination { get; init; }
} \ No newline at end of file
diff --git a/src/slskd/Transfers/API/DTO/Transfer.cs b/src/slskd/Transfers/API/DTO/Transfer.cs
deleted file mode 100644
index 949f15d4..00000000
--- a/src/slskd/Transfers/API/DTO/Transfer.cs
+++ /dev/null
@@ -1,169 +0,0 @@
-// <copyright file="Transfer.cs" company="JP Dillingham">
-// ▄▄▄▄ ▄▄▄▄ ▄▄▄▄
-// ▄▄▄▄▄▄█ █▄▄▄▄▄█ █▄▄▄▄▄█ █
-// █__ --█ █__ --█ ◄█ - █
-// █▄▄▄▄▄█▄▄█▄▄▄▄▄█▄▄█▄▄█▄▄▄▄▄█
-// ┍━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ ━━━━ ━ ━┉ ┉ ┉
-// │ Copyright (c) JP Dillingham.
-// │
-// │ 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, version 3.
-// │
-// │ 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/.
-// │
-// │ This program is distributed with Additional Terms pursuant to Section 7
-// │ of the AGPLv3. See the LICENSE file in the root directory of this
-// │ project for the complete terms and conditions.
-// │
-// │ https://slskd.org
-// │
-// ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌ ╌ ╌╌╌╌ ╌
-// │ SPDX-FileCopyrightText: JP Dillingham
-// │ SPDX-License-Identifier: AGPL-3.0-only
-// ╰───────────────────────────────────────────╶──── ─ ─── ─ ── ──┈ ┈
-// </copyright>
-
-namespace slskd.Transfers.API
-{
- using System;
- using System.Net;
- using Soulseek;
-
- /// <summary>
- /// A single file transfer.
- /// </summary>
- public class Transfer
- {
- /// <summary>
- /// Gets the current average transfer speed.
- /// </summary>
- public double AverageSpeed { get; set; }
-
- /// <summary>
- /// Gets the number of remaining bytes to be transferred.
- /// </summary>
- public long BytesRemaining { get; set; }
-
- /// <summary>
- /// Gets the total number of bytes transferred.
- /// </summary>
- public long BytesTransferred { get; set; }
-
- /// <summary>
- /// Gets the transfer direction.
- /// </summary>
- public TransferDirection Direction { get; set; }
-
- /// <summary>
- /// Gets the current duration of the transfer, if it has been started.
- /// </summary>
- public double? ElapsedTime { get; set; }
-
- /// <summary>
- /// Gets the UTC time at which the transfer transitioned into the <see cref="TransferStates.Completed"/> state.
- /// </summary>
- public DateTime? EndTime { get; set; }
-
- /// <summary>
- /// Gets the filename of the file to be transferred.
- /// </summary>
- public string Filename { get; set; }
-
- /// <summary>
- /// Gets the transfer id.
- /// </summary>
- public string Id => Compute.Sha1Hash(Filename);
-
- /// <summary>
- /// Gets the ip endpoint of the remote transfer connection, if one has been established.
- /// </summary>
- public IPEndPoint IPEndPoint { get; set; }
-
- /// <summary>
- /// Gets the current progress in percent.
- /// </summary>
- public double PercentComplete { get; set; }
-
- /// <summary>
- /// Gets the current place in queue, if it has been fetched.
- /// </summary>
- public int? PlaceInQueue { get; set; }
-
- /// <summary>
- /// Gets the projected remaining duration of the transfer.
- /// </summary>
- public double? RemainingTime { get; set; }
-
- /// <summary>
- /// Gets the remote unique token for the transfer.
- /// </summary>
- public int? RemoteToken { get; set; }
-
- /// <summary>
- /// Gets the size of the file to be transferred, in bytes.
- /// </summary>
- public long Size { get; set; }
-
- /// <summary>
- /// Gets the starting offset of the transfer, in bytes.
- /// </summary>
- public long StartOffset { get; set; }
-
- /// <summary>
- /// Gets the UTC time at which the transfer transitioned into the <see cref="TransferStates.InProgress"/> state.
- /// </summary>
- public DateTime? StartTime { get; set; }
-
- /// <summary>
- /// Gets the state of the transfer.
- /// </summary>
- public TransferStates State { get; set; }
-
- /// <summary>
- /// Gets the unique token for the transfer.
- /// </summary>
- public int Token { get; set; }
-
- /// <summary>
- /// Gets the username of the peer to or from which the file is to be transferred.
- /// </summary>
- public string Username { get; set; }
-
- /// <summary>
- /// Gets the Exception that caused the failure of the transfer, if applicable.
- /// </summary>
- public string Exception { get; set; }
-
- public static Transfer FromSoulseekTransfer(Soulseek.Transfer transfer)
- {
- return new Transfer()
- {
- AverageSpeed = transfer.AverageSpeed,
- BytesRemaining = transfer.BytesRemaining,
- BytesTransferred = transfer.BytesTransferred,
- Direction = transfer.Direction,
- ElapsedTime = transfer.ElapsedTime?.TotalMilliseconds,
- EndTime = transfer.EndTime,
- Filename = transfer.Filename,
- IPEndPoint = transfer.IPEndPoint,
- PercentComplete = transfer.PercentComplete,
- RemainingTime = transfer.RemainingTime?.TotalMilliseconds,
- RemoteToken = transfer.RemoteToken,
- Size = transfer.Size,
- StartOffset = transfer.StartOffset,
- StartTime = transfer.StartTime,
- State = transfer.State,
- Token = transfer.Token,
- Username = transfer.Username,
- Exception = transfer.Exception?.Message,
- };
- }
- }
-} \ No newline at end of file
diff --git a/src/slskd/Transfers/TransfersDbContext.cs b/src/slskd/Transfers/TransfersDbContext.cs
index 13d0984d..b25e7663 100644
--- a/src/slskd/Transfers/TransfersDbContext.cs
+++ b/src/slskd/Transfers/TransfersDbContext.cs
@@ -50,11 +50,17 @@ namespace slskd.Transfers
public override int SaveChanges(bool acceptAllChangesOnSuccess)
{
// this is absolutely NOT IDEAL and will accellerate the move away from EF
+ // we have to do this to store both the integer and the string value in the database
+ // well, we don't *HAVE* to, but storing the string allows external apps to understand transfer history
+ // and not need to work out the flags. storing the integer allows us to use bitwise operations in queries,
+ // which is the main driver for this.
foreach (var entry in ChangeTracker.Entries<Transfer>())
{
if (entry.State == EntityState.Added || entry.State == EntityState.Modified)
{
+#pragma warning disable CS0618 // Type or member is obsolete
entry.Entity.StateDescription = entry.Entity.State.ToString();
+#pragma warning restore CS0618 // Type or member is obsolete
}
}
diff --git a/src/slskd/Transfers/Types/Transfer.cs b/src/slskd/Transfers/Types/Transfer.cs
index 8d1afa25..d33a5efc 100644
--- a/src/slskd/Transfers/Types/Transfer.cs
+++ b/src/slskd/Transfers/Types/Transfer.cs
@@ -90,6 +90,8 @@ public class Transfer
/// and especially **DO NOT** set the value. The getter and setter can't be protected because
/// EF Core needs them to be public.
/// </remarks>
+ [Obsolete("Use State isntead; this is a hack for EF")]
+ [JsonIgnore]
public string StateDescription { get; set; }
/// <summary>
@@ -160,7 +162,6 @@ public class Transfer
/// <summary>
/// Gets or sets a value indicating whether the Transfer has been removed from the UI.
/// </summary>
- [JsonIgnore]
public bool Removed { get; set; }
[NotMapped]