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;
using API.Entities.Enums; using API.Entities.Enums;
using API.Parser; using API.Parser;
@ -21,7 +22,8 @@ namespace API.Data
NormalizedName = Parser.Parser.Normalize(name), NormalizedName = Parser.Parser.Normalize(name),
SortName = name, SortName = name,
Summary = string.Empty, Summary = string.Empty,
Volumes = new List<Volume>() Volumes = new List<Volume>(),
Metadata = SeriesMetadata(Array.Empty<CollectionTag>())
}; };
} }

View File

@ -100,11 +100,12 @@ namespace API
options.AddExceptionFilterForType<NetVips.VipsException>(); options.AddExceptionFilterForType<NetVips.VipsException>();
options.AddExceptionFilterForType<InvalidDataException>(); options.AddExceptionFilterForType<InvalidDataException>();
options.AddExceptionFilterForType<KavitaException>(); options.AddExceptionFilterForType<KavitaException>();
options.BeforeSend = sentryEvent => options.BeforeSend = sentryEvent =>
{ {
if (sentryEvent.Exception != null 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 return null; // Don't send this event to Sentry
} }

View File

@ -156,22 +156,31 @@ namespace API.Services
public string GetSummaryInfo(string filePath) public string GetSummaryInfo(string filePath)
{ {
if (!IsValidFile(filePath)) return string.Empty; if (!IsValidFile(filePath)) return string.Empty;
using var epubBook = EpubReader.OpenBook(filePath); try
return epubBook.Schema.Package.Metadata.Description; {
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) private bool IsValidFile(string filePath)
{ {
if (!File.Exists(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; return false;
} }
if (Parser.Parser.IsBook(filePath)) return true; 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; return false;
} }
@ -186,7 +195,7 @@ namespace API.Services
} }
catch (Exception ex) 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; return 0;
@ -238,7 +247,7 @@ namespace API.Services
} }
catch (Exception ex) 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; 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. // 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 var coverImageContent = epubBook.Content.Cover
?? epubBook.Content.Images.Values.FirstOrDefault(file => Parser.Parser.IsCoverImage(file.FileName)) ?? 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>(); if (coverImageContent == null) return Array.Empty<byte>();
@ -273,7 +282,7 @@ namespace API.Services
} }
catch (Exception ex) 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>(); return Array.Empty<byte>();