Usenet streaming with a WebDAV server and a SABnzbd-compatible API
C#
Added MemoryPack annotations for serialization/deserialization of blob models.
nzbdav-devfa9e6376e8c6
diff --git a/backend/Database/Models/DavMultipartFile.cs b/backend/Database/Models/DavMultipartFile.csindex 07d9ec0a..31c66252 100644--- a/backend/Database/Models/DavMultipartFile.cs+++ b/backend/Database/Models/DavMultipartFile.cs@@ -1,31 +1,45 @@-using NzbWebDAV.Models;+using MemoryPack;+using NzbWebDAV.Models;namespace NzbWebDAV.Database.Models;-public class DavMultipartFile+[MemoryPackable(GenerateType.VersionTolerant)]+public partial class DavMultipartFile{+ [MemoryPackOrder(0)]public Guid Id { get; set; } // foreign key to DavItem.Id++ [MemoryPackOrder(1)]public Meta Metadata { get; set; }// navigation helpers+ [MemoryPackIgnore]public DavItem? DavItem { get; set; }- public class Meta+ [MemoryPackable(GenerateType.VersionTolerant)]+ public partial class Meta{+ [MemoryPackOrder(0)]public AesParams? AesParams { get; set; }++ [MemoryPackOrder(1)]public FilePart[] FileParts { get; set; } = [];}- public class FilePart+ [MemoryPackable(GenerateType.VersionTolerant)]+ public partial class FilePart{// a subsequence of segments from an NzbFile+ [MemoryPackOrder(0)]public string[] SegmentIds { get; set; } = [];// what byte range is contained within the segmentIds? (relative to the full NzbFile)+ [MemoryPackOrder(1)]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.+ [MemoryPackOrder(2)]public LongRange FilePartByteRange { get; set; }}}\ No newline at end of filediff --git a/backend/Database/Models/DavNzbFile.cs b/backend/Database/Models/DavNzbFile.csindex 836759e4..49947bd8 100644--- a/backend/Database/Models/DavNzbFile.cs+++ b/backend/Database/Models/DavNzbFile.cs@@ -1,10 +1,17 @@-namespace NzbWebDAV.Database.Models;+using MemoryPack;-public class DavNzbFile+namespace NzbWebDAV.Database.Models;++[MemoryPackable(GenerateType.VersionTolerant)]+public partial class DavNzbFile{+ [MemoryPackOrder(0)]public Guid Id { get; set; } // foreign key to DavItem.Id++ [MemoryPackOrder(1)]public string[] SegmentIds { get; set; } = [];// navigation helpers+ [MemoryPackIgnore]public DavItem? DavItem { get; set; }}\ No newline at end of filediff --git a/backend/Database/Models/DavRarFile.cs b/backend/Database/Models/DavRarFile.csindex 7b89440b..168f4a59 100644--- a/backend/Database/Models/DavRarFile.cs+++ b/backend/Database/Models/DavRarFile.cs@@ -1,20 +1,34 @@-using NzbWebDAV.Models;+using MemoryPack;+using NzbWebDAV.Models;namespace NzbWebDAV.Database.Models;-public class DavRarFile+[MemoryPackable(GenerateType.VersionTolerant)]+public partial class DavRarFile{+ [MemoryPackOrder(0)]public Guid Id { get; set; } // foreign key to DavItem.Id++ [MemoryPackOrder(1)]public RarPart[] RarParts { get; set; } = [];// navigation helpers+ [MemoryPackIgnore]public DavItem? DavItem { get; set; }- public class RarPart+ [MemoryPackable(GenerateType.VersionTolerant)]+ public partial class RarPart{+ [MemoryPackOrder(0)]public string[] SegmentIds { get; set; } = [];++ [MemoryPackOrder(1)]public long PartSize { get; set; }++ [MemoryPackOrder(2)]public long Offset { get; set; }++ [MemoryPackOrder(3)]public long ByteCount { get; set; }}diff --git a/backend/Models/AesParams.cs b/backend/Models/AesParams.csindex 289fb203..22caa669 100644--- a/backend/Models/AesParams.cs+++ b/backend/Models/AesParams.cs@@ -1,14 +1,27 @@using System.Security.Cryptography;using System.Text;+using MemoryPack;namespace NzbWebDAV.Models;-public class AesParams()+[MemoryPackable(GenerateType.VersionTolerant)]+public partial class AesParams{+ [MemoryPackOrder(0)]public long DecodedSize { get; set; } = 0;++ [MemoryPackOrder(1)]public byte[] Iv { get; set; } = [];++ [MemoryPackOrder(2)]public byte[] Key { get; set; } = [];+ [MemoryPackConstructor]+ public AesParams()+ {+ // intentionally left blank+ }+public static AesParams? FromCoderInfo(byte[]? coderInfo, string? password, long decodedSize){if (coderInfo == null || password == null) return null;diff --git a/backend/Models/LongRange.cs b/backend/Models/LongRange.csindex 3bd6ad96..e05c00c8 100644--- a/backend/Models/LongRange.cs+++ b/backend/Models/LongRange.cs@@ -1,9 +1,25 @@-namespace NzbWebDAV.Models;+using MemoryPack;-public record LongRange(long StartInclusive, long EndExclusive)+namespace NzbWebDAV.Models;++[MemoryPackable(GenerateType.VersionTolerant)]+public partial record LongRange{+ [MemoryPackOrder(0)]+ public long StartInclusive { get; set; }++ [MemoryPackOrder(1)]+ public long EndExclusive { get; set; }++ [MemoryPackIgnore]public long Count => EndExclusive - StartInclusive;+ public LongRange(long startInclusive, long endExclusive)+ {+ StartInclusive = startInclusive;+ EndExclusive = endExclusive;+ }+public bool Contains(long value) =>value >= StartInclusive && value < EndExclusive;diff --git a/backend/NzbWebDAV.csproj b/backend/NzbWebDAV.csprojindex b4c2469a..77382e4e 100644--- a/backend/NzbWebDAV.csproj+++ b/backend/NzbWebDAV.csproj@@ -8,6 +8,7 @@</PropertyGroup><ItemGroup>+ <PackageReference Include="MemoryPack" Version="1.21.4" /><PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.1" /><PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.1"><PrivateAssets>all</PrivateAssets>