Ability to update settings. Take effect on next reboot.
This commit is contained in:
parent
e60f795410
commit
1050fa4e54
21 changed files with 953 additions and 146 deletions
|
|
@ -74,19 +74,18 @@ namespace API.Services
|
|||
|
||||
private byte[] CreateThumbnail(ZipArchiveEntry entry)
|
||||
{
|
||||
var coverImage = Array.Empty<byte>();
|
||||
try
|
||||
{
|
||||
using var stream = entry.Open();
|
||||
using var thumbnail = Image.ThumbnailStream(stream, ThumbnailWidth);
|
||||
coverImage = thumbnail.WriteToBuffer(".jpg");
|
||||
return thumbnail.WriteToBuffer(".jpg");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "There was a critical error and prevented thumbnail generation. Defaulting to no cover image.");
|
||||
}
|
||||
|
||||
return coverImage;
|
||||
return Array.Empty<byte>();
|
||||
}
|
||||
|
||||
private static byte[] ConvertEntryToByteArray(ZipArchiveEntry entry)
|
||||
|
|
|
|||
|
|
@ -75,7 +75,6 @@ namespace API.Services
|
|||
|
||||
public void CleanupChapters(int[] chapterIds)
|
||||
{
|
||||
// TODO: Fix this code to work with chapters
|
||||
_logger.LogInformation($"Running Cache cleanup on Volumes");
|
||||
|
||||
foreach (var chapter in chapterIds)
|
||||
|
|
@ -112,7 +111,7 @@ namespace API.Services
|
|||
{
|
||||
var path = GetCachePath(chapter.Id);
|
||||
// TODO: GetFiles should only get image files.
|
||||
var files = _directoryService.GetFiles(path);
|
||||
var files = _directoryService.GetFiles(path);
|
||||
Array.Sort(files, _numericComparer);
|
||||
|
||||
return (files.ElementAt(page - pagesSoFar), mangaFile);
|
||||
|
|
|
|||
|
|
@ -4,15 +4,12 @@ using System.Collections.Generic;
|
|||
using System.Collections.Immutable;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using API.Entities;
|
||||
using API.Extensions;
|
||||
using API.Interfaces;
|
||||
using API.Parser;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NetVips;
|
||||
|
||||
namespace API.Services
|
||||
{
|
||||
|
|
@ -61,11 +58,11 @@ namespace API.Services
|
|||
var totalFiles = 0;
|
||||
foreach (var folderPath in library.Folders)
|
||||
{
|
||||
// if (!forceUpdate && Directory.GetLastWriteTime(folderPath.Path) <= folderPath.LastScanned)
|
||||
// {
|
||||
// _logger.LogDebug($"{folderPath.Path} hasn't been updated since last scan. Skipping.");
|
||||
// continue;
|
||||
// }
|
||||
if (!forceUpdate && Directory.GetLastWriteTime(folderPath.Path) <= folderPath.LastScanned)
|
||||
{
|
||||
_logger.LogDebug($"{folderPath.Path} hasn't been updated since last scan. Skipping.");
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
totalFiles += DirectoryService.TraverseTreeParallelForEach(folderPath.Path, (f) =>
|
||||
|
|
@ -163,7 +160,7 @@ namespace API.Services
|
|||
{
|
||||
if (info.Series == string.Empty) return;
|
||||
|
||||
_scannedSeries.AddOrUpdate(info.Series, new List<ParserInfo>() {info}, (key, oldValue) =>
|
||||
_scannedSeries.AddOrUpdate(info.Series, new List<ParserInfo>() {info}, (_, oldValue) =>
|
||||
{
|
||||
oldValue ??= new List<ParserInfo>();
|
||||
if (!oldValue.Contains(info))
|
||||
|
|
@ -234,94 +231,6 @@ namespace API.Services
|
|||
return forceUpdate || coverImage == null || !coverImage.Any();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Creates or Updates volumes for a given series
|
||||
/// </summary>
|
||||
/// <param name="series">Series wanting to be updated</param>
|
||||
/// <param name="infos">Parser info</param>
|
||||
/// <param name="forceUpdate">Forces metadata update (cover image) even if it's already been set.</param>
|
||||
/// <returns>Updated Volumes for given series</returns>
|
||||
private ICollection<Volume> UpdateVolumes(Series series, ParserInfo[] infos, bool forceUpdate)
|
||||
{
|
||||
ICollection<Volume> volumes = new List<Volume>();
|
||||
IList<Volume> existingVolumes = _unitOfWork.SeriesRepository.GetVolumes(series.Id).ToList();
|
||||
|
||||
//var justVolumes = infos.Select(pi => pi.Chapters == "0");
|
||||
|
||||
|
||||
foreach (var info in infos)
|
||||
{
|
||||
var existingVolume = existingVolumes.SingleOrDefault(v => v.Name == info.Volumes);
|
||||
if (existingVolume != null)
|
||||
{
|
||||
//var existingFile = existingVolume.Files.SingleOrDefault(f => f.FilePath == info.FullFilePath);
|
||||
var existingFile = new MangaFile();
|
||||
if (existingFile != null)
|
||||
{
|
||||
//existingFile.Chapter = Parser.Parser.MinimumNumberFromRange(info.Chapters);
|
||||
existingFile.Format = info.Format;
|
||||
existingFile.NumberOfPages = _archiveService.GetNumberOfPagesFromArchive(info.FullFilePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (info.Format == MangaFormat.Archive)
|
||||
{
|
||||
// existingVolume.Files.Add(CreateMangaFile(info));
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.LogDebug($"Ignoring {info.Filename} as it is not an archive.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
volumes.Add(existingVolume);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create New Volume
|
||||
existingVolume = volumes.SingleOrDefault(v => v.Name == info.Volumes);
|
||||
if (existingVolume != null)
|
||||
{
|
||||
//existingVolume.Files.Add(CreateMangaFile(info));
|
||||
}
|
||||
else
|
||||
{
|
||||
var vol = new Volume()
|
||||
{
|
||||
Name = info.Volumes,
|
||||
Number = Parser.Parser.MinimumNumberFromRange(info.Volumes),
|
||||
// Files = new List<MangaFile>()
|
||||
// {
|
||||
// CreateMangaFile(info)
|
||||
// }
|
||||
};
|
||||
volumes.Add(vol);
|
||||
}
|
||||
}
|
||||
|
||||
_logger.LogInformation($"Adding volume {volumes.Last().Number} with File: {info.Filename}");
|
||||
}
|
||||
|
||||
foreach (var volume in volumes)
|
||||
{
|
||||
// if (forceUpdate || volume.CoverImage == null || !volume.Files.Any())
|
||||
// {
|
||||
// var firstFile = volume.Files.OrderBy(x => x.Chapter).FirstOrDefault();
|
||||
// if (firstFile != null) volume.CoverImage = _archiveService.GetCoverImage(firstFile.FilePath, true);
|
||||
// }
|
||||
|
||||
//volume.Pages = volume.Files.Sum(x => x.NumberOfPages);
|
||||
}
|
||||
|
||||
return volumes;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
|
|
@ -345,7 +254,7 @@ namespace API.Services
|
|||
};
|
||||
|
||||
chapter.Files ??= new List<MangaFile>();
|
||||
var existingFile = chapter?.Files.SingleOrDefault(f => f.FilePath == info.FullFilePath);
|
||||
var existingFile = chapter.Files.SingleOrDefault(f => f.FilePath == info.FullFilePath);
|
||||
if (existingFile != null)
|
||||
{
|
||||
existingFile.Format = info.Format;
|
||||
|
|
@ -376,7 +285,8 @@ namespace API.Services
|
|||
|
||||
if (ShouldFindCoverImage(forceUpdate, chapter.CoverImage))
|
||||
{
|
||||
var firstFile = chapter?.Files.OrderBy(x => x.Chapter).FirstOrDefault();
|
||||
chapter.Files ??= new List<MangaFile>();
|
||||
var firstFile = chapter.Files.OrderBy(x => x.Chapter).FirstOrDefault();
|
||||
if (firstFile != null) chapter.CoverImage = _archiveService.GetCoverImage(firstFile.FilePath, true);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
using API.Interfaces;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using API.Entities;
|
||||
using API.Helpers.Converters;
|
||||
using API.Interfaces;
|
||||
using Hangfire;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
|
|
@ -9,17 +13,30 @@ namespace API.Services
|
|||
private readonly ICacheService _cacheService;
|
||||
private readonly ILogger<TaskScheduler> _logger;
|
||||
private readonly IScannerService _scannerService;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
public BackgroundJobServer Client => new BackgroundJobServer();
|
||||
|
||||
public TaskScheduler(ICacheService cacheService, ILogger<TaskScheduler> logger, IScannerService scannerService)
|
||||
public TaskScheduler(ICacheService cacheService, ILogger<TaskScheduler> logger, IScannerService scannerService, IUnitOfWork unitOfWork)
|
||||
{
|
||||
_cacheService = cacheService;
|
||||
_logger = logger;
|
||||
_scannerService = scannerService;
|
||||
_unitOfWork = unitOfWork;
|
||||
|
||||
_logger.LogInformation("Scheduling/Updating cache cleanup on a daily basis.");
|
||||
RecurringJob.AddOrUpdate(() => _cacheService.Cleanup(), Cron.Daily);
|
||||
RecurringJob.AddOrUpdate(() => _scannerService.ScanLibraries(), Cron.Daily);
|
||||
var setting = Task.Run(() => _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.TaskScan)).Result;
|
||||
if (setting != null)
|
||||
{
|
||||
RecurringJob.AddOrUpdate(() => _scannerService.ScanLibraries(), () => CronConverter.ConvertToCronNotation(setting.Value));
|
||||
}
|
||||
else
|
||||
{
|
||||
RecurringJob.AddOrUpdate(() => _cacheService.Cleanup(), Cron.Daily);
|
||||
RecurringJob.AddOrUpdate(() => _scannerService.ScanLibraries(), Cron.Daily);
|
||||
}
|
||||
|
||||
//JobStorage.Current.GetMonitoringApi().
|
||||
|
||||
}
|
||||
|
||||
public void ScanSeries(int libraryId, int seriesId)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue