Skip to content

Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.

Cleanup after feature implementation.

Joseph Milazzo10c8ea34fe78
diff --git a/API.Tests/Converters/CronConverterTests.cs b/API.Tests/Converters/CronConverterTests.cs
index 6f5cd9419..df1ca6294 100644
--- a/API.Tests/Converters/CronConverterTests.cs
+++ b/API.Tests/Converters/CronConverterTests.cs
@@ -1,7 +1,4 @@
-using System;
-using API.Helpers.Converters;
-using AutoMapper;
-using Hangfire;
+using API.Helpers.Converters;
using Xunit;
using Xunit.Abstractions;
diff --git a/API.Tests/Services/CacheServiceTests.cs b/API.Tests/Services/CacheServiceTests.cs
index 5459133af..4e10cf836 100644
--- a/API.Tests/Services/CacheServiceTests.cs
+++ b/API.Tests/Services/CacheServiceTests.cs
@@ -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;
diff --git a/API.Tests/Services/ScannerServiceTests.cs b/API.Tests/Services/ScannerServiceTests.cs
deleted file mode 100644
index efde36e52..000000000
--- a/API.Tests/Services/ScannerServiceTests.cs
+++ /dev/null
@@ -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);
- // }
-
-
- }
-}
\ No newline at end of file
diff --git a/API/Controllers/LibraryController.cs b/API/Controllers/LibraryController.cs
index 19d7465b1..3ecd6bf8a 100644
--- a/API/Controllers/LibraryController.cs
+++ b/API/Controllers/LibraryController.cs
@@ -145,7 +145,7 @@ namespace API.Controllers
[HttpPost("scan")]
public ActionResult Scan(int libraryId)
{
- _taskScheduler.ScanLibrary(libraryId, false);
+ _taskScheduler.ScanLibrary(libraryId);
return Ok();
}
diff --git a/API/Controllers/ReaderController.cs b/API/Controllers/ReaderController.cs
index cb10f46e5..7c535aa57 100644
--- a/API/Controllers/ReaderController.cs
+++ b/API/Controllers/ReaderController.cs
@@ -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);
diff --git a/API/Controllers/SeriesController.cs b/API/Controllers/SeriesController.cs
index 0e52fbc61..78a16f015 100644
--- a/API/Controllers/SeriesController.cs
+++ b/API/Controllers/SeriesController.cs
@@ -1,5 +1,4 @@
using System.Collections.Generic;
-using System.Linq;
using System.Threading.Tasks;
using API.DTOs;
using API.Entities;
diff --git a/API/Controllers/SettingsController.cs b/API/Controllers/SettingsController.cs
index 2e0f8f57f..eecece06c 100644
--- a/API/Controllers/SettingsController.cs
+++ b/API/Controllers/SettingsController.cs
@@ -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("")]
diff --git a/API/Data/DataContext.cs b/API/Data/DataContext.cs
index b5dd4710d..6aea9a959 100644
--- a/API/Data/DataContext.cs
+++ b/API/Data/DataContext.cs
@@ -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)
diff --git a/API/Data/Seed.cs b/API/Data/Seed.cs
index 9b4a49e6b..c7a216215 100644
--- a/API/Data/Seed.cs
+++ b/API/Data/Seed.cs
@@ -5,7 +5,6 @@ using API.Constants;
using API.Entities;
using API.Services;
using Microsoft.AspNetCore.Identity;
-using Microsoft.EntityFrameworkCore;
namespace API.Data
{
diff --git a/API/Data/SeriesRepository.cs b/API/Data/SeriesRepository.cs
index b188f232c..e682648a6 100644
--- a/API/Data/SeriesRepository.cs
+++ b/API/Data/SeriesRepository.cs
@@ -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)
diff --git a/API/Entities/ServerSetting.cs b/API/Entities/ServerSetting.cs
index a851f834b..148286cdf 100644
--- a/API/Entities/ServerSetting.cs
+++ b/API/Entities/ServerSetting.cs
@@ -1,6 +1,5 @@
using System.ComponentModel.DataAnnotations;
using API.Entities.Interfaces;
-using Microsoft.EntityFrameworkCore;
namespace API.Entities
{
diff --git a/API/Extensions/DirectoryInfoExtensions.cs b/API/Extensions/DirectoryInfoExtensions.cs
index 2e37057da..e7f65dc51 100644
--- a/API/Extensions/DirectoryInfoExtensions.cs
+++ b/API/Extensions/DirectoryInfoExtensions.cs
@@ -1,6 +1,4 @@
-using System;
-using System.Diagnostics;
-using System.IO;
+using System.IO;
namespace API.Extensions
{
diff --git a/API/Interfaces/IDirectoryService.cs b/API/Interfaces/IDirectoryService.cs
index a004ac6e2..539a4c0f6 100644
--- a/API/Interfaces/IDirectoryService.cs
+++ b/API/Interfaces/IDirectoryService.cs
@@ -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 = "");
}
}
\ No newline at end of file
diff --git a/API/Interfaces/IScannerService.cs b/API/Interfaces/IScannerService.cs
index 8d4399eb7..87274e88b 100644
--- a/API/Interfaces/IScannerService.cs
+++ b/API/Interfaces/IScannerService.cs
@@ -1,7 +1,4 @@
-using System.Threading.Tasks;
-using API.DTOs;
-
-namespace API.Interfaces
+namespace API.Interfaces
{
public interface IScannerService
{
diff --git a/API/Interfaces/ISeriesRepository.cs b/API/Interfaces/ISeriesRepository.cs
index 86f3c3387..6b11ecb8f 100644
--- a/API/Interfaces/ISeriesRepository.cs
+++ b/API/Interfaces/ISeriesRepository.cs
@@ -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);
}
}
\ No newline at end of file
diff --git a/API/Program.cs b/API/Program.cs
index 21d37e064..129fbcdc2 100644
--- a/API/Program.cs
+++ b/API/Program.cs
@@ -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>();
diff --git a/API/Services/CacheService.cs b/API/Services/CacheService.cs
index 692be4266..1092c57c1 100644
--- a/API/Services/CacheService.cs
+++ b/API/Services/CacheService.cs
@@ -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);
diff --git a/API/Services/DirectoryService.cs b/API/Services/DirectoryService.cs
index c93485821..96853914f 100644
--- a/API/Services/DirectoryService.cs
+++ b/API/Services/DirectoryService.cs
@@ -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);
}
diff --git a/API/Services/TaskScheduler.cs b/API/Services/TaskScheduler.cs
index 12b1f2f60..0c2a143df 100644
--- a/API/Services/TaskScheduler.cs
+++ b/API/Services/TaskScheduler.cs
@@ -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));