Merge branch 'develop' of https://github.com/Kareadita/Kavita into develop

This commit is contained in:
Joseph Milazzo 2021-06-02 07:27:51 -05:00
commit 215dbde4db
3 changed files with 25 additions and 13 deletions

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using API.Entities;
using API.Entities.Enums;
using API.Parser;
@ -21,7 +22,8 @@ namespace API.Data
NormalizedName = Parser.Parser.Normalize(name),
SortName = name,
Summary = string.Empty,
Volumes = new List<Volume>()
Volumes = new List<Volume>(),
Metadata = SeriesMetadata(Array.Empty<CollectionTag>())
};
}

View File

@ -104,7 +104,8 @@ namespace API
options.BeforeSend = sentryEvent =>
{
if (sentryEvent.Exception != null
&& sentryEvent.Exception.Message.Contains("[GetCoverImage] This archive cannot be read:"))
&& sentryEvent.Exception.Message.Contains("[GetCoverImage] This archive cannot be read:")
&& sentryEvent.Exception.Message.Contains("[BookService] "))
{
return null; // Don't send this event to Sentry
}

View File

@ -157,21 +157,30 @@ namespace API.Services
{
if (!IsValidFile(filePath)) return string.Empty;
try
{
using var epubBook = EpubReader.OpenBook(filePath);
return epubBook.Schema.Package.Metadata.Description;
}
catch (Exception ex)
{
_logger.LogError(ex, "[BookService] There was an exception getting summary, defaulting to empty string");
}
return string.Empty;
}
private bool IsValidFile(string filePath)
{
if (!File.Exists(filePath))
{
_logger.LogError("Book {EpubFile} could not be found", filePath);
_logger.LogError("[BookService] Book {EpubFile} could not be found", filePath);
return false;
}
if (Parser.Parser.IsBook(filePath)) return true;
_logger.LogError("Book {EpubFile} is not a valid EPUB", filePath);
_logger.LogError("[BookService] Book {EpubFile} is not a valid EPUB", filePath);
return false;
}
@ -186,7 +195,7 @@ namespace API.Services
}
catch (Exception ex)
{
_logger.LogError(ex, "There was an exception getting number of pages, defaulting to 0");
_logger.LogError(ex, "[BookService] There was an exception getting number of pages, defaulting to 0");
}
return 0;
@ -238,7 +247,7 @@ namespace API.Services
}
catch (Exception ex)
{
_logger.LogError(ex, "There was an exception when opening epub book: {FileName}", filePath);
_logger.LogError(ex, "[BookService] There was an exception when opening epub book: {FileName}", filePath);
}
return null;
@ -257,7 +266,7 @@ namespace API.Services
// Try to get the cover image from OPF file, if not set, try to parse it from all the files, then result to the first one.
var coverImageContent = epubBook.Content.Cover
?? epubBook.Content.Images.Values.FirstOrDefault(file => Parser.Parser.IsCoverImage(file.FileName))
?? epubBook.Content.Images.Values.First();
?? epubBook.Content.Images.Values.FirstOrDefault();
if (coverImageContent == null) return Array.Empty<byte>();
@ -273,7 +282,7 @@ namespace API.Services
}
catch (Exception ex)
{
_logger.LogError(ex, "There was a critical error and prevented thumbnail generation on {BookFile}. Defaulting to no cover image", fileFilePath);
_logger.LogError(ex, "[BookService] There was a critical error and prevented thumbnail generation on {BookFile}. Defaulting to no cover image", fileFilePath);
}
return Array.Empty<byte>();