aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Transfers/Types
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-08-07 16:07:05 -0500
committerGitHub <noreply@github.com>2022-08-07 16:07:05 -0500
commit4ba81ad7d51cdbe2a1bb9fb055f7d941c6061876 (patch)
treedd8ea1392c4f61defc67b6436ee58be689b3991b /src/slskd/Transfers/Types
parent25c4abfc9428272eed0936d17c8a310653b21111 (diff)
parent80ecb0d03cf1da83e33dde6326365713b3d605e0 (diff)
downloadslskd-4ba81ad7d51cdbe2a1bb9fb055f7d941c6061876.tar.gz
Merge pull request #569 from slskd/transfers
Store transfers in a database (as opposed to in-memory)
Diffstat (limited to 'src/slskd/Transfers/Types')
-rw-r--r--src/slskd/Transfers/Types/Transfer.cs59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/slskd/Transfers/Types/Transfer.cs b/src/slskd/Transfers/Types/Transfer.cs
new file mode 100644
index 00000000..c55826d4
--- /dev/null
+++ b/src/slskd/Transfers/Types/Transfer.cs
@@ -0,0 +1,59 @@
+// <copyright file="Transfer.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
+{
+ using System;
+ using System.ComponentModel.DataAnnotations;
+ using System.ComponentModel.DataAnnotations.Schema;
+ using System.Text.Json.Serialization;
+ using Soulseek;
+
+ public class Transfer
+ {
+ [Key]
+ public Guid Id { get; init; }
+ public string Username { get; init; }
+ public TransferDirection Direction { get; init; }
+ public string Filename { get; init; }
+ public long Size { get; set; }
+ public long StartOffset { get; init; }
+
+ public TransferStates State { get; set; }
+ public DateTime RequestedAt { get; set; }
+ public DateTime? EnqueuedAt { get; set; }
+ public DateTime? StartedAt { get; set; }
+ public DateTime? EndedAt { get; set; }
+ public long BytesTransferred { get; set; }
+ public double AverageSpeed { get; set; }
+
+ public int? PlaceInQueue { get; set; }
+ public string Exception { get; set; }
+
+ [JsonIgnore]
+ public bool Removed { get; set; }
+
+ [NotMapped]
+ public long BytesRemaining => Size - BytesTransferred;
+ [NotMapped]
+ public TimeSpan? ElapsedTime => StartedAt == null ? null : (EndedAt ?? DateTime.UtcNow) - StartedAt.Value;
+ [NotMapped]
+ public double PercentComplete => Size == 0 ? 0 : (BytesTransferred / (double)Size) * 100;
+ [NotMapped]
+ public TimeSpan? RemainingTime => AverageSpeed == 0 ? null : TimeSpan.FromSeconds(BytesRemaining / AverageSpeed);
+ }
+} \ No newline at end of file