mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-10 23:33:38 -07:00
parent
a602611a5f
commit
a4b78b44ce
1307 changed files with 8702 additions and 7403 deletions
|
@ -2,11 +2,11 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentValidation;
|
||||
using Nancy;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using Lidarr.Http.Extensions;
|
||||
using Newtonsoft.Json;
|
||||
using Nancy;
|
||||
using Nancy.Responses.Negotiation;
|
||||
using Newtonsoft.Json;
|
||||
using NzbDrone.Core.Datastore;
|
||||
|
||||
namespace Lidarr.Http.REST
|
||||
{
|
||||
|
@ -16,7 +16,7 @@ namespace Lidarr.Http.REST
|
|||
private const string ROOT_ROUTE = "/";
|
||||
private const string ID_ROUTE = @"/(?<id>[\d]{1,10})";
|
||||
|
||||
private HashSet<string> EXCLUDED_KEYS = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase)
|
||||
private readonly HashSet<string> _excludedKeys = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase)
|
||||
{
|
||||
"page",
|
||||
"pageSize",
|
||||
|
@ -56,10 +56,12 @@ namespace Lidarr.Http.REST
|
|||
SharedValidator = new ResourceValidator<TResource>();
|
||||
}
|
||||
|
||||
|
||||
private void ValidateModule()
|
||||
{
|
||||
if (GetResourceById != null) return;
|
||||
if (GetResourceById != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (CreateResource != null || UpdateResource != null)
|
||||
{
|
||||
|
@ -69,7 +71,11 @@ namespace Lidarr.Http.REST
|
|||
|
||||
protected Action<int> DeleteResource
|
||||
{
|
||||
private get { return _deleteResource; }
|
||||
private get
|
||||
{
|
||||
return _deleteResource;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_deleteResource = value;
|
||||
|
@ -85,7 +91,11 @@ namespace Lidarr.Http.REST
|
|||
|
||||
protected Func<int, TResource> GetResourceById
|
||||
{
|
||||
get { return _getResourceById; }
|
||||
get
|
||||
{
|
||||
return _getResourceById;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_getResourceById = value;
|
||||
|
@ -113,11 +123,14 @@ namespace Lidarr.Http.REST
|
|||
|
||||
protected Func<List<TResource>> GetResourceAll
|
||||
{
|
||||
private get { return _getResourceAll; }
|
||||
private get
|
||||
{
|
||||
return _getResourceAll;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_getResourceAll = value;
|
||||
|
||||
Get(ROOT_ROUTE, options =>
|
||||
{
|
||||
var resource = GetResourceAll();
|
||||
|
@ -128,11 +141,14 @@ namespace Lidarr.Http.REST
|
|||
|
||||
protected Func<PagingResource<TResource>, PagingResource<TResource>> GetResourcePaged
|
||||
{
|
||||
private get { return _getResourcePaged; }
|
||||
private get
|
||||
{
|
||||
return _getResourcePaged;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_getResourcePaged = value;
|
||||
|
||||
Get(ROOT_ROUTE, options =>
|
||||
{
|
||||
var resource = GetResourcePaged(ReadPagingResourceFromRequest());
|
||||
|
@ -143,11 +159,14 @@ namespace Lidarr.Http.REST
|
|||
|
||||
protected Func<TResource> GetResourceSingle
|
||||
{
|
||||
private get { return _getResourceSingle; }
|
||||
private get
|
||||
{
|
||||
return _getResourceSingle;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_getResourceSingle = value;
|
||||
|
||||
Get(ROOT_ROUTE, options =>
|
||||
{
|
||||
var resource = GetResourceSingle();
|
||||
|
@ -158,7 +177,11 @@ namespace Lidarr.Http.REST
|
|||
|
||||
protected Func<TResource, int> CreateResource
|
||||
{
|
||||
private get { return _createResource; }
|
||||
private get
|
||||
{
|
||||
return _createResource;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_createResource = value;
|
||||
|
@ -167,13 +190,16 @@ namespace Lidarr.Http.REST
|
|||
var id = CreateResource(ReadResourceFromRequest());
|
||||
return ResponseWithCode(GetResourceById(id), HttpStatusCode.Created);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected Action<TResource> UpdateResource
|
||||
{
|
||||
private get { return _updateResource; }
|
||||
private get
|
||||
{
|
||||
return _updateResource;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_updateResource = value;
|
||||
|
@ -183,7 +209,6 @@ namespace Lidarr.Http.REST
|
|||
UpdateResource(resource);
|
||||
return ResponseWithCode(GetResourceById(resource.Id), HttpStatusCode.Accepted);
|
||||
});
|
||||
|
||||
Put(ID_ROUTE, options =>
|
||||
{
|
||||
var resource = ReadResourceFromRequest();
|
||||
|
@ -240,12 +265,17 @@ namespace Lidarr.Http.REST
|
|||
{
|
||||
int pageSize;
|
||||
int.TryParse(Request.Query.PageSize.ToString(), out pageSize);
|
||||
if (pageSize == 0) pageSize = 10;
|
||||
if (pageSize == 0)
|
||||
{
|
||||
pageSize = 10;
|
||||
}
|
||||
|
||||
int page;
|
||||
int.TryParse(Request.Query.Page.ToString(), out page);
|
||||
if (page == 0) page = 1;
|
||||
|
||||
if (page == 0)
|
||||
{
|
||||
page = 1;
|
||||
}
|
||||
|
||||
var pagingResource = new PagingResource<TResource>
|
||||
{
|
||||
|
@ -294,10 +324,9 @@ namespace Lidarr.Http.REST
|
|||
}
|
||||
|
||||
// v3 uses filters in key=value format
|
||||
|
||||
foreach (var key in Request.Query)
|
||||
{
|
||||
if (EXCLUDED_KEYS.Contains(key))
|
||||
if (_excludedKeys.Contains(key))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue