New: Use ASP.NET Core instead of Nancy

This commit is contained in:
ta264
2021-03-11 20:56:24 +00:00
parent d348232e0d
commit 58ddbcd77e
158 changed files with 2747 additions and 3544 deletions
@@ -1,18 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Nancy;
using Microsoft.AspNetCore.Mvc;
using NLog;
using NzbDrone.Core.Books;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MediaFiles.BookImport.Manual;
using NzbDrone.Core.Qualities;
using Readarr.Http;
using Readarr.Http.Extensions;
namespace Readarr.Api.V1.ManualImport
{
public class ManualImportModule : ReadarrRestModule<ManualImportResource>
[V1ApiController]
public class ManualImportController : Controller
{
private readonly IAuthorService _authorService;
private readonly IBookService _bookService;
@@ -20,7 +19,7 @@ namespace Readarr.Api.V1.ManualImport
private readonly IManualImportService _manualImportService;
private readonly Logger _logger;
public ManualImportModule(IManualImportService manualImportService,
public ManualImportController(IManualImportService manualImportService,
IAuthorService authorService,
IEditionService editionService,
IBookService bookService,
@@ -31,31 +30,25 @@ namespace Readarr.Api.V1.ManualImport
_editionService = editionService;
_manualImportService = manualImportService;
_logger = logger;
GetResourceAll = GetMediaFiles;
Put("/", options =>
{
var resource = Request.Body.FromJson<List<ManualImportResource>>();
return ResponseWithCode(UpdateImportItems(resource), HttpStatusCode.Accepted);
});
}
private List<ManualImportResource> GetMediaFiles()
[HttpPut]
public IActionResult UpdateItems(List<ManualImportResource> resource)
{
return Accepted(UpdateImportItems(resource));
}
[HttpGet]
public List<ManualImportResource> GetMediaFiles(string folder, string downloadId, int? authorId, bool filterExistingFiles = true, bool replaceExistingFiles = true)
{
var folder = (string)Request.Query.folder;
var downloadId = (string)Request.Query.downloadId;
NzbDrone.Core.Books.Author author = null;
var authorIdQuery = Request.GetNullableIntegerQueryParameter("authorId", null);
if (authorIdQuery.HasValue && authorIdQuery.Value > 0)
if (authorId > 0)
{
author = _authorService.GetAuthor(Convert.ToInt32(authorIdQuery.Value));
author = _authorService.GetAuthor(authorId.Value);
}
var filter = Request.GetBooleanQueryParameter("filterExistingFiles", true) ? FilterFilesType.Matched : FilterFilesType.None;
var replaceExistingFiles = Request.GetBooleanQueryParameter("replaceExistingFiles", true);
var filter = filterExistingFiles ? FilterFilesType.Matched : FilterFilesType.None;
return _manualImportService.GetMediaFiles(folder, downloadId, author, filter, replaceExistingFiles).ToResource().Select(AddQualityWeight).ToList();
}