mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-06-10 00:54:18 -04:00
* Started working on a report problems implementation. * Started code * Added logging to book and archive service. * Removed an additional ComicInfo read when comicinfo is null when trying to load. But we've already done it once earlier, so there really isn't any point. * Added basic implementation for media errors. * MediaErrors will ignore duplicate errors when there are multiple issues on same file in a scan. * Fixed unit tests * Basic code in place to view and clear. Just UI Cleanup needed. * Slight css upgrade * Fixed up centering and simplified the code to use regular array instead of observables as it wasn't working. * Fixed unit tests * Fixed unit tests for real
68 lines
2.2 KiB
C#
68 lines
2.2 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using API.Data;
|
|
using API.Helpers.Builders;
|
|
using Hangfire;
|
|
|
|
namespace API.Services;
|
|
|
|
public enum MediaErrorProducer
|
|
{
|
|
BookService = 0,
|
|
ArchiveService = 1
|
|
|
|
}
|
|
|
|
public interface IMediaErrorService
|
|
{
|
|
Task ReportMediaIssueAsync(string filename, MediaErrorProducer producer, string errorMessage, string details);
|
|
void ReportMediaIssue(string filename, MediaErrorProducer producer, string errorMessage, string details);
|
|
Task ReportMediaIssueAsync(string filename, MediaErrorProducer producer, string errorMessage, Exception ex);
|
|
void ReportMediaIssue(string filename, MediaErrorProducer producer, string errorMessage, Exception ex);
|
|
}
|
|
|
|
public class MediaErrorService : IMediaErrorService
|
|
{
|
|
private readonly IUnitOfWork _unitOfWork;
|
|
|
|
public MediaErrorService(IUnitOfWork unitOfWork)
|
|
{
|
|
_unitOfWork = unitOfWork;
|
|
}
|
|
|
|
public async Task ReportMediaIssueAsync(string filename, MediaErrorProducer producer, string errorMessage, Exception ex)
|
|
{
|
|
await ReportMediaIssueAsync(filename, producer, errorMessage, ex.Message);
|
|
}
|
|
|
|
public void ReportMediaIssue(string filename, MediaErrorProducer producer, string errorMessage, Exception ex)
|
|
{
|
|
// To avoid overhead on commits, do async. We don't need to wait.
|
|
BackgroundJob.Enqueue(() => ReportMediaIssueAsync(filename, producer, errorMessage, ex.Message));
|
|
}
|
|
|
|
public void ReportMediaIssue(string filename, MediaErrorProducer producer, string errorMessage, string details)
|
|
{
|
|
// To avoid overhead on commits, do async. We don't need to wait.
|
|
BackgroundJob.Enqueue(() => ReportMediaIssueAsync(filename, producer, errorMessage, details));
|
|
}
|
|
|
|
public async Task ReportMediaIssueAsync(string filename, MediaErrorProducer producer, string errorMessage, string details)
|
|
{
|
|
var error = new MediaErrorBuilder(filename)
|
|
.WithComment(errorMessage)
|
|
.WithDetails(details)
|
|
.Build();
|
|
|
|
if (await _unitOfWork.MediaErrorRepository.ExistsAsync(error))
|
|
{
|
|
return;
|
|
}
|
|
|
|
|
|
_unitOfWork.MediaErrorRepository.Attach(error);
|
|
await _unitOfWork.CommitAsync();
|
|
}
|
|
|
|
}
|