Some cleanup. There is a bug around cover image not working for chapter image due to overwriting current and not using a temp image.
This commit is contained in:
parent
01f9cea86f
commit
eb1a524b2f
6 changed files with 47 additions and 18 deletions
|
|
@ -142,7 +142,7 @@ public class ChapterListExtensionsTests
|
||||||
CreateChapter("darker than black", "1", CreateFile("/manga/darker than black.cbz", MangaFormat.Archive), false),
|
CreateChapter("darker than black", "1", CreateFile("/manga/darker than black.cbz", MangaFormat.Archive), false),
|
||||||
};
|
};
|
||||||
|
|
||||||
Assert.Equal(chapterList.First(), chapterList.GetFirstChapterWithFiles());
|
Assert.Equal(chapterList[0], chapterList.GetFirstChapterWithFiles());
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
@ -150,13 +150,13 @@ public class ChapterListExtensionsTests
|
||||||
{
|
{
|
||||||
var chapterList = new List<Chapter>()
|
var chapterList = new List<Chapter>()
|
||||||
{
|
{
|
||||||
CreateChapter("darker than black", API.Services.Tasks.Scanner.Parser.Parser.DefaultChapter, CreateFile("/manga/darker than black.cbz", MangaFormat.Archive), true),
|
CreateChapter("darker than black", Parser.DefaultChapter, CreateFile("/manga/darker than black.cbz", MangaFormat.Archive), true),
|
||||||
CreateChapter("darker than black", "1", CreateFile("/manga/darker than black.cbz", MangaFormat.Archive), false),
|
CreateChapter("darker than black", "1", CreateFile("/manga/darker than black.cbz", MangaFormat.Archive), false),
|
||||||
};
|
};
|
||||||
|
|
||||||
chapterList.First().Files = new List<MangaFile>();
|
chapterList[0].Files = new List<MangaFile>();
|
||||||
|
|
||||||
Assert.Equal(chapterList.Last(), chapterList.GetFirstChapterWithFiles());
|
Assert.Equal(chapterList[^1], chapterList.GetFirstChapterWithFiles());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -181,7 +181,7 @@ public class ChapterListExtensionsTests
|
||||||
CreateChapter("detective comics", API.Services.Tasks.Scanner.Parser.Parser.DefaultChapter, CreateFile("/manga/detective comics #001.cbz", MangaFormat.Archive), true)
|
CreateChapter("detective comics", API.Services.Tasks.Scanner.Parser.Parser.DefaultChapter, CreateFile("/manga/detective comics #001.cbz", MangaFormat.Archive), true)
|
||||||
};
|
};
|
||||||
|
|
||||||
chapterList[0].ReleaseDate = new DateTime(10, 1, 1);
|
chapterList[0].ReleaseDate = new DateTime(10, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||||
chapterList[1].ReleaseDate = DateTime.MinValue;
|
chapterList[1].ReleaseDate = DateTime.MinValue;
|
||||||
|
|
||||||
Assert.Equal(0, chapterList.MinimumReleaseYear());
|
Assert.Equal(0, chapterList.MinimumReleaseYear());
|
||||||
|
|
@ -196,8 +196,8 @@ public class ChapterListExtensionsTests
|
||||||
CreateChapter("detective comics", API.Services.Tasks.Scanner.Parser.Parser.DefaultChapter, CreateFile("/manga/detective comics #001.cbz", MangaFormat.Archive), true)
|
CreateChapter("detective comics", API.Services.Tasks.Scanner.Parser.Parser.DefaultChapter, CreateFile("/manga/detective comics #001.cbz", MangaFormat.Archive), true)
|
||||||
};
|
};
|
||||||
|
|
||||||
chapterList[0].ReleaseDate = new DateTime(2002, 1, 1);
|
chapterList[0].ReleaseDate = new DateTime(2002, 1, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||||
chapterList[1].ReleaseDate = new DateTime(2012, 2, 1);
|
chapterList[1].ReleaseDate = new DateTime(2012, 2, 1, 0, 0, 0, DateTimeKind.Utc);
|
||||||
|
|
||||||
Assert.Equal(2002, chapterList.MinimumReleaseYear());
|
Assert.Equal(2002, chapterList.MinimumReleaseYear());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -419,7 +419,7 @@ public class ChapterController : BaseApiController
|
||||||
ret.HasBeenRated = ownRating.HasBeenRated;
|
ret.HasBeenRated = ownRating.HasBeenRated;
|
||||||
}
|
}
|
||||||
|
|
||||||
var externalReviews = await _unitOfWork.ChapterRepository.GetExternalChapterReviews(chapterId);
|
var externalReviews = await _unitOfWork.ChapterRepository.GetExternalChapterReviewDtos(chapterId);
|
||||||
if (externalReviews.Count > 0)
|
if (externalReviews.Count > 0)
|
||||||
{
|
{
|
||||||
userReviews.AddRange(ReviewHelper.SelectSpectrumOfReviews(externalReviews));
|
userReviews.AddRange(ReviewHelper.SelectSpectrumOfReviews(externalReviews));
|
||||||
|
|
@ -427,7 +427,7 @@ public class ChapterController : BaseApiController
|
||||||
|
|
||||||
ret.Reviews = userReviews;
|
ret.Reviews = userReviews;
|
||||||
|
|
||||||
ret.Ratings = await _unitOfWork.ChapterRepository.GetExternalChapterRatings(chapterId);
|
ret.Ratings = await _unitOfWork.ChapterRepository.GetExternalChapterRatingDtos(chapterId);
|
||||||
|
|
||||||
return Ok(ret);
|
return Ok(ret);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ using API.DTOs.Reader;
|
||||||
using API.DTOs.SeriesDetail;
|
using API.DTOs.SeriesDetail;
|
||||||
using API.Entities;
|
using API.Entities;
|
||||||
using API.Entities.Enums;
|
using API.Entities.Enums;
|
||||||
|
using API.Entities.Metadata;
|
||||||
using API.Extensions;
|
using API.Extensions;
|
||||||
using API.Extensions.QueryExtensions;
|
using API.Extensions.QueryExtensions;
|
||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
|
|
@ -51,8 +52,10 @@ public interface IChapterRepository
|
||||||
IEnumerable<Chapter> GetChaptersForSeries(int seriesId);
|
IEnumerable<Chapter> GetChaptersForSeries(int seriesId);
|
||||||
Task<IList<Chapter>> GetAllChaptersForSeries(int seriesId);
|
Task<IList<Chapter>> GetAllChaptersForSeries(int seriesId);
|
||||||
Task<int> GetAverageUserRating(int chapterId, int userId);
|
Task<int> GetAverageUserRating(int chapterId, int userId);
|
||||||
Task<IList<UserReviewDto>> GetExternalChapterReviews(int chapterId);
|
Task<IList<UserReviewDto>> GetExternalChapterReviewDtos(int chapterId);
|
||||||
Task<IList<RatingDto>> GetExternalChapterRatings(int chapterId);
|
Task<IList<ExternalReview>> GetExternalChapterReview(int chapterId);
|
||||||
|
Task<IList<RatingDto>> GetExternalChapterRatingDtos(int chapterId);
|
||||||
|
Task<IList<ExternalRating>> GetExternalChapterRatings(int chapterId);
|
||||||
}
|
}
|
||||||
public class ChapterRepository : IChapterRepository
|
public class ChapterRepository : IChapterRepository
|
||||||
{
|
{
|
||||||
|
|
@ -332,7 +335,7 @@ public class ChapterRepository : IChapterRepository
|
||||||
return avg.HasValue ? (int) (avg.Value * 20) : 0;
|
return avg.HasValue ? (int) (avg.Value * 20) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IList<UserReviewDto>> GetExternalChapterReviews(int chapterId)
|
public async Task<IList<UserReviewDto>> GetExternalChapterReviewDtos(int chapterId)
|
||||||
{
|
{
|
||||||
return await _context.Chapter
|
return await _context.Chapter
|
||||||
.Where(c => c.Id == chapterId)
|
.Where(c => c.Id == chapterId)
|
||||||
|
|
@ -342,7 +345,15 @@ public class ChapterRepository : IChapterRepository
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<IList<RatingDto>> GetExternalChapterRatings(int chapterId)
|
public async Task<IList<ExternalReview>> GetExternalChapterReview(int chapterId)
|
||||||
|
{
|
||||||
|
return await _context.Chapter
|
||||||
|
.Where(c => c.Id == chapterId)
|
||||||
|
.SelectMany(c => c.ExternalReviews)
|
||||||
|
.ToListAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IList<RatingDto>> GetExternalChapterRatingDtos(int chapterId)
|
||||||
{
|
{
|
||||||
return await _context.Chapter
|
return await _context.Chapter
|
||||||
.Where(c => c.Id == chapterId)
|
.Where(c => c.Id == chapterId)
|
||||||
|
|
@ -350,4 +361,12 @@ public class ChapterRepository : IChapterRepository
|
||||||
.ProjectTo<RatingDto>(_mapper.ConfigurationProvider)
|
.ProjectTo<RatingDto>(_mapper.ConfigurationProvider)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<IList<ExternalRating>> GetExternalChapterRatings(int chapterId)
|
||||||
|
{
|
||||||
|
return await _context.Chapter
|
||||||
|
.Where(c => c.Id == chapterId)
|
||||||
|
.SelectMany(c => c.ExternalRatings)
|
||||||
|
.ToListAsync();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1085,7 +1085,7 @@ public class ExternalMetadataService : IExternalMetadataService
|
||||||
madeModification = await UpdateChapterPeople(chapter, settings, PersonRole.Writer, potentialMatch.Writers) || madeModification;
|
madeModification = await UpdateChapterPeople(chapter, settings, PersonRole.Writer, potentialMatch.Writers) || madeModification;
|
||||||
|
|
||||||
madeModification = await UpdateChapterCoverImage(chapter, settings, potentialMatch.CoverImageUrl) || madeModification;
|
madeModification = await UpdateChapterCoverImage(chapter, settings, potentialMatch.CoverImageUrl) || madeModification;
|
||||||
madeModification = UpdateExternalChapterMetadata(chapter, settings, potentialMatch) || madeModification;
|
madeModification = await UpdateExternalChapterMetadata(chapter, settings, potentialMatch) || madeModification;
|
||||||
|
|
||||||
_unitOfWork.ChapterRepository.Update(chapter);
|
_unitOfWork.ChapterRepository.Update(chapter);
|
||||||
await _unitOfWork.CommitAsync();
|
await _unitOfWork.CommitAsync();
|
||||||
|
|
@ -1094,7 +1094,7 @@ public class ExternalMetadataService : IExternalMetadataService
|
||||||
return madeModification;
|
return madeModification;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool UpdateExternalChapterMetadata(Chapter chapter, MetadataSettingsDto settings, ExternalChapterDto metadata)
|
private async Task<bool> UpdateExternalChapterMetadata(Chapter chapter, MetadataSettingsDto settings, ExternalChapterDto metadata)
|
||||||
{
|
{
|
||||||
if (!settings.Enabled) return false;
|
if (!settings.Enabled) return false;
|
||||||
|
|
||||||
|
|
@ -1106,7 +1106,12 @@ public class ExternalMetadataService : IExternalMetadataService
|
||||||
var madeModification = false;
|
var madeModification = false;
|
||||||
|
|
||||||
#region Review
|
#region Review
|
||||||
_unitOfWork.ExternalSeriesMetadataRepository.Remove(chapter.ExternalReviews);
|
|
||||||
|
// Remove existing Reviews
|
||||||
|
var existingReviews = await _unitOfWork.ChapterRepository.GetExternalChapterReview(chapter.Id);
|
||||||
|
_unitOfWork.ExternalSeriesMetadataRepository.Remove(existingReviews);
|
||||||
|
|
||||||
|
|
||||||
List<ExternalReview> externalReviews = [];
|
List<ExternalReview> externalReviews = [];
|
||||||
externalReviews.AddRange(metadata.CriticReviews
|
externalReviews.AddRange(metadata.CriticReviews
|
||||||
.Where(r => !string.IsNullOrWhiteSpace(r.Username) && !string.IsNullOrWhiteSpace(r.Body))
|
.Where(r => !string.IsNullOrWhiteSpace(r.Username) && !string.IsNullOrWhiteSpace(r.Body))
|
||||||
|
|
@ -1139,7 +1144,9 @@ public class ExternalMetadataService : IExternalMetadataService
|
||||||
var averageCriticRating = metadata.CriticReviews.Average(r => r.Rating);
|
var averageCriticRating = metadata.CriticReviews.Average(r => r.Rating);
|
||||||
var averageUserRating = metadata.UserReviews.Average(r => r.Rating);
|
var averageUserRating = metadata.UserReviews.Average(r => r.Rating);
|
||||||
|
|
||||||
_unitOfWork.ExternalSeriesMetadataRepository.Remove(chapter.ExternalRatings);
|
var existingRatings = await _unitOfWork.ChapterRepository.GetExternalChapterRatings(chapter.Id);
|
||||||
|
_unitOfWork.ExternalSeriesMetadataRepository.Remove(existingRatings);
|
||||||
|
|
||||||
chapter.ExternalRatings =
|
chapter.ExternalRatings =
|
||||||
[
|
[
|
||||||
new ExternalRating
|
new ExternalRating
|
||||||
|
|
|
||||||
|
|
@ -458,7 +458,7 @@ public class SeriesService : ISeriesService
|
||||||
allChapterIds.AddRange(mapping.Value);
|
allChapterIds.AddRange(mapping.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// BUG: This isn't getting all the people and whatnot currently
|
// NOTE: This isn't getting all the people and whatnot currently due to the lack of includes
|
||||||
var series = await _unitOfWork.SeriesRepository.GetSeriesByIdsAsync(seriesIds);
|
var series = await _unitOfWork.SeriesRepository.GetSeriesByIdsAsync(seriesIds);
|
||||||
_unitOfWork.SeriesRepository.Remove(series);
|
_unitOfWork.SeriesRepository.Remove(series);
|
||||||
|
|
||||||
|
|
@ -481,6 +481,7 @@ public class SeriesService : ISeriesService
|
||||||
await _unitOfWork.AppUserProgressRepository.CleanupAbandonedChapters();
|
await _unitOfWork.AppUserProgressRepository.CleanupAbandonedChapters();
|
||||||
await _unitOfWork.CollectionTagRepository.RemoveCollectionsWithoutSeries();
|
await _unitOfWork.CollectionTagRepository.RemoveCollectionsWithoutSeries();
|
||||||
_taskScheduler.CleanupChapters([.. allChapterIds]);
|
_taskScheduler.CleanupChapters([.. allChapterIds]);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
|
||||||
|
|
@ -308,6 +308,7 @@ public class CoverDbService : ICoverDbService
|
||||||
.AllowHttpStatus("2xx,304")
|
.AllowHttpStatus("2xx,304")
|
||||||
.GetStreamAsync();
|
.GetStreamAsync();
|
||||||
|
|
||||||
|
|
||||||
using var image = Image.NewFromStream(personStream);
|
using var image = Image.NewFromStream(personStream);
|
||||||
switch (encodeFormat)
|
switch (encodeFormat)
|
||||||
{
|
{
|
||||||
|
|
@ -553,6 +554,7 @@ public class CoverDbService : ICoverDbService
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
// BUG: There might be a bug here where it's comparing the same 2 images
|
||||||
var betterImage = Path.Join(_directoryService.CoverImageDirectory, series.CoverImage)
|
var betterImage = Path.Join(_directoryService.CoverImageDirectory, series.CoverImage)
|
||||||
.GetBetterImage(Path.Join(_directoryService.CoverImageDirectory, filePath))!;
|
.GetBetterImage(Path.Join(_directoryService.CoverImageDirectory, filePath))!;
|
||||||
filePath = Path.GetFileName(betterImage);
|
filePath = Path.GetFileName(betterImage);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue