diff options
Diffstat (limited to 'Jellyfin.Server.Implementations/Item/ChapterRepository.cs')
| -rw-r--r-- | Jellyfin.Server.Implementations/Item/ChapterRepository.cs | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/Jellyfin.Server.Implementations/Item/ChapterRepository.cs b/Jellyfin.Server.Implementations/Item/ChapterRepository.cs index 93e15735c..98700f322 100644 --- a/Jellyfin.Server.Implementations/Item/ChapterRepository.cs +++ b/Jellyfin.Server.Implementations/Item/ChapterRepository.cs @@ -1,12 +1,12 @@ using System; using System.Collections.Generic; -using System.Collections.Immutable; using System.Linq; +using System.Threading; +using System.Threading.Tasks; using Jellyfin.Database.Implementations; using Jellyfin.Database.Implementations.Entities; -using MediaBrowser.Controller.Chapters; using MediaBrowser.Controller.Drawing; -using MediaBrowser.Model.Dto; +using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Entities; using Microsoft.EntityFrameworkCore; @@ -31,19 +31,7 @@ public class ChapterRepository : IChapterRepository _imageProcessor = imageProcessor; } - /// <inheritdoc cref="IChapterRepository"/> - public ChapterInfo? GetChapter(BaseItemDto baseItem, int index) - { - return GetChapter(baseItem.Id, index); - } - - /// <inheritdoc cref="IChapterRepository"/> - public IReadOnlyList<ChapterInfo> GetChapters(BaseItemDto baseItem) - { - return GetChapters(baseItem.Id); - } - - /// <inheritdoc cref="IChapterRepository"/> + /// <inheritdoc /> public ChapterInfo? GetChapter(Guid baseItemId, int index) { using var context = _dbProvider.CreateDbContext(); @@ -62,7 +50,7 @@ public class ChapterRepository : IChapterRepository return null; } - /// <inheritdoc cref="IChapterRepository"/> + /// <inheritdoc /> public IReadOnlyList<ChapterInfo> GetChapters(Guid baseItemId) { using var context = _dbProvider.CreateDbContext(); @@ -77,7 +65,7 @@ public class ChapterRepository : IChapterRepository .ToArray(); } - /// <inheritdoc cref="IChapterRepository"/> + /// <inheritdoc /> public void SaveChapters(Guid itemId, IReadOnlyList<ChapterInfo> chapters) { using var context = _dbProvider.CreateDbContext(); @@ -95,6 +83,17 @@ public class ChapterRepository : IChapterRepository } } + /// <inheritdoc /> + public async Task DeleteChaptersAsync(Guid itemId, CancellationToken cancellationToken) + { + var dbContext = await _dbProvider.CreateDbContextAsync(cancellationToken).ConfigureAwait(false); + await using (dbContext.ConfigureAwait(false)) + { + await dbContext.Chapters.Where(c => c.ItemId.Equals(itemId)).ExecuteDeleteAsync(cancellationToken).ConfigureAwait(false); + await dbContext.SaveChangesAsync(cancellationToken).ConfigureAwait(false); + } + } + private Chapter Map(ChapterInfo chapterInfo, int index, Guid itemId) { return new Chapter() @@ -118,7 +117,12 @@ public class ChapterRepository : IChapterRepository ImagePath = chapterInfo.ImagePath, Name = chapterInfo.Name, }; - chapterEntity.ImageTag = _imageProcessor.GetImageCacheTag(baseItemPath, chapterEntity.ImageDateModified); + + if (!string.IsNullOrEmpty(chapterInfo.ImagePath)) + { + chapterEntity.ImageTag = _imageProcessor.GetImageCacheTag(baseItemPath, chapterEntity.ImageDateModified); + } + return chapterEntity; } } |
