mirror of
https://github.com/Kareadita/Kavita.git
synced 2025-07-09 03:04:19 -04:00
Cleanup after feature implementation.
This commit is contained in:
parent
1050fa4e54
commit
10c8ea34fe
@ -1,7 +1,4 @@
|
||||
using System;
|
||||
using API.Helpers.Converters;
|
||||
using AutoMapper;
|
||||
using Hangfire;
|
||||
using API.Helpers.Converters;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
|
@ -1,6 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using API.Entities;
|
||||
using API.Interfaces;
|
||||
using API.Interfaces;
|
||||
using API.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NSubstitute;
|
||||
|
@ -1,23 +0,0 @@
|
||||
using System.IO;
|
||||
using API.Interfaces;
|
||||
using API.Services;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NSubstitute;
|
||||
using Xunit;
|
||||
|
||||
namespace API.Tests.Services
|
||||
{
|
||||
public class ScannerServiceTests
|
||||
{
|
||||
// private readonly ScannerService _scannerService;
|
||||
// private readonly ILogger<ScannerService> _logger = Substitute.For<ILogger<ScannerService>>();
|
||||
// private readonly IUnitOfWork _unitOfWork = Substitute.For<IUnitOfWork>();
|
||||
// private readonly string _testDirectory = Path.Join(Directory.GetCurrentDirectory(), "../../../Services/Test Data/ScannerService");
|
||||
// public ScannerServiceTests()
|
||||
// {
|
||||
// _scannerService = new ScannerService(_unitOfWork, _logger);
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -145,7 +145,7 @@ namespace API.Controllers
|
||||
[HttpPost("scan")]
|
||||
public ActionResult Scan(int libraryId)
|
||||
{
|
||||
_taskScheduler.ScanLibrary(libraryId, false);
|
||||
_taskScheduler.ScanLibrary(libraryId);
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@ using API.DTOs;
|
||||
using API.Entities;
|
||||
using API.Extensions;
|
||||
using API.Interfaces;
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
@ -18,16 +17,14 @@ namespace API.Controllers
|
||||
private readonly ICacheService _cacheService;
|
||||
private readonly ILogger<ReaderController> _logger;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public ReaderController(IDirectoryService directoryService, ICacheService cacheService,
|
||||
ILogger<ReaderController> logger, IUnitOfWork unitOfWork, IMapper mapper)
|
||||
ILogger<ReaderController> logger, IUnitOfWork unitOfWork)
|
||||
{
|
||||
_directoryService = directoryService;
|
||||
_cacheService = cacheService;
|
||||
_logger = logger;
|
||||
_unitOfWork = unitOfWork;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
[HttpGet("image")]
|
||||
@ -42,7 +39,6 @@ namespace API.Controllers
|
||||
if (string.IsNullOrEmpty(path)) return BadRequest($"No such image for page {page}");
|
||||
var file = await _directoryService.ReadImageAsync(path);
|
||||
file.Page = page;
|
||||
//file.Chapter = chapter.Number;
|
||||
file.MangaFileName = mangaFile.FilePath;
|
||||
|
||||
return Ok(file);
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using API.DTOs;
|
||||
using API.Entities;
|
||||
|
@ -1,7 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
using API.Data;
|
||||
using API.DTOs;
|
||||
using API.Entities;
|
||||
using API.Extensions;
|
||||
@ -16,18 +15,13 @@ namespace API.Controllers
|
||||
[Authorize]
|
||||
public class SettingsController : BaseApiController
|
||||
{
|
||||
private readonly DataContext _dataContext;
|
||||
private readonly ILogger<SettingsController> _logger;
|
||||
private readonly IUnitOfWork _unitOfWork;
|
||||
private readonly ITaskScheduler _taskScheduler;
|
||||
|
||||
public SettingsController(DataContext dataContext, ILogger<SettingsController> logger, IUnitOfWork unitOfWork,
|
||||
ITaskScheduler taskScheduler)
|
||||
public SettingsController(ILogger<SettingsController> logger, IUnitOfWork unitOfWork)
|
||||
{
|
||||
_dataContext = dataContext;
|
||||
_logger = logger;
|
||||
_unitOfWork = unitOfWork;
|
||||
_taskScheduler = taskScheduler;
|
||||
}
|
||||
|
||||
[HttpGet("")]
|
||||
|
@ -33,10 +33,6 @@ namespace API.Data
|
||||
{
|
||||
base.OnModelCreating(builder);
|
||||
|
||||
// builder.Entity<ServerSetting>()
|
||||
// .HasAlternateKey(s => s.Key)
|
||||
// .HasName("AlternateKey_Key");
|
||||
|
||||
builder.Entity<AppUser>()
|
||||
.HasMany(ur => ur.UserRoles)
|
||||
.WithOne(u => u.User)
|
||||
|
@ -5,7 +5,6 @@ using API.Constants;
|
||||
using API.Entities;
|
||||
using API.Services;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Data
|
||||
{
|
||||
|
@ -137,8 +137,6 @@ namespace API.Data
|
||||
var volumeList = new List<VolumeDto>() {volume};
|
||||
await AddVolumeModifiers(userId, volumeList);
|
||||
|
||||
//TODO: volumeList[0].Files = volumeList[0].Files.OrderBy(f => f.Chapter).ToList();
|
||||
|
||||
return volumeList[0];
|
||||
}
|
||||
|
||||
@ -197,8 +195,6 @@ namespace API.Data
|
||||
}
|
||||
|
||||
return chapterIds.ToArray();
|
||||
|
||||
//return series.Select(s => s.Volumes).Select(v => v.Select(v => v.Chapters)).Select(c => c.Id);
|
||||
}
|
||||
|
||||
private async Task AddSeriesModifiers(int userId, List<SeriesDto> series)
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using API.Entities.Interfaces;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace API.Entities
|
||||
{
|
||||
|
@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
|
||||
namespace API.Extensions
|
||||
{
|
||||
|
@ -14,6 +14,12 @@ namespace API.Interfaces
|
||||
IEnumerable<string> ListDirectory(string rootPath);
|
||||
|
||||
Task<ImageDto> ReadImageAsync(string imagePath);
|
||||
string[] GetFiles(string path); // TODO: Refactor. This is currently for CacheServiceTest mocking
|
||||
/// <summary>
|
||||
/// Gets files in a directory. If searchPatternExpression is passed, will match the regex against for filtering.
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="searchPatternExpression"></param>
|
||||
/// <returns></returns>
|
||||
string[] GetFiles(string path, string searchPatternExpression = "");
|
||||
}
|
||||
}
|
@ -1,7 +1,4 @@
|
||||
using System.Threading.Tasks;
|
||||
using API.DTOs;
|
||||
|
||||
namespace API.Interfaces
|
||||
namespace API.Interfaces
|
||||
{
|
||||
public interface IScannerService
|
||||
{
|
||||
|
@ -16,16 +16,12 @@ namespace API.Interfaces
|
||||
Task<IEnumerable<VolumeDto>> GetVolumesDtoAsync(int seriesId, int userId);
|
||||
IEnumerable<Volume> GetVolumes(int seriesId);
|
||||
Task<SeriesDto> GetSeriesDtoByIdAsync(int seriesId, int userId);
|
||||
|
||||
Task<Volume> GetVolumeAsync(int volumeId);
|
||||
Task<VolumeDto> GetVolumeDtoAsync(int volumeId, int userId);
|
||||
|
||||
Task<IEnumerable<Volume>> GetVolumesForSeriesAsync(int[] seriesIds);
|
||||
Task<bool> DeleteSeriesAsync(int seriesId);
|
||||
Task<Volume> GetVolumeByIdAsync(int volumeId);
|
||||
Task<Series> GetSeriesByIdAsync(int seriesId);
|
||||
|
||||
//Task<MangaFileDto> GetVolumeMangaFileDtos(int volumeId);
|
||||
Task<int[]> GetChapterIdsForSeriesAsync(int[] seriesIds);
|
||||
}
|
||||
}
|
@ -44,11 +44,6 @@ namespace API
|
||||
|
||||
private static IHostBuilder CreateHostBuilder(string[] args) =>
|
||||
Host.CreateDefaultBuilder(args)
|
||||
// .ConfigureLogging(logging =>
|
||||
// {
|
||||
// logging.ClearProviders();
|
||||
// logging.AddConsole();
|
||||
// })
|
||||
.ConfigureWebHostDefaults(webBuilder =>
|
||||
{
|
||||
webBuilder.UseStartup<Startup>();
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
@ -110,8 +109,7 @@ namespace API.Services
|
||||
if (page < (mangaFile.NumberOfPages + pagesSoFar))
|
||||
{
|
||||
var path = GetCachePath(chapter.Id);
|
||||
// TODO: GetFiles should only get image files.
|
||||
var files = _directoryService.GetFiles(path);
|
||||
var files = _directoryService.GetFiles(path, Parser.Parser.ImageFileExtensions);
|
||||
Array.Sort(files, _numericComparer);
|
||||
|
||||
return (files.ElementAt(page - pagesSoFar), mangaFile);
|
||||
|
@ -40,8 +40,13 @@ namespace API.Services
|
||||
reSearchPattern.IsMatch(Path.GetExtension(file)));
|
||||
}
|
||||
|
||||
public string[] GetFiles(string path)
|
||||
public string[] GetFiles(string path, string searchPatternExpression = "")
|
||||
{
|
||||
if (searchPatternExpression != string.Empty)
|
||||
{
|
||||
return GetFilesWithCertainExtensions(path, searchPatternExpression).ToArray();
|
||||
}
|
||||
|
||||
return !Directory.Exists(path) ? Array.Empty<string>() : Directory.GetFiles(path);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using API.Entities;
|
||||
using API.Helpers.Converters;
|
||||
using API.Interfaces;
|
||||
@ -13,7 +12,6 @@ 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, IUnitOfWork unitOfWork)
|
||||
@ -21,10 +19,9 @@ namespace API.Services
|
||||
_cacheService = cacheService;
|
||||
_logger = logger;
|
||||
_scannerService = scannerService;
|
||||
_unitOfWork = unitOfWork;
|
||||
|
||||
_logger.LogInformation("Scheduling/Updating cache cleanup on a daily basis.");
|
||||
var setting = Task.Run(() => _unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.TaskScan)).Result;
|
||||
var setting = Task.Run(() => unitOfWork.SettingsRepository.GetSettingAsync(ServerSettingKey.TaskScan)).Result;
|
||||
if (setting != null)
|
||||
{
|
||||
RecurringJob.AddOrUpdate(() => _scannerService.ScanLibraries(), () => CronConverter.ConvertToCronNotation(setting.Value));
|
||||
|
Loading…
x
Reference in New Issue
Block a user