Colorscape Love (#3326)
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
This commit is contained in:
parent
b44f89d1e8
commit
a847468a6c
42 changed files with 1009 additions and 429 deletions
67
API/Data/ManualMigrations/MigrateDuplicateDarkTheme.cs
Normal file
67
API/Data/ManualMigrations/MigrateDuplicateDarkTheme.cs
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using API.Entities;
|
||||
using API.Services.Tasks.Scanner.Parser;
|
||||
using Kavita.Common.EnvironmentInfo;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace API.Data.ManualMigrations;
|
||||
|
||||
/// <summary>
|
||||
/// v0.8.0 ensured that MangaFile Path is normalized. This will normalize existing data to avoid churn.
|
||||
/// </summary>
|
||||
public static class MigrateDuplicateDarkTheme
|
||||
{
|
||||
public static async Task Migrate(DataContext dataContext, ILogger<Program> logger)
|
||||
{
|
||||
if (await dataContext.ManualMigrationHistory.AnyAsync(m => m.Name == "MigrateDuplicateDarkTheme"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
logger.LogCritical(
|
||||
"Running MigrateDuplicateDarkTheme migration - Please be patient, this may take some time. This is not an error");
|
||||
|
||||
var darkThemes = await dataContext.SiteTheme.Where(t => t.Name == "Dark").ToListAsync();
|
||||
|
||||
if (darkThemes.Count > 1)
|
||||
{
|
||||
var correctDarkTheme = darkThemes.First(d => !string.IsNullOrEmpty(d.Description));
|
||||
|
||||
// Get users
|
||||
var users = await dataContext.AppUser
|
||||
.Include(u => u.UserPreferences)
|
||||
.ThenInclude(p => p.Theme)
|
||||
.Where(u => u.UserPreferences.Theme.Name == "Dark")
|
||||
.ToListAsync();
|
||||
|
||||
// Find any users that have a duplicate Dark theme as default and switch to the correct one
|
||||
foreach (var user in users)
|
||||
{
|
||||
if (string.IsNullOrEmpty(user.UserPreferences.Theme.Description))
|
||||
{
|
||||
user.UserPreferences.Theme = correctDarkTheme;
|
||||
}
|
||||
}
|
||||
await dataContext.SaveChangesAsync();
|
||||
|
||||
// Now remove the bad themes
|
||||
dataContext.SiteTheme.RemoveRange(darkThemes.Where(d => string.IsNullOrEmpty(d.Description)));
|
||||
|
||||
await dataContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
dataContext.ManualMigrationHistory.Add(new ManualMigrationHistory()
|
||||
{
|
||||
Name = "MigrateDuplicateDarkTheme",
|
||||
ProductVersion = BuildInfo.Version.ToString(),
|
||||
RanAt = DateTime.UtcNow
|
||||
});
|
||||
await dataContext.SaveChangesAsync();
|
||||
|
||||
logger.LogCritical(
|
||||
"Running MigrateDuplicateDarkTheme migration - Completed. This is not an error");
|
||||
}
|
||||
}
|
||||
85
API/Data/Repositories/CoverDbRepository.cs
Normal file
85
API/Data/Repositories/CoverDbRepository.cs
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using API.DTOs.CoverDb;
|
||||
using API.Entities;
|
||||
using YamlDotNet.Serialization;
|
||||
using YamlDotNet.Serialization.NamingConventions;
|
||||
|
||||
namespace API.Data.Repositories;
|
||||
#nullable enable
|
||||
|
||||
/// <summary>
|
||||
/// This is a manual repository, not a DB repo
|
||||
/// </summary>
|
||||
public class CoverDbRepository
|
||||
{
|
||||
private readonly List<CoverDbAuthor> _authors;
|
||||
|
||||
public CoverDbRepository(string filePath)
|
||||
{
|
||||
var deserializer = new DeserializerBuilder()
|
||||
.WithNamingConvention(CamelCaseNamingConvention.Instance)
|
||||
.Build();
|
||||
|
||||
// Read and deserialize YAML file
|
||||
var yamlContent = File.ReadAllText(filePath);
|
||||
var peopleData = deserializer.Deserialize<CoverDbPeople>(yamlContent);
|
||||
_authors = peopleData.People;
|
||||
}
|
||||
|
||||
public CoverDbAuthor? FindAuthorByNameOrAlias(string name)
|
||||
{
|
||||
return _authors.Find(author =>
|
||||
author.Name.Equals(name, StringComparison.OrdinalIgnoreCase) ||
|
||||
author.Aliases.Contains(name, StringComparer.OrdinalIgnoreCase));
|
||||
}
|
||||
|
||||
public CoverDbAuthor? FindBestAuthorMatch(Person person)
|
||||
{
|
||||
var aniListId = person.AniListId > 0 ? $"{person.AniListId}" : string.Empty;
|
||||
var highestScore = 0;
|
||||
CoverDbAuthor? bestMatch = null;
|
||||
|
||||
foreach (var author in _authors)
|
||||
{
|
||||
var score = 0;
|
||||
|
||||
// Check metadata IDs and add points if they match
|
||||
if (!string.IsNullOrEmpty(author.Ids.AmazonId) && author.Ids.AmazonId == person.Asin)
|
||||
{
|
||||
score += 10;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(author.Ids.AnilistId) && author.Ids.AnilistId == aniListId)
|
||||
{
|
||||
score += 10;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(author.Ids.HardcoverId) && author.Ids.HardcoverId == person.HardcoverId)
|
||||
{
|
||||
score += 10;
|
||||
}
|
||||
|
||||
// Check for exact name match
|
||||
if (author.Name.Equals(person.Name, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
score += 7;
|
||||
}
|
||||
|
||||
// Check for alias match
|
||||
if (author.Aliases.Contains(person.Name, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
score += 5;
|
||||
}
|
||||
|
||||
// Update the best match if current score is higher
|
||||
if (score <= highestScore) continue;
|
||||
|
||||
highestScore = score;
|
||||
bestMatch = author;
|
||||
}
|
||||
|
||||
return bestMatch;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -38,6 +38,7 @@ public interface IPersonRepository
|
|||
Task<Person?> GetPersonById(int personId);
|
||||
Task<PersonDto?> GetPersonDtoByName(string name, int userId);
|
||||
Task<Person> GetPersonByName(string name);
|
||||
Task<bool> IsNameUnique(string name);
|
||||
|
||||
Task<IEnumerable<SeriesDto>> GetSeriesKnownFor(int personId);
|
||||
Task<IEnumerable<StandaloneChapterDto>> GetChaptersForPersonByRole(int personId, int userId, PersonRole role);
|
||||
|
|
@ -211,6 +212,11 @@ public class PersonRepository : IPersonRepository
|
|||
return await _context.Person.FirstOrDefaultAsync(p => p.NormalizedName == name.ToNormalized());
|
||||
}
|
||||
|
||||
public async Task<bool> IsNameUnique(string name)
|
||||
{
|
||||
return !(await _context.Person.AnyAsync(p => p.Name == name));
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<SeriesDto>> GetSeriesKnownFor(int personId)
|
||||
{
|
||||
return await _context.Person
|
||||
|
|
|
|||
|
|
@ -248,6 +248,7 @@ public class ReadingListRepository : IReadingListRepository
|
|||
ChapterTitleName = chapter.TitleName,
|
||||
FileSize = chapter.Files.Sum(f => f.Bytes),
|
||||
chapter.Summary,
|
||||
chapter.IsSpecial
|
||||
|
||||
})
|
||||
.Join(_context.Volume, s => s.ReadingListItem.VolumeId, volume => volume.Id, (data, volume) => new
|
||||
|
|
@ -259,6 +260,7 @@ public class ReadingListRepository : IReadingListRepository
|
|||
data.ChapterTitleName,
|
||||
data.FileSize,
|
||||
data.Summary,
|
||||
data.IsSpecial,
|
||||
VolumeId = volume.Id,
|
||||
VolumeNumber = volume.Name,
|
||||
})
|
||||
|
|
@ -277,6 +279,7 @@ public class ReadingListRepository : IReadingListRepository
|
|||
data.ChapterTitleName,
|
||||
data.FileSize,
|
||||
data.Summary,
|
||||
data.IsSpecial,
|
||||
LibraryName = _context.Library.Where(l => l.Id == s.LibraryId).Select(l => l.Name).Single(),
|
||||
LibraryType = _context.Library.Where(l => l.Id == s.LibraryId).Select(l => l.Type).Single()
|
||||
})
|
||||
|
|
@ -299,7 +302,8 @@ public class ReadingListRepository : IReadingListRepository
|
|||
ChapterTitleName = data.ChapterTitleName,
|
||||
LibraryName = data.LibraryName,
|
||||
FileSize = data.FileSize,
|
||||
Summary = data.Summary
|
||||
Summary = data.Summary,
|
||||
IsSpecial = data.IsSpecial
|
||||
})
|
||||
.Where(o => userLibraries.Contains(o.LibraryId))
|
||||
.OrderBy(rli => rli.Order)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue