Bugfix/sentry and fixes (#243)
* Generate SeriesMetadata when creating Series from Scanner. * Ignore errors from BookService * Fixed a case where we used First() when it should have been FirstOrDefault() to fail when there are no cover images (or images)
This commit is contained in:
parent
ce35c4f84a
commit
5083608f24
3 changed files with 25 additions and 13 deletions
|
@ -156,22 +156,31 @@ namespace API.Services
|
|||
public string GetSummaryInfo(string filePath)
|
||||
{
|
||||
if (!IsValidFile(filePath)) return string.Empty;
|
||||
|
||||
using var epubBook = EpubReader.OpenBook(filePath);
|
||||
return epubBook.Schema.Package.Metadata.Description;
|
||||
|
||||
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>();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue