Usenet streaming with a WebDAV server and a SABnzbd-compatible API
C#
Added DavMultipartFiles table.
nzbdav-devb13caecbe0f6
diff --git a/backend/Api/Controllers/GetHealthCheckQueue/GetHealthCheckQueueController.cs b/backend/Api/Controllers/GetHealthCheckQueue/GetHealthCheckQueueController.csindex 3a7f88fd..f73dd1bf 100644--- a/backend/Api/Controllers/GetHealthCheckQueue/GetHealthCheckQueueController.cs+++ b/backend/Api/Controllers/GetHealthCheckQueue/GetHealthCheckQueueController.cs@@ -17,7 +17,9 @@ public class GetHealthCheckQueueController(DavDatabaseClient dbClient) : BaseApi.ToListAsync();var uncheckedCount = await dbClient.Ctx.Items- .Where(x => x.Type == DavItem.ItemType.NzbFile || x.Type == DavItem.ItemType.RarFile)+ .Where(x => x.Type == DavItem.ItemType.NzbFile+ || x.Type == DavItem.ItemType.RarFile+ || x.Type == DavItem.ItemType.MultipartFile).Where(x => x.NextHealthCheck == null).CountAsync();diff --git a/backend/Database/DavDatabaseClient.cs b/backend/Database/DavDatabaseClient.csindex 06b6274a..dc2d76e3 100644--- a/backend/Database/DavDatabaseClient.cs+++ b/backend/Database/DavDatabaseClient.cs@@ -18,7 +18,9 @@ public sealed class DavDatabaseClient(DavDatabaseContext ctx){return ctx.Items.Where(i => i.IdPrefix == prefix)- .Where(i => i.Type == DavItem.ItemType.NzbFile || i.Type == DavItem.ItemType.RarFile)+ .Where(i => i.Type == DavItem.ItemType.NzbFile+ || i.Type == DavItem.ItemType.RarFile+ || i.Type == DavItem.ItemType.MultipartFile).ToListAsync();}diff --git a/backend/Database/DavDatabaseContext.cs b/backend/Database/DavDatabaseContext.csindex 70d3174b..32fa05eb 100644--- a/backend/Database/DavDatabaseContext.cs+++ b/backend/Database/DavDatabaseContext.cs@@ -23,6 +23,7 @@ public sealed class DavDatabaseContext() : DbContext(Options.Value)public DbSet<DavItem> Items => Set<DavItem>();public DbSet<DavNzbFile> NzbFiles => Set<DavNzbFile>();public DbSet<DavRarFile> RarFiles => Set<DavRarFile>();+ public DbSet<DavMultipartFile> MultipartFiles => Set<DavMultipartFile>();public DbSet<QueueItem> QueueItems => Set<QueueItem>();public DbSet<HistoryItem> HistoryItems => Set<HistoryItem>();public DbSet<HealthCheckResult> HealthCheckResults => Set<HealthCheckResult>();@@ -162,6 +163,31 @@ public sealed class DavDatabaseContext() : DbContext(Options.Value).OnDelete(DeleteBehavior.Cascade);});+ // DavMultipartFile+ b.Entity<DavMultipartFile>(e =>+ {+ e.ToTable("DavMultipartFiles");+ e.HasKey(f => f.Id);++ e.Property(i => i.Id)+ .ValueGeneratedNever();++ e.Property(f => f.Metadata)+ .HasConversion(new ValueConverter<DavMultipartFile.Meta, string>+ (+ v => JsonSerializer.Serialize(v, (JsonSerializerOptions?)null),+ v => JsonSerializer.Deserialize<DavMultipartFile.Meta>(v, (JsonSerializerOptions?)null) ??+ new DavMultipartFile.Meta()+ ))+ .HasColumnType("TEXT") // store raw JSON+ .IsRequired();++ e.HasOne(f => f.DavItem)+ .WithOne()+ .HasForeignKey<DavMultipartFile>(f => f.Id)+ .OnDelete(DeleteBehavior.Cascade);+ });+// QueueItemb.Entity<QueueItem>(e =>{diff --git a/backend/Database/Migrations/20251024003729_Add-DavMultipartFiles-Table.Designer.cs b/backend/Database/Migrations/20251024003729_Add-DavMultipartFiles-Table.Designer.csnew file mode 100644index 00000000..2a805870--- /dev/null+++ b/backend/Database/Migrations/20251024003729_Add-DavMultipartFiles-Table.Designer.cs@@ -0,0 +1,341 @@+// <auto-generated />+using System;+using Microsoft.EntityFrameworkCore;+using Microsoft.EntityFrameworkCore.Infrastructure;+using Microsoft.EntityFrameworkCore.Migrations;+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;+using NzbWebDAV.Database;++#nullable disable++namespace NzbWebDAV.Database.Migrations+{+ [DbContext(typeof(DavDatabaseContext))]+ [Migration("20251024003729_Add-DavMultipartFiles-Table")]+ partial class AddDavMultipartFilesTable+ {+ /// <inheritdoc />+ protected override void BuildTargetModel(ModelBuilder modelBuilder)+ {+#pragma warning disable 612, 618+ modelBuilder.HasAnnotation("ProductVersion", "9.0.4");++ modelBuilder.Entity("NzbWebDAV.Database.Models.Account", b =>+ {+ b.Property<int>("Type")+ .HasColumnType("INTEGER");++ b.Property<string>("Username")+ .HasMaxLength(255)+ .HasColumnType("TEXT");++ b.Property<string>("PasswordHash")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<string>("RandomSalt")+ .IsRequired()+ .HasColumnType("TEXT");++ b.HasKey("Type", "Username");++ b.ToTable("Accounts", (string)null);+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.ConfigItem", b =>+ {+ b.Property<string>("ConfigName")+ .HasColumnType("TEXT");++ b.Property<string>("ConfigValue")+ .IsRequired()+ .HasColumnType("TEXT");++ b.HasKey("ConfigName");++ b.ToTable("ConfigItems", (string)null);+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.DavItem", b =>+ {+ b.Property<Guid>("Id")+ .HasColumnType("TEXT");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("TEXT");++ b.Property<long?>("FileSize")+ .HasColumnType("INTEGER");++ b.Property<string>("IdPrefix")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<long?>("LastHealthCheck")+ .HasColumnType("INTEGER");++ b.Property<string>("Name")+ .IsRequired()+ .HasMaxLength(255)+ .HasColumnType("TEXT");++ b.Property<long?>("NextHealthCheck")+ .HasColumnType("INTEGER");++ b.Property<Guid?>("ParentId")+ .HasColumnType("TEXT");++ b.Property<string>("Path")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<long?>("ReleaseDate")+ .HasColumnType("INTEGER");++ b.Property<int>("Type")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("IdPrefix", "Type");++ b.HasIndex("ParentId", "Name")+ .IsUnique();++ b.HasIndex("Type", "NextHealthCheck", "ReleaseDate", "Id");++ b.ToTable("DavItems", (string)null);+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.DavMultipartFile", b =>+ {+ b.Property<Guid>("Id")+ .HasColumnType("TEXT");++ b.Property<string>("Metadata")+ .IsRequired()+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.ToTable("DavMultipartFiles", (string)null);+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.DavNzbFile", b =>+ {+ b.Property<Guid>("Id")+ .HasColumnType("TEXT");++ b.Property<string>("SegmentIds")+ .IsRequired()+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.ToTable("DavNzbFiles", (string)null);+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.DavRarFile", b =>+ {+ b.Property<Guid>("Id")+ .HasColumnType("TEXT");++ b.Property<string>("RarParts")+ .IsRequired()+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.ToTable("DavRarFiles", (string)null);+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.HealthCheckResult", b =>+ {+ b.Property<Guid>("Id")+ .HasColumnType("TEXT");++ b.Property<long>("CreatedAt")+ .HasColumnType("INTEGER");++ b.Property<Guid>("DavItemId")+ .HasColumnType("TEXT");++ b.Property<string>("Message")+ .HasColumnType("TEXT");++ b.Property<string>("Path")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<int>("RepairStatus")+ .HasColumnType("INTEGER");++ b.Property<int>("Result")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("DavItemId")+ .HasFilter("\"RepairStatus\" = 3");++ b.HasIndex("Result", "RepairStatus", "CreatedAt");++ b.ToTable("HealthCheckResults", (string)null);+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.HistoryItem", b =>+ {+ b.Property<Guid>("Id")+ .HasColumnType("TEXT");++ b.Property<string>("Category")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("TEXT");++ b.Property<Guid?>("DownloadDirId")+ .HasColumnType("TEXT");++ b.Property<int>("DownloadStatus")+ .HasColumnType("INTEGER");++ b.Property<int>("DownloadTimeSeconds")+ .HasColumnType("INTEGER");++ b.Property<string>("FailMessage")+ .HasColumnType("TEXT");++ b.Property<string>("FileName")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<string>("JobName")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<long>("TotalSegmentBytes")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("Category");++ b.HasIndex("CreatedAt");++ b.HasIndex("Category", "CreatedAt");++ b.HasIndex("Category", "DownloadDirId");++ b.ToTable("HistoryItems", (string)null);+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.QueueItem", b =>+ {+ b.Property<Guid>("Id")+ .HasColumnType("TEXT");++ b.Property<string>("Category")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<DateTime>("CreatedAt")+ .HasColumnType("TEXT");++ b.Property<string>("FileName")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<string>("JobName")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<string>("NzbContents")+ .IsRequired()+ .HasColumnType("TEXT");++ b.Property<long>("NzbFileSize")+ .HasColumnType("INTEGER");++ b.Property<DateTime?>("PauseUntil")+ .HasColumnType("TEXT");++ b.Property<int>("PostProcessing")+ .HasColumnType("INTEGER");++ b.Property<int>("Priority")+ .HasColumnType("INTEGER");++ b.Property<long>("TotalSegmentBytes")+ .HasColumnType("INTEGER");++ b.HasKey("Id");++ b.HasIndex("Category");++ b.HasIndex("CreatedAt");++ b.HasIndex("FileName")+ .IsUnique();++ b.HasIndex("Priority");++ b.HasIndex("Priority", "CreatedAt");++ b.HasIndex("Category", "Priority", "CreatedAt");++ b.ToTable("QueueItems", (string)null);+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.DavItem", b =>+ {+ b.HasOne("NzbWebDAV.Database.Models.DavItem", "Parent")+ .WithMany("Children")+ .HasForeignKey("ParentId")+ .OnDelete(DeleteBehavior.Cascade);++ b.Navigation("Parent");+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.DavMultipartFile", b =>+ {+ b.HasOne("NzbWebDAV.Database.Models.DavItem", "DavItem")+ .WithOne()+ .HasForeignKey("NzbWebDAV.Database.Models.DavMultipartFile", "Id")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("DavItem");+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.DavNzbFile", b =>+ {+ b.HasOne("NzbWebDAV.Database.Models.DavItem", "DavItem")+ .WithOne()+ .HasForeignKey("NzbWebDAV.Database.Models.DavNzbFile", "Id")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("DavItem");+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.DavRarFile", b =>+ {+ b.HasOne("NzbWebDAV.Database.Models.DavItem", "DavItem")+ .WithOne()+ .HasForeignKey("NzbWebDAV.Database.Models.DavRarFile", "Id")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("DavItem");+ });++ modelBuilder.Entity("NzbWebDAV.Database.Models.DavItem", b =>+ {+ b.Navigation("Children");+ });+#pragma warning restore 612, 618+ }+ }+}diff --git a/backend/Database/Migrations/20251024003729_Add-DavMultipartFiles-Table.cs b/backend/Database/Migrations/20251024003729_Add-DavMultipartFiles-Table.csnew file mode 100644index 00000000..3ef7f0aa--- /dev/null+++ b/backend/Database/Migrations/20251024003729_Add-DavMultipartFiles-Table.cs@@ -0,0 +1,40 @@+using System;+using Microsoft.EntityFrameworkCore.Migrations;++#nullable disable++namespace NzbWebDAV.Database.Migrations+{+ /// <inheritdoc />+ public partial class AddDavMultipartFilesTable : Migration+ {+ /// <inheritdoc />+ protected override void Up(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.CreateTable(+ name: "DavMultipartFiles",+ columns: table => new+ {+ Id = table.Column<Guid>(type: "TEXT", nullable: false),+ Metadata = table.Column<string>(type: "TEXT", nullable: false)+ },+ constraints: table =>+ {+ table.PrimaryKey("PK_DavMultipartFiles", x => x.Id);+ table.ForeignKey(+ name: "FK_DavMultipartFiles_DavItems_Id",+ column: x => x.Id,+ principalTable: "DavItems",+ principalColumn: "Id",+ onDelete: ReferentialAction.Cascade);+ });+ }++ /// <inheritdoc />+ protected override void Down(MigrationBuilder migrationBuilder)+ {+ migrationBuilder.DropTable(+ name: "DavMultipartFiles");+ }+ }+}diff --git a/backend/Database/Migrations/DavDatabaseContextModelSnapshot.cs b/backend/Database/Migrations/DavDatabaseContextModelSnapshot.csindex 7e82c7c7..ef2015d7 100644--- a/backend/Database/Migrations/DavDatabaseContextModelSnapshot.cs+++ b/backend/Database/Migrations/DavDatabaseContextModelSnapshot.cs@@ -104,6 +104,20 @@ namespace NzbWebDAV.Database.Migrationsb.ToTable("DavItems", (string)null);});+ modelBuilder.Entity("NzbWebDAV.Database.Models.DavMultipartFile", b =>+ {+ b.Property<Guid>("Id")+ .HasColumnType("TEXT");++ b.Property<string>("Metadata")+ .IsRequired()+ .HasColumnType("TEXT");++ b.HasKey("Id");++ b.ToTable("DavMultipartFiles", (string)null);+ });+modelBuilder.Entity("NzbWebDAV.Database.Models.DavNzbFile", b =>{b.Property<Guid>("Id")@@ -281,6 +295,17 @@ namespace NzbWebDAV.Database.Migrationsb.Navigation("Parent");});+ modelBuilder.Entity("NzbWebDAV.Database.Models.DavMultipartFile", b =>+ {+ b.HasOne("NzbWebDAV.Database.Models.DavItem", "DavItem")+ .WithOne()+ .HasForeignKey("NzbWebDAV.Database.Models.DavMultipartFile", "Id")+ .OnDelete(DeleteBehavior.Cascade)+ .IsRequired();++ b.Navigation("DavItem");+ });+modelBuilder.Entity("NzbWebDAV.Database.Models.DavNzbFile", b =>{b.HasOne("NzbWebDAV.Database.Models.DavItem", "DavItem")diff --git a/backend/Database/Models/DavItem.cs b/backend/Database/Models/DavItem.csindex 3ad83b89..fbb4ed03 100644--- a/backend/Database/Models/DavItem.cs+++ b/backend/Database/Models/DavItem.cs@@ -56,6 +56,7 @@ public class DavItemNzbFile = 3,RarFile = 4,IdsRoot = 5,+ MultipartFile = 6,}// navigation helpersdiff --git a/backend/Database/Models/DavMultipartFile.cs b/backend/Database/Models/DavMultipartFile.csnew file mode 100644index 00000000..ee90ad31--- /dev/null+++ b/backend/Database/Models/DavMultipartFile.cs@@ -0,0 +1,30 @@+using NzbWebDAV.Models;++namespace NzbWebDAV.Database.Models;++public class DavMultipartFile+{+ public Guid Id { get; set; } // foreign key to DavItem.Id+ public Meta Metadata { get; set; }++ // navigation helpers+ public DavItem? DavItem { get; set; }++ public class Meta+ {+ public FilePart[] FileParts { get; set; } = [];+ }++ public class FilePart+ {+ // a subsequence of segments from an NzbFile+ public string[] SegmentIds { get; set; } = [];++ // what byte range is contained within the segmentIds? (relative to the full NzbFile)+ public LongRange SegmentIdByteRange { get; set; }++ // what byte range contains the file part contents? (relative to the full NzbFile)+ // note: this range should always be fully contained within the SegmentIdByteRange above.+ public LongRange FilePartByteRange { get; set; }+ }+}\ No newline at end of filediff --git a/backend/Database/Models/DavRarFile.cs b/backend/Database/Models/DavRarFile.csindex 8f2220f3..7b89440b 100644--- a/backend/Database/Models/DavRarFile.cs+++ b/backend/Database/Models/DavRarFile.cs@@ -1,4 +1,6 @@-namespace NzbWebDAV.Database.Models;+using NzbWebDAV.Models;++namespace NzbWebDAV.Database.Models;public class DavRarFile{@@ -15,4 +17,17 @@ public class DavRarFilepublic long Offset { get; set; }public long ByteCount { get; set; }}++ public DavMultipartFile.Meta ToDavMultipartFileMeta()+ {+ return new DavMultipartFile.Meta+ {+ FileParts = RarParts.Select(x => new DavMultipartFile.FilePart()+ {+ SegmentIds = x.SegmentIds,+ SegmentIdByteRange = LongRange.FromStartAndSize(0, x.PartSize),+ FilePartByteRange = LongRange.FromStartAndSize(x.Offset, x.ByteCount),+ }).ToArray()+ };+ }}\ No newline at end of filediff --git a/backend/Queue/FileAggregators/MultipartMkvAggregator.cs b/backend/Queue/FileAggregators/MultipartMkvAggregator.csindex e3b7cb06..0861388a 100644--- a/backend/Queue/FileAggregators/MultipartMkvAggregator.cs+++ b/backend/Queue/FileAggregators/MultipartMkvAggregator.cs@@ -35,20 +35,23 @@ public class MultipartMkvAggregatorid: Guid.NewGuid(),parent: parentDirectory,name: name,- fileSize: fileParts.Sum(x => x.ByteCount),- type: DavItem.ItemType.RarFile,+ fileSize: fileParts.Sum(x => x.FilePartByteRange.Count),+ type: DavItem.ItemType.MultipartFile,releaseDate: multipartMkvFile.ReleaseDate,lastHealthCheck: checkedFullHealth ? DateTimeOffset.UtcNow : null);- var davRarFile = new DavRarFile()+ var davMultipartFile = new DavMultipartFile(){Id = davItem.Id,- RarParts = fileParts.ToArray(),+ Metadata = new DavMultipartFile.Meta()+ {+ FileParts = fileParts.ToArray()+ }};dbClient.Ctx.Items.Add(davItem);- dbClient.Ctx.RarFiles.Add(davRarFile);+ dbClient.Ctx.MultipartFiles.Add(davMultipartFile);}}}\ No newline at end of filediff --git a/backend/Queue/FileAggregators/RarAggregator.cs b/backend/Queue/FileAggregators/RarAggregator.csindex 60a208eb..48bf1c97 100644--- a/backend/Queue/FileAggregators/RarAggregator.cs+++ b/backend/Queue/FileAggregators/RarAggregator.cs@@ -1,6 +1,7 @@using NzbWebDAV.Database;using NzbWebDAV.Database.Models;using NzbWebDAV.Extensions;+using NzbWebDAV.Models;using NzbWebDAV.Queue.FileProcessors;using NzbWebDAV.Utils;@@ -23,7 +24,7 @@ public class RarAggregator(DavDatabaseClient dbClient, DavItem mountDirectory, bprivate void ProcessArchive(List<RarProcessor.Result> archiveParts){- var archiveFiles = new Dictionary<string, List<DavRarFile.RarPart>>();+ var archiveFiles = new Dictionary<string, List<DavMultipartFile.FilePart>>();foreach (var archivePart in archiveParts){foreach (var fileSegment in archivePart.StoredFileSegments)@@ -31,12 +32,11 @@ public class RarAggregator(DavDatabaseClient dbClient, DavItem mountDirectory, bif (!archiveFiles.ContainsKey(fileSegment.PathWithinArchive))archiveFiles.Add(fileSegment.PathWithinArchive, []);- archiveFiles[fileSegment.PathWithinArchive].Add(new DavRarFile.RarPart()+ archiveFiles[fileSegment.PathWithinArchive].Add(new DavMultipartFile.FilePart(){SegmentIds = archivePart.NzbFile.GetSegmentIds(),- PartSize = archivePart.PartSize,- Offset = fileSegment.Offset,- ByteCount = fileSegment.ByteCount,+ SegmentIdByteRange = LongRange.FromStartAndSize(0, archivePart.PartSize),+ FilePartByteRange = LongRange.FromStartAndSize(fileSegment.Offset, fileSegment.ByteCount),});}}@@ -44,7 +44,7 @@ public class RarAggregator(DavDatabaseClient dbClient, DavItem mountDirectory, bforeach (var archiveFile in archiveFiles){var pathWithinArchive = archiveFile.Key;- var rarParts = archiveFile.Value.ToArray();+ var fileParts = archiveFile.Value.ToArray();var parentDirectory = EnsureExtractPath(pathWithinArchive);var name = Path.GetFileName(pathWithinArchive);@@ -57,20 +57,23 @@ public class RarAggregator(DavDatabaseClient dbClient, DavItem mountDirectory, bid: Guid.NewGuid(),parent: parentDirectory,name: name,- fileSize: rarParts.Sum(x => x.ByteCount),- type: DavItem.ItemType.RarFile,+ fileSize: fileParts.Sum(x => x.FilePartByteRange.Count),+ type: DavItem.ItemType.MultipartFile,releaseDate: archiveParts.First().ReleaseDate,lastHealthCheck: checkedFullHealth ? DateTimeOffset.UtcNow : null);- var davRarFile = new DavRarFile()+ var davMultipartFile = new DavMultipartFile(){Id = davItem.Id,- RarParts = rarParts,+ Metadata = new DavMultipartFile.Meta()+ {+ FileParts = fileParts,+ }};dbClient.Ctx.Items.Add(davItem);- dbClient.Ctx.RarFiles.Add(davRarFile);+ dbClient.Ctx.MultipartFiles.Add(davMultipartFile);}}}\ No newline at end of filediff --git a/backend/Queue/FileAggregators/SevenZipAggregator.cs b/backend/Queue/FileAggregators/SevenZipAggregator.csindex 8ae23739..35c02b9e 100644--- a/backend/Queue/FileAggregators/SevenZipAggregator.cs+++ b/backend/Queue/FileAggregators/SevenZipAggregator.cs@@ -5,8 +5,7 @@ using NzbWebDAV.Utils;namespace NzbWebDAV.Queue.FileAggregators;-public class SevenZipAggregator-(+public class SevenZipAggregator(DavDatabaseClient dbClient,DavItem mountDirectory,bool checkedFullHealth@@ -43,20 +42,23 @@ public class SevenZipAggregatorid: Guid.NewGuid(),parent: parentDirectory,name: name,- fileSize: sevenZipParts.Sum(x => x.ByteCount),- type: DavItem.ItemType.RarFile,+ fileSize: sevenZipParts.Sum(x => x.FilePartByteRange.Count),+ type: DavItem.ItemType.MultipartFile,releaseDate: sevenZipFile.ReleaseDate,lastHealthCheck: checkedFullHealth ? DateTimeOffset.UtcNow : null);- var davRarFile = new DavRarFile()+ var davMultipartFile = new DavMultipartFile(){Id = davItem.Id,- RarParts = sevenZipParts.ToArray(),+ Metadata = new DavMultipartFile.Meta()+ {+ FileParts = sevenZipParts.ToArray()+ }};dbClient.Ctx.Items.Add(davItem);- dbClient.Ctx.RarFiles.Add(davRarFile);+ dbClient.Ctx.MultipartFiles.Add(davMultipartFile);}}}\ No newline at end of filediff --git a/backend/Queue/FileProcessors/MultipartMkvProcessor.cs b/backend/Queue/FileProcessors/MultipartMkvProcessor.csindex f4166dfd..b71deead 100644--- a/backend/Queue/FileProcessors/MultipartMkvProcessor.cs+++ b/backend/Queue/FileProcessors/MultipartMkvProcessor.cs@@ -2,6 +2,7 @@using NzbWebDAV.Clients.Usenet;using NzbWebDAV.Database.Models;using NzbWebDAV.Extensions;+using NzbWebDAV.Models;using NzbWebDAV.Queue.DeobfuscationSteps._3.GetFileInfos;namespace NzbWebDAV.Queue.FileProcessors;@@ -27,16 +28,15 @@ public class MultipartMkvProcessor : BaseProcessorpublic override async Task<BaseProcessor.Result?> ProcessAsync(){var sortedFileInfos = _fileInfos.OrderBy(f => GetPartNumber(f.FileName)).ToList();- var fileParts = new List<DavRarFile.RarPart>();+ var fileParts = new List<DavMultipartFile.FilePart>();foreach (var fileInfo in sortedFileInfos){var partSize = fileInfo.FileSize ?? await _client.GetFileSizeAsync(fileInfo.NzbFile, _ct);- fileParts.Add(new DavRarFile.RarPart+ fileParts.Add(new DavMultipartFile.FilePart{SegmentIds = fileInfo.NzbFile.GetSegmentIds(),- PartSize = partSize,- Offset = 0,- ByteCount = partSize+ SegmentIdByteRange = LongRange.FromStartAndSize(0, partSize),+ FilePartByteRange = LongRange.FromStartAndSize(0, partSize),});}@@ -63,7 +63,7 @@ public class MultipartMkvProcessor : BaseProcessorpublic new class Result : BaseProcessor.Result{public required string Filename { get; init; }- public required List<DavRarFile.RarPart> Parts { get; init; } = [];+ public required List<DavMultipartFile.FilePart> Parts { get; init; } = [];public required DateTimeOffset ReleaseDate { get; init; }}}\ No newline at end of filediff --git a/backend/Queue/FileProcessors/SevenZipProcessor.cs b/backend/Queue/FileProcessors/SevenZipProcessor.csindex 34cac129..8ec5ec09 100644--- a/backend/Queue/FileProcessors/SevenZipProcessor.cs+++ b/backend/Queue/FileProcessors/SevenZipProcessor.cs@@ -78,7 +78,7 @@ public class SevenZipProcessor : BaseProcessorreturn string.IsNullOrEmpty(match.Groups[2].Value) ? -1 : int.Parse(match.Groups[2].Value);}- private List<DavRarFile.RarPart> GetSevenZipParts+ private List<DavMultipartFile.FilePart> GetSevenZipParts(SevenZipUtil.SevenZipEntry sevenZipEntry,MultipartFile multipartFile@@ -112,12 +112,11 @@ public class SevenZipProcessor : BaseProcessor: multipartFile.FileParts[index].PartSize;var partByteCount = partEndExclusive - partStartInclusive;- return new DavRarFile.RarPart()+ return new DavMultipartFile.FilePart(){SegmentIds = multipartFile.FileParts[index].NzbFile.GetSegmentIds(),- PartSize = multipartFile.FileParts[index].PartSize,- Offset = partStartInclusive,- ByteCount = partByteCount+ SegmentIdByteRange = LongRange.FromStartAndSize(0, multipartFile.FileParts[index].PartSize),+ FilePartByteRange = LongRange.FromStartAndSize(partStartInclusive, partByteCount),};}).ToList();@@ -131,7 +130,7 @@ public class SevenZipProcessor : BaseProcessorpublic class SevenZipFile{public required string PathWithinArchive { get; init; }- public required List<DavRarFile.RarPart> Parts { get; init; }+ public required List<DavMultipartFile.FilePart> Parts { get; init; }public required DateTimeOffset ReleaseDate { get; init; }}}\ No newline at end of filediff --git a/backend/Services/HealthCheckService.cs b/backend/Services/HealthCheckService.csindex 02922b43..727c2d14 100644--- a/backend/Services/HealthCheckService.cs+++ b/backend/Services/HealthCheckService.cs@@ -85,7 +85,9 @@ public class HealthCheckServicevar actionNeeded = HealthCheckResult.RepairAction.ActionNeeded;var healthCheckResults = dbClient.Ctx.HealthCheckResults;return dbClient.Ctx.Items- .Where(x => x.Type == DavItem.ItemType.NzbFile || x.Type == DavItem.ItemType.RarFile)+ .Where(x => x.Type == DavItem.ItemType.NzbFile+ || x.Type == DavItem.ItemType.RarFile+ || x.Type == DavItem.ItemType.MultipartFile).Where(x => !healthCheckResults.Any(h => h.DavItemId == x.Id && h.RepairStatus == actionNeeded)).OrderBy(x => x.NextHealthCheck).ThenByDescending(x => x.ReleaseDate)@@ -170,6 +172,14 @@ public class HealthCheckServicereturn rarFile?.RarParts?.SelectMany(x => x.SegmentIds)?.ToList() ?? [];}+ if (davItem.Type == DavItem.ItemType.MultipartFile)+ {+ var multipartFile = await dbClient.Ctx.MultipartFiles+ .Where(x => x.Id == davItem.Id)+ .FirstOrDefaultAsync(ct);+ return multipartFile?.Metadata?.FileParts?.SelectMany(x => x.SegmentIds)?.ToList() ?? [];+ }+return [];}diff --git a/backend/Streams/RarFileStream.cs b/backend/Streams/DavMultipartFileStream.cssimilarity index 74%rename from backend/Streams/RarFileStream.csrename to backend/Streams/DavMultipartFileStream.csindex c3861f1b..38964ee5 100644--- a/backend/Streams/RarFileStream.cs+++ b/backend/Streams/DavMultipartFileStream.cs@@ -4,8 +4,8 @@ using NzbWebDAV.Extensions;namespace NzbWebDAV.Streams;-public class RarFileStream(- DavRarFile.RarPart[] rarParts,+public class DavMultipartFileStream(+ DavMultipartFile.FilePart[] fileParts,UsenetStreamingClient usenet,int concurrentConnections) : Stream@@ -58,7 +58,7 @@ public class RarFileStream(public override bool CanRead => true;public override bool CanSeek => true;public override bool CanWrite => false;- public override long Length { get; } = rarParts.Select(x => x.ByteCount).Sum();+ public override long Length { get; } = fileParts.Select(x => x.FilePartByteRange.Count).Sum();public override long Position{@@ -67,13 +67,13 @@ public class RarFileStream(}- private (int rarPartIndex, long rarPartOffset) SeekRarPart(long byteOffset)+ private (int filePartIndex, long filePartOffset) SeekFilePart(long byteOffset){long offset = 0;- for (var i = 0; i < rarParts.Length; i++)+ for (var i = 0; i < fileParts.Length; i++){- var rarPart = rarParts[i];- var nextOffset = offset + rarPart.ByteCount;+ var filePart = fileParts[i];+ var nextOffset = offset + filePart.FilePartByteRange.Count;if (byteOffset < nextOffset)return (i, offset);offset = nextOffset;@@ -85,20 +85,20 @@ public class RarFileStream(private CombinedStream GetFileStream(long rangeStart, CancellationToken cancellationToken){if (rangeStart == 0) return GetCombinedStream(0, 0, cancellationToken);- var (rarPartIndex, rarPartOffset) = SeekRarPart(rangeStart);- var stream = GetCombinedStream(rarPartIndex, rangeStart - rarPartOffset, cancellationToken);+ var (filePartIndex, filePartOffset) = SeekFilePart(rangeStart);+ var stream = GetCombinedStream(filePartIndex, rangeStart - filePartOffset, cancellationToken);return stream;}- private CombinedStream GetCombinedStream(int firstRarPartIndex, long additionalOffset, CancellationToken ct)+ private CombinedStream GetCombinedStream(int firstFilePartIndex, long additionalOffset, CancellationToken ct){- var streams = rarParts[firstRarPartIndex..]+ var streams = fileParts[firstFilePartIndex..].Select((x, i) =>{var offset = (i == 0) ? additionalOffset : 0;- var stream = usenet.GetFileStream(x.SegmentIds, x.PartSize, concurrentConnections);- stream.Seek(x.Offset + offset, SeekOrigin.Begin);- return Task.FromResult(stream.LimitLength(x.ByteCount - offset));+ var stream = usenet.GetFileStream(x.SegmentIds, x.SegmentIdByteRange.Count, concurrentConnections);+ stream.Seek(x.FilePartByteRange.StartInclusive + offset, SeekOrigin.Begin);+ return Task.FromResult(stream.LimitLength(x.FilePartByteRange.Count - offset));});return new CombinedStream(streams);}diff --git a/backend/Tasks/MigrateLibrarySymlinksTask.cs b/backend/Tasks/MigrateLibrarySymlinksTask.csindex 2386b987..1a222b92 100644--- a/backend/Tasks/MigrateLibrarySymlinksTask.cs+++ b/backend/Tasks/MigrateLibrarySymlinksTask.cs@@ -69,6 +69,7 @@ public class MigrateLibrarySymlinksTask({DatabaseStoreNzbFile nzbFile => nzbFile.DavItem,DatabaseStoreRarFile rarFile => rarFile.DavItem,+ DatabaseStoreMultipartFile multipartFile => multipartFile.DavItem,_ => null};diff --git a/backend/Tasks/RemoveUnlinkedFilesTask.cs b/backend/Tasks/RemoveUnlinkedFilesTask.csindex 8ed0f1b6..36a556e8 100644--- a/backend/Tasks/RemoveUnlinkedFilesTask.cs+++ b/backend/Tasks/RemoveUnlinkedFilesTask.cs@@ -59,7 +59,10 @@ public class RemoveUnlinkedFilesTask(.Where(x => x.CreatedAt < dateThreshold).Where(x => x.Children.All(y => removedItems.Contains(y.Id)));var allUnlinkedFiles = allDavItems- .Where(x => x.Type is DavItem.ItemType.NzbFile or DavItem.ItemType.RarFile)+ .Where(x => x.Type+ is DavItem.ItemType.NzbFile+ or DavItem.ItemType.RarFile+ or DavItem.ItemType.MultipartFile).Where(x => x.CreatedAt < dateThreshold).Where(x => !linkedIds.Contains(x.Id));diff --git a/backend/WebDav/DatabaseStoreCollection.cs b/backend/WebDav/DatabaseStoreCollection.csindex 891acf52..600ddc61 100644--- a/backend/WebDav/DatabaseStoreCollection.cs+++ b/backend/WebDav/DatabaseStoreCollection.cs@@ -61,7 +61,7 @@ public class DatabaseStoreCollection(if (davItem is null) return DavStatusCode.NotFound;// If the item is a file, simply delete it and we're done.- if (davItem.Type is DavItem.ItemType.NzbFile or DavItem.ItemType.RarFile)+ if (davItem.Type is DavItem.ItemType.NzbFile or DavItem.ItemType.RarFile or DavItem.ItemType.MultipartFile){dbClient.Ctx.Items.Remove(davItem);await dbClient.Ctx.SaveChangesAsync();@@ -102,6 +102,9 @@ public class DatabaseStoreCollection(DavItem.ItemType.RarFile =>new DatabaseStoreRarFile(davItem, httpContext, dbClient, usenetClient, configManager),+ DavItem.ItemType.MultipartFile =>+ new DatabaseStoreMultipartFile(+ davItem, httpContext, dbClient, usenetClient, configManager),_ => throw new ArgumentException("Unrecognized directory child type.")};}diff --git a/backend/WebDav/DatabaseStoreIdFile.cs b/backend/WebDav/DatabaseStoreIdFile.csindex 7a2e3544..04febbbe 100644--- a/backend/WebDav/DatabaseStoreIdFile.cs+++ b/backend/WebDav/DatabaseStoreIdFile.cs@@ -34,6 +34,8 @@ public class DatabaseStoreIdFile(new DatabaseStoreNzbFile(davItem, httpContext, dbClient, usenetClient, configManager),DavItem.ItemType.RarFile =>new DatabaseStoreRarFile(davItem, httpContext, dbClient, usenetClient, configManager),+ DavItem.ItemType.MultipartFile =>+ new DatabaseStoreMultipartFile(davItem, httpContext, dbClient, usenetClient, configManager),_ => throw new ArgumentException("Unrecognized id child type.")};}diff --git a/backend/WebDav/DatabaseStoreMultipartFile.cs b/backend/WebDav/DatabaseStoreMultipartFile.csnew file mode 100644index 00000000..26e05503--- /dev/null+++ b/backend/WebDav/DatabaseStoreMultipartFile.cs@@ -0,0 +1,41 @@+using Microsoft.AspNetCore.Http;+using Microsoft.EntityFrameworkCore;+using NzbWebDAV.Clients.Usenet;+using NzbWebDAV.Config;+using NzbWebDAV.Database;+using NzbWebDAV.Database.Models;+using NzbWebDAV.Streams;+using NzbWebDAV.WebDav.Base;++namespace NzbWebDAV.WebDav;++public class DatabaseStoreMultipartFile(+ DavItem davMultipartFile,+ HttpContext httpContext,+ DavDatabaseClient dbClient,+ UsenetStreamingClient usenetClient,+ ConfigManager configManager+) : BaseStoreReadonlyItem+{+ public DavItem DavItem => davMultipartFile;+ public override string Name => davMultipartFile.Name;+ public override string UniqueKey => davMultipartFile.Id.ToString();+ public override long FileSize => davMultipartFile.FileSize!.Value;+ public override DateTime CreatedAt => davMultipartFile.CreatedAt;++ public override async Task<Stream> GetReadableStreamAsync(CancellationToken ct)+ {+ // store the DavItem being accessed in the http context+ httpContext.Items["DavItem"] = davMultipartFile;++ // return the stream+ var id = davMultipartFile.Id;+ var multipartFile = await dbClient.Ctx.MultipartFiles.Where(x => x.Id == id).FirstOrDefaultAsync(ct);+ if (multipartFile is null) throw new FileNotFoundException($"Could not find nzb file with id: {id}");+ return new DavMultipartFileStream(+ multipartFile.Metadata.FileParts,+ usenetClient,+ configManager.GetConnectionsPerStream()+ );+ }+}\ No newline at end of filediff --git a/backend/WebDav/DatabaseStoreRarFile.cs b/backend/WebDav/DatabaseStoreRarFile.csindex 5073d3d8..972a9005 100644--- a/backend/WebDav/DatabaseStoreRarFile.cs+++ b/backend/WebDav/DatabaseStoreRarFile.cs@@ -4,6 +4,7 @@ using NzbWebDAV.Clients.Usenet;using NzbWebDAV.Config;using NzbWebDAV.Database;using NzbWebDAV.Database.Models;+using NzbWebDAV.Models;using NzbWebDAV.Streams;using NzbWebDAV.WebDav.Base;@@ -32,6 +33,11 @@ public class DatabaseStoreRarFile(var id = davRarFile.Id;var rarFile = await dbClient.Ctx.RarFiles.Where(x => x.Id == id).FirstOrDefaultAsync(ct);if (rarFile is null) throw new FileNotFoundException($"Could not find nzb file with id: {id}");- return new RarFileStream(rarFile.RarParts, usenetClient, configManager.GetConnectionsPerStream());+ return new DavMultipartFileStream+ (+ rarFile.ToDavMultipartFileMeta().FileParts,+ usenetClient,+ configManager.GetConnectionsPerStream()+ );}}\ No newline at end of filediff --git a/backend/WebDav/DatabaseStoreSymlinkCollection.cs b/backend/WebDav/DatabaseStoreSymlinkCollection.csindex c1971d25..17a09895 100644--- a/backend/WebDav/DatabaseStoreSymlinkCollection.cs+++ b/backend/WebDav/DatabaseStoreSymlinkCollection.cs@@ -97,6 +97,8 @@ public class DatabaseStoreSymlinkCollection(new DatabaseStoreSymlinkFile(davItem, configManager),DavItem.ItemType.RarFile =>new DatabaseStoreSymlinkFile(davItem, configManager),+ DavItem.ItemType.MultipartFile =>+ new DatabaseStoreSymlinkFile(davItem, configManager),_ => throw new ArgumentException("Unrecognized directory child type.")};}