using LehrerApp.Core.Interfaces; namespace LehrerApp.Data; public class LiteAttachmentStorage(LiteDbContext db) : IAttachmentStorage { public string Upload(string fileName, Stream content) { if (content.Length > IAttachmentStorage.MaxSizeBytes) throw new InvalidOperationException( $"Datei ist größer als {IAttachmentStorage.MaxSizeBytes / 1024 / 1024} MB."); var id = Guid.NewGuid().ToString("N"); db.Attachments.Upload(id, fileName, content); return id; } public Stream? OpenRead(string storageId) => db.Attachments.Exists(storageId) ? db.Attachments.OpenRead(storageId) : null; public void Delete(string storageId) => db.Attachments.Delete(storageId); }