mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-06-21 14:30:33 -04:00
* Bump express from 4.17.2 to 4.18.2 in /UI/Web Bumps [express](https://github.com/expressjs/express) from 4.17.2 to 4.18.2. - [Release notes](https://github.com/expressjs/express/releases) - [Changelog](https://github.com/expressjs/express/blob/master/History.md) - [Commits](https://github.com/expressjs/express/compare/4.17.2...4.18.2) --- updated-dependencies: - dependency-name: express dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Bump decode-uri-component from 0.2.0 to 0.2.2 in /UI/Web Bumps [decode-uri-component](https://github.com/SamVerschueren/decode-uri-component) from 0.2.0 to 0.2.2. - [Release notes](https://github.com/SamVerschueren/decode-uri-component/releases) - [Commits](https://github.com/SamVerschueren/decode-uri-component/compare/v0.2.0...v0.2.2) --- updated-dependencies: - dependency-name: decode-uri-component dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Bump qs and express in /UI/Web Bumps [qs](https://github.com/ljharb/qs) and [express](https://github.com/expressjs/express). These dependencies needed to be updated together. Updates `qs` from 6.5.3 to 6.11.0 - [Release notes](https://github.com/ljharb/qs/releases) - [Changelog](https://github.com/ljharb/qs/blob/main/CHANGELOG.md) - [Commits](https://github.com/ljharb/qs/compare/v6.5.3...v6.11.0) Updates `express` from 4.17.2 to 4.18.2 - [Release notes](https://github.com/expressjs/express/releases) - [Changelog](https://github.com/expressjs/express/blob/master/History.md) - [Commits](https://github.com/expressjs/express/compare/4.17.2...4.18.2) --- updated-dependencies: - dependency-name: qs dependency-type: indirect - dependency-name: express dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * Added genre and authors to Series level, added summary to volume and chapter level. Force order on reading list title as Chunky enforces their own sort order and doesn't respect the spec. * Moved all the reading list formatting logic to the backend. This allows us to re-use the UI logic for OPDS streams. * Fixed a broken unit test * Code smells Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
75 lines
2.8 KiB
C#
75 lines
2.8 KiB
C#
using System;
|
|
using System.Text.RegularExpressions;
|
|
using API.DTOs.ReadingLists;
|
|
using API.Entities;
|
|
using API.Entities.Enums;
|
|
|
|
namespace API.Helpers;
|
|
|
|
public static class ReadingListHelper
|
|
{
|
|
private static readonly Regex JustNumbers = new Regex(@"^\d+$", RegexOptions.Compiled | RegexOptions.IgnoreCase,
|
|
Services.Tasks.Scanner.Parser.Parser.RegexTimeout);
|
|
public static string FormatTitle(ReadingListItemDto item)
|
|
{
|
|
var title = string.Empty;
|
|
if (item.ChapterNumber == Services.Tasks.Scanner.Parser.Parser.DefaultChapter) {
|
|
title = $"Volume {item.VolumeNumber}";
|
|
}
|
|
|
|
if (item.SeriesFormat == MangaFormat.Epub) {
|
|
var specialTitle = Services.Tasks.Scanner.Parser.Parser.CleanSpecialTitle(item.ChapterNumber);
|
|
if (specialTitle == Services.Tasks.Scanner.Parser.Parser.DefaultChapter)
|
|
{
|
|
if (!string.IsNullOrEmpty(item.ChapterTitleName))
|
|
{
|
|
title = item.ChapterTitleName;
|
|
}
|
|
else
|
|
{
|
|
title = $"Volume {Services.Tasks.Scanner.Parser.Parser.CleanSpecialTitle(item.VolumeNumber)}";
|
|
}
|
|
} else {
|
|
title = $"Volume {specialTitle}";
|
|
}
|
|
}
|
|
|
|
var chapterNum = item.ChapterNumber;
|
|
if (!string.IsNullOrEmpty(chapterNum) && !JustNumbers.Match(item.ChapterNumber).Success) {
|
|
chapterNum = Services.Tasks.Scanner.Parser.Parser.CleanSpecialTitle(item.ChapterNumber);
|
|
}
|
|
|
|
if (title == string.Empty) {
|
|
title = FormatChapterName(item.LibraryType, true, true) + chapterNum;
|
|
}
|
|
return title;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Formats a Chapter name based on the library it's in
|
|
/// </summary>
|
|
/// <param name="libraryType"></param>
|
|
/// <param name="includeHash">For comics only, includes a # which is used for numbering on cards</param>
|
|
/// <param name="includeSpace">Add a space at the end of the string. if includeHash and includeSpace are true, only hash will be at the end.</param>
|
|
/// <returns></returns>
|
|
private static string FormatChapterName(LibraryType libraryType, bool includeHash = false,
|
|
bool includeSpace = false)
|
|
{
|
|
switch (libraryType)
|
|
{
|
|
case LibraryType.Manga:
|
|
return "Chapter" + (includeSpace ? " " : string.Empty);
|
|
case LibraryType.Comic:
|
|
if (includeHash) {
|
|
return "Issue #";
|
|
}
|
|
return "Issue" + (includeSpace ? " " : string.Empty);
|
|
case LibraryType.Book:
|
|
return "Book" + (includeSpace ? " " : string.Empty);
|
|
default:
|
|
throw new ArgumentOutOfRangeException(nameof(libraryType), libraryType, null);
|
|
}
|
|
}
|
|
|
|
}
|