diff --git a/frontend/src/Utilities/createAjaxRequest.js b/frontend/src/Utilities/createAjaxRequest.js index 72d759b22..02773f63e 100644 --- a/frontend/src/Utilities/createAjaxRequest.js +++ b/frontend/src/Utilities/createAjaxRequest.js @@ -40,7 +40,7 @@ export default function createAjaxRequest(originalAjaxOptions) { } } - const ajaxOptions = { ...originalAjaxOptions }; + const ajaxOptions = { dataType: 'json', ...originalAjaxOptions }; if (isRelative(ajaxOptions)) { moveBodyToQuery(ajaxOptions); diff --git a/src/NzbDrone.Api/Calendar/CalendarFeedModule.cs b/src/NzbDrone.Api/Calendar/CalendarFeedModule.cs index aae8630a2..9a2bfec9b 100644 --- a/src/NzbDrone.Api/Calendar/CalendarFeedModule.cs +++ b/src/NzbDrone.Api/Calendar/CalendarFeedModule.cs @@ -26,12 +26,12 @@ namespace NzbDrone.Api.Calendar _movieService = movieService; _tagService = tagService; - Get["/NzbDrone.ics"] = options => GetCalendarFeed(); - Get["/Sonarr.ics"] = options => GetCalendarFeed(); - Get["/Radarr.ics"] = options => GetCalendarFeed(); + Get("/NzbDrone.ics", options => GetCalendarFeed()); + Get("/Sonarr.ics", options => GetCalendarFeed()); + Get("/Radarr.ics", options => GetCalendarFeed()); } - private Response GetCalendarFeed() + private object GetCalendarFeed() { var pastDays = 7; var futureDays = 28; diff --git a/src/NzbDrone.Api/Config/NamingConfigModule.cs b/src/NzbDrone.Api/Config/NamingConfigModule.cs index 77422568c..8047eed0f 100644 --- a/src/NzbDrone.Api/Config/NamingConfigModule.cs +++ b/src/NzbDrone.Api/Config/NamingConfigModule.cs @@ -2,13 +2,10 @@ using System.Collections.Generic; using System.Linq; using FluentValidation; using FluentValidation.Results; -using Nancy.Responses; using NzbDrone.Common.Extensions; using NzbDrone.Core.Organizer; using Nancy.ModelBinding; -using Radarr.Http.Extensions; using Radarr.Http; -using Radarr.Http.Mapping; namespace NzbDrone.Api.Config { @@ -33,7 +30,7 @@ namespace NzbDrone.Api.Config GetResourceById = GetNamingConfig; UpdateResource = UpdateNamingConfig; - Get["/samples"] = x => GetExamples(this.Bind()); + Get("/samples", x => GetExamples(this.Bind())); SharedValidator.RuleFor(c => c.MultiEpisodeStyle).InclusiveBetween(0, 5); SharedValidator.RuleFor(c => c.StandardMovieFormat).ValidMovieFormat(); @@ -67,7 +64,7 @@ namespace NzbDrone.Api.Config return GetNamingConfig(); } - private JsonResponse GetExamples(NamingConfigResource config) + private object GetExamples(NamingConfigResource config) { var nameSpec = config.ToModel(); var sampleResource = new NamingSampleResource(); @@ -82,7 +79,7 @@ namespace NzbDrone.Api.Config ? "Invalid format" : _filenameSampleService.GetMovieFolderSample(nameSpec); - return sampleResource.AsResponse(); + return sampleResource; } private void ValidateFormatResult(NamingConfig nameSpec) diff --git a/src/NzbDrone.Api/FileSystem/FileSystemModule.cs b/src/NzbDrone.Api/FileSystem/FileSystemModule.cs index 47c2773e2..34b859e13 100644 --- a/src/NzbDrone.Api/FileSystem/FileSystemModule.cs +++ b/src/NzbDrone.Api/FileSystem/FileSystemModule.cs @@ -23,49 +23,49 @@ namespace NzbDrone.Api.FileSystem _fileSystemLookupService = fileSystemLookupService; _diskProvider = diskProvider; _diskScanService = diskScanService; - Get["/"] = x => GetContents(); - Get["/type"] = x => GetEntityType(); - Get["/mediafiles"] = x => GetMediaFiles(); + Get("/", x => GetContents()); + Get("/type", x => GetEntityType()); + Get("/mediafiles", x => GetMediaFiles()); } - private Response GetContents() + private object GetContents() { var pathQuery = Request.Query.path; var includeFiles = Request.GetBooleanQueryParameter("includeFiles"); var allowFoldersWithoutTrailingSlashes = Request.GetBooleanQueryParameter("allowFoldersWithoutTrailingSlashes"); - return _fileSystemLookupService.LookupContents((string)pathQuery.Value, includeFiles, allowFoldersWithoutTrailingSlashes).AsResponse(); + return _fileSystemLookupService.LookupContents((string)pathQuery.Value, includeFiles, allowFoldersWithoutTrailingSlashes); } - private Response GetEntityType() + private object GetEntityType() { var pathQuery = Request.Query.path; var path = (string)pathQuery.Value; if (_diskProvider.FileExists(path)) { - return new { type = "file" }.AsResponse(); + return new { type = "file" }; } //Return folder even if it doesn't exist on disk to avoid leaking anything from the UI about the underlying system - return new { type = "folder" }.AsResponse(); + return new { type = "folder" }; } - private Response GetMediaFiles() + private object GetMediaFiles() { var pathQuery = Request.Query.path; var path = (string)pathQuery.Value; if (!_diskProvider.FolderExists(path)) { - return new string[0].AsResponse(); + return new string[0]; } return _diskScanService.GetVideoFiles(path).Select(f => new { Path = f, RelativePath = path.GetRelativePath(f), Name = Path.GetFileName(f) - }).AsResponse(); + }); } } } diff --git a/src/NzbDrone.Api/History/HistoryModule.cs b/src/NzbDrone.Api/History/HistoryModule.cs index abcc2ad2c..76325d82e 100644 --- a/src/NzbDrone.Api/History/HistoryModule.cs +++ b/src/NzbDrone.Api/History/HistoryModule.cs @@ -27,7 +27,7 @@ namespace NzbDrone.Api.History _failedDownloadService = failedDownloadService; GetResourcePaged = GetHistory; - Post["/failed"] = x => MarkAsFailed(); + Post("/failed", x => MarkAsFailed()); } protected HistoryResource MapToResource(Core.History.History model) @@ -64,11 +64,11 @@ namespace NzbDrone.Api.History return ApplyToPage(_historyService.Paged, pagingSpec, MapToResource); } - private Response MarkAsFailed() + private object MarkAsFailed() { var id = (int)Request.Form.Id; _failedDownloadService.MarkAsFailed(id); - return new object().AsResponse(); + return new object(); } } } diff --git a/src/NzbDrone.Api/Indexers/ReleaseModule.cs b/src/NzbDrone.Api/Indexers/ReleaseModule.cs index b00290830..6042e9c32 100644 --- a/src/NzbDrone.Api/Indexers/ReleaseModule.cs +++ b/src/NzbDrone.Api/Indexers/ReleaseModule.cs @@ -43,7 +43,7 @@ namespace NzbDrone.Api.Indexers _logger = logger; GetResourceAll = GetReleases; - Post["/"] = x => DownloadRelease(this.Bind()); + Post("/", x => DownloadRelease(this.Bind())); //PostValidator.RuleFor(s => s.DownloadAllowed).Equal(true); PostValidator.RuleFor(s => s.Guid).NotEmpty(); @@ -51,7 +51,7 @@ namespace NzbDrone.Api.Indexers _remoteMovieCache = cacheManager.GetCache(GetType(), "remoteMovies"); } - private Response DownloadRelease(ReleaseResource release) + private object DownloadRelease(ReleaseResource release) { var remoteMovie = _remoteMovieCache.Find(release.Guid); @@ -71,7 +71,7 @@ namespace NzbDrone.Api.Indexers throw new NzbDroneClientException(HttpStatusCode.Conflict, "Getting release from indexer failed"); } - return release.AsResponse(); + return release; } private List GetReleases() diff --git a/src/NzbDrone.Api/Indexers/ReleasePushModule.cs b/src/NzbDrone.Api/Indexers/ReleasePushModule.cs index 44abbba4e..88b62bac2 100644 --- a/src/NzbDrone.Api/Indexers/ReleasePushModule.cs +++ b/src/NzbDrone.Api/Indexers/ReleasePushModule.cs @@ -30,7 +30,7 @@ namespace NzbDrone.Api.Indexers _indexerFactory = indexerFactory; _logger = logger; - Post["/push"] = x => ProcessRelease(ReadResourceFromRequest()); + Post("/push", x => ProcessRelease(ReadResourceFromRequest())); PostValidator.RuleFor(s => s.Title).NotEmpty(); PostValidator.RuleFor(s => s.DownloadUrl).NotEmpty(); @@ -38,7 +38,7 @@ namespace NzbDrone.Api.Indexers PostValidator.RuleFor(s => s.PublishDate).NotEmpty(); } - private Response ProcessRelease(ReleaseResource release) + private object ProcessRelease(ReleaseResource release) { _logger.Info("Release pushed: {0} - {1}", release.Title, release.DownloadUrl); @@ -51,7 +51,7 @@ namespace NzbDrone.Api.Indexers var decisions = _downloadDecisionMaker.GetRssDecision(new List { info }); _downloadDecisionProcessor.ProcessDecisions(decisions); - return MapDecisions(decisions).First().AsResponse(); + return MapDecisions(decisions).First(); } private void ResolveIndexer(ReleaseInfo release) diff --git a/src/NzbDrone.Api/Logs/LogFileModuleBase.cs b/src/NzbDrone.Api/Logs/LogFileModuleBase.cs index 8e78848c5..b43dce781 100644 --- a/src/NzbDrone.Api/Logs/LogFileModuleBase.cs +++ b/src/NzbDrone.Api/Logs/LogFileModuleBase.cs @@ -26,7 +26,7 @@ namespace NzbDrone.Api.Logs _configFileProvider = configFileProvider; GetResourceAll = GetLogFilesResponse; - Get[LOGFILE_ROUTE] = options => GetLogFileResponse(options.filename); + Get(LOGFILE_ROUTE, options => GetLogFileResponse(options.filename)); } private List GetLogFilesResponse() @@ -53,7 +53,7 @@ namespace NzbDrone.Api.Logs return result.OrderByDescending(l => l.LastWriteTime).ToList(); } - private Response GetLogFileResponse(string filename) + private object GetLogFileResponse(string filename) { LogManager.Flush(); diff --git a/src/NzbDrone.Api/MediaCovers/MediaCoverModule.cs b/src/NzbDrone.Api/MediaCovers/MediaCoverModule.cs index a4ad78ef4..26391be9a 100644 --- a/src/NzbDrone.Api/MediaCovers/MediaCoverModule.cs +++ b/src/NzbDrone.Api/MediaCovers/MediaCoverModule.cs @@ -22,10 +22,10 @@ namespace NzbDrone.Api.MediaCovers _appFolderInfo = appFolderInfo; _diskProvider = diskProvider; - Get[MEDIA_COVER_ROUTE] = options => GetMediaCover(options.seriesId, options.filename); + Get(MEDIA_COVER_ROUTE, options => GetMediaCover(options.seriesId, options.filename)); } - private Response GetMediaCover(int seriesId, string filename) + private object GetMediaCover(int seriesId, string filename) { var filePath = Path.Combine(_appFolderInfo.GetAppDataPath(), "MediaCover", seriesId.ToString(), filename); diff --git a/src/NzbDrone.Api/Movies/FetchMovieListModule.cs b/src/NzbDrone.Api/Movies/FetchMovieListModule.cs index 953a9bd27..8ef4c791b 100644 --- a/src/NzbDrone.Api/Movies/FetchMovieListModule.cs +++ b/src/NzbDrone.Api/Movies/FetchMovieListModule.cs @@ -19,11 +19,11 @@ namespace NzbDrone.Api.Movies { _fetchNetImport = netImport; _movieSearch = movieSearch; - Get["/"] = x => Search(); + Get("/", x => Search()); } - private Response Search() + private object Search() { var results = _fetchNetImport.FetchAndFilter((int) Request.Query.listId, false); @@ -39,7 +39,7 @@ namespace NzbDrone.Api.Movies } }*/ - return MapToResource(results).AsResponse(); + return MapToResource(results); } diff --git a/src/NzbDrone.Api/Movies/MovieBulkImportModule.cs b/src/NzbDrone.Api/Movies/MovieBulkImportModule.cs index ea71e8a12..81a04fa0d 100644 --- a/src/NzbDrone.Api/Movies/MovieBulkImportModule.cs +++ b/src/NzbDrone.Api/Movies/MovieBulkImportModule.cs @@ -53,11 +53,11 @@ namespace NzbDrone.Api.Movies _movieService = movieService; _profileService = profileService; _parsingService = parsingService; - Get["/"] = x => Search(); + Get("/", x => Search()); } - private Response Search() + private object Search() { if (Request.Query.Id == 0) { @@ -166,7 +166,7 @@ namespace NzbDrone.Api.Movies SortKey = Request.Query.sort_by, TotalRecords = total_count - mapped.Where(m => m == null).Count(), Records = MapToResource(mapped.Where(m => m != null)).ToList() - }.AsResponse(); + }; } diff --git a/src/NzbDrone.Api/Movies/MovieDiscoverModule.cs b/src/NzbDrone.Api/Movies/MovieDiscoverModule.cs index 40db69bda..acf0eeb8a 100644 --- a/src/NzbDrone.Api/Movies/MovieDiscoverModule.cs +++ b/src/NzbDrone.Api/Movies/MovieDiscoverModule.cs @@ -21,17 +21,17 @@ namespace NzbDrone.Api.Movies { _searchProxy = searchProxy; _netImportFactory = netImportFactory; - Get["/lists"] = x => GetLists(); - Get["/{action?recommendations}"] = x => Search(x.action); + Get("/lists", x => GetLists()); + Get("/{action?recommendations}", x => Search(x.action)); } - private Response Search(string action) + private object Search(string action) { var imdbResults = _searchProxy.DiscoverNewMovies(action); - return MapToResource(imdbResults).AsResponse(); + return MapToResource(imdbResults); } - private Response GetLists() + private object GetLists() { var lists = _netImportFactory.Discoverable(); @@ -42,7 +42,7 @@ namespace NzbDrone.Api.Movies resource.Name = definition.Definition.Name; return resource; - }).AsResponse(); + }); } private static IEnumerable MapToResource(IEnumerable movies) diff --git a/src/NzbDrone.Api/Movies/MovieEditorModule.cs b/src/NzbDrone.Api/Movies/MovieEditorModule.cs index db7721fcf..f63154daf 100644 --- a/src/NzbDrone.Api/Movies/MovieEditorModule.cs +++ b/src/NzbDrone.Api/Movies/MovieEditorModule.cs @@ -18,22 +18,22 @@ namespace NzbDrone.Api.Movies : base("/movie/editor") { _movieService = movieService; - Put["/"] = Movie => SaveAll(); - Put["/delete"] = Movie => DeleteSelected(); + Put("/", Movie => SaveAll()); + Put("/delete", Movie => DeleteSelected()); } - private Response SaveAll() + private object SaveAll() { var resources = Request.Body.FromJson>(); var Movie = resources.Select(MovieResource => MovieResource.ToModel(_movieService.GetMovie(MovieResource.Id))).ToList(); - return _movieService.UpdateMovie(Movie) + return ResponseWithCode(_movieService.UpdateMovie(Movie) .ToResource() - .AsResponse(HttpStatusCode.Accepted); + , HttpStatusCode.Accepted); } - private Response DeleteSelected() + private object DeleteSelected() { var deleteFiles = false; var addExclusion = false; diff --git a/src/NzbDrone.Api/Movies/MovieLookupModule.cs b/src/NzbDrone.Api/Movies/MovieLookupModule.cs index a2f02c545..b5b7f0f35 100644 --- a/src/NzbDrone.Api/Movies/MovieLookupModule.cs +++ b/src/NzbDrone.Api/Movies/MovieLookupModule.cs @@ -20,34 +20,34 @@ namespace NzbDrone.Api.Movies { _movieInfo = movieInfo; _searchProxy = searchProxy; - Get["/"] = x => Search(); - Get["/tmdb"] = x => SearchByTmdbId(); - Get["/imdb"] = x => SearchByImdbId(); + Get("/", x => Search()); + Get("/tmdb", x => SearchByTmdbId()); + Get("/imdb", x => SearchByImdbId()); } - private Response SearchByTmdbId() + private object SearchByTmdbId() { int tmdbId = -1; if(Int32.TryParse(Request.Query.tmdbId, out tmdbId)) { var result = _movieInfo.GetMovieInfo(tmdbId, null, true); - return result.ToResource().AsResponse(); + return result.ToResource(); } throw new BadRequestException("Tmdb Id was not valid"); } - private Response SearchByImdbId() + private object SearchByImdbId() { string imdbId = Request.Query.imdbId; var result = _movieInfo.GetMovieInfo(imdbId); - return result.ToResource().AsResponse(); + return result.ToResource(); } - private Response Search() + private object Search() { var imdbResults = _searchProxy.SearchForNewMovie((string)Request.Query.term); - return MapToResource(imdbResults).AsResponse(); + return MapToResource(imdbResults); } private static IEnumerable MapToResource(IEnumerable movies) diff --git a/src/NzbDrone.Api/Movies/MovieModule.cs b/src/NzbDrone.Api/Movies/MovieModule.cs index 18c07c241..6915204a8 100644 --- a/src/NzbDrone.Api/Movies/MovieModule.cs +++ b/src/NzbDrone.Api/Movies/MovieModule.cs @@ -54,7 +54,8 @@ namespace NzbDrone.Api.Movies GetResourceAll = AllMovie; GetResourceById = GetMovie; - Get[TITLE_SLUG_ROUTE] = GetByTitleSlug; + Get(TITLE_SLUG_ROUTE, GetByTitleSlug); + CreateResource = AddMovie; UpdateResource = UpdateMovie; DeleteResource = DeleteMovie; @@ -105,7 +106,7 @@ namespace NzbDrone.Api.Movies return moviesResources; } - private Response GetByTitleSlug(dynamic options) + private object GetByTitleSlug(dynamic options) { string slug; try @@ -120,7 +121,7 @@ namespace NzbDrone.Api.Movies try { - return MapToResource(_moviesService.FindByTitleSlug(slug)).AsResponse(HttpStatusCode.OK); + return ResponseWithCode(MapToResource(_moviesService.FindByTitleSlug(slug)), HttpStatusCode.OK); } catch (ModelNotFoundException) { diff --git a/src/NzbDrone.Api/NetImport/ListImportModule.cs b/src/NzbDrone.Api/NetImport/ListImportModule.cs index 78c0fc538..a8d2eca3c 100644 --- a/src/NzbDrone.Api/NetImport/ListImportModule.cs +++ b/src/NzbDrone.Api/NetImport/ListImportModule.cs @@ -19,16 +19,16 @@ namespace NzbDrone.Api.NetImport { _movieService = movieService; _movieSearch = movieSearch; - Put["/"] = Movie => SaveAll(); + Put("/", Movie => SaveAll()); } - private Response SaveAll() + private object SaveAll() { var resources = Request.Body.FromJson>(); var Movies = resources.Select(MovieResource => _movieSearch.MapMovieToTmdbMovie(MovieResource.ToModel())).Where(m => m != null).DistinctBy(m => m.TmdbId).ToList(); - return _movieService.AddMovies(Movies).ToResource().AsResponse(HttpStatusCode.Accepted); + return ResponseWithCode(_movieService.AddMovies(Movies).ToResource(), HttpStatusCode.Accepted); } } } diff --git a/src/NzbDrone.Api/NzbDroneApiModule.cs b/src/NzbDrone.Api/NzbDroneApiModule.cs index ad8131487..4ec87a867 100644 --- a/src/NzbDrone.Api/NzbDroneApiModule.cs +++ b/src/NzbDrone.Api/NzbDroneApiModule.cs @@ -1,12 +1,12 @@ -using Nancy; +using Radarr.Http; namespace NzbDrone.Api { - public abstract class NzbDroneApiModule : NancyModule + public abstract class NzbDroneApiModule : RadarrModule { protected NzbDroneApiModule(string resource) : base("/api/" + resource.Trim('/')) { } } -} \ No newline at end of file +} diff --git a/src/NzbDrone.Api/NzbDroneFeedModule.cs b/src/NzbDrone.Api/NzbDroneFeedModule.cs index d79307bef..794ef6583 100644 --- a/src/NzbDrone.Api/NzbDroneFeedModule.cs +++ b/src/NzbDrone.Api/NzbDroneFeedModule.cs @@ -1,12 +1,12 @@ -using Nancy; +using Radarr.Http; namespace NzbDrone.Api { - public abstract class NzbDroneFeedModule : NancyModule + public abstract class NzbDroneFeedModule : RadarrModule { protected NzbDroneFeedModule(string resource) : base("/feed/" + resource.Trim('/')) { } } -} \ No newline at end of file +} diff --git a/src/NzbDrone.Api/Profiles/LegacyProfileModule.cs b/src/NzbDrone.Api/Profiles/LegacyProfileModule.cs index d0e6b744e..0e704aa43 100644 --- a/src/NzbDrone.Api/Profiles/LegacyProfileModule.cs +++ b/src/NzbDrone.Api/Profiles/LegacyProfileModule.cs @@ -8,13 +8,13 @@ namespace NzbDrone.Api.Profiles public LegacyProfileModule() : base("qualityprofile") { - Get["/"] = x => + Get("/", x => { string queryString = ConvertQueryParams(Request.Query); var url = string.Format("/api/profile?{0}", queryString); return Response.AsRedirect(url); - }; + }); } private string ConvertQueryParams(DynamicDictionary query) diff --git a/src/NzbDrone.Api/ProviderModuleBase.cs b/src/NzbDrone.Api/ProviderModuleBase.cs index c7a09ea05..9c825e743 100644 --- a/src/NzbDrone.Api/ProviderModuleBase.cs +++ b/src/NzbDrone.Api/ProviderModuleBase.cs @@ -26,9 +26,9 @@ namespace NzbDrone.Api { _providerFactory = providerFactory; - Get["schema"] = x => GetTemplates(); - Post["test"] = x => Test(ReadResourceFromRequest(true)); - Post["action/{action}"] = x => RequestAction(x.action, ReadResourceFromRequest(true)); + Get("schema", x => GetTemplates()); + Post("test", x => Test(ReadResourceFromRequest(true))); + Post("action/{action}", x => RequestAction(x.action, ReadResourceFromRequest(true))); GetResourceAll = GetAll; GetResourceById = GetProviderById; @@ -145,7 +145,7 @@ namespace NzbDrone.Api _providerFactory.Delete(id); } - private Response GetTemplates() + private object GetTemplates() { var defaultDefinitions = _providerFactory.GetDefaultDefinitions().OrderBy(p => p.ImplementationName).ToList(); @@ -169,10 +169,10 @@ namespace NzbDrone.Api result.Add(providerResource); } - return result.AsResponse(); + return result; } - private Response Test(TProviderResource providerResource) + private object Test(TProviderResource providerResource) { // Don't validate when getting the definition so we can validate afterwards (avoids validation being skipped because the provider is disabled) var providerDefinition = GetDefinition(providerResource, true, false); @@ -184,7 +184,7 @@ namespace NzbDrone.Api } - private Response RequestAction(string action, TProviderResource providerResource) + private object RequestAction(string action, TProviderResource providerResource) { var providerDefinition = GetDefinition(providerResource, true, false); diff --git a/src/NzbDrone.Api/Qualities/CustomFormatModule.cs b/src/NzbDrone.Api/Qualities/CustomFormatModule.cs index e04cfc05c..7f1101500 100644 --- a/src/NzbDrone.Api/Qualities/CustomFormatModule.cs +++ b/src/NzbDrone.Api/Qualities/CustomFormatModule.cs @@ -48,11 +48,11 @@ namespace NzbDrone.Api.Qualities DeleteResource = DeleteFormat; - Get["/test"] = x => Test(); + Get("/test", x => Test()); - Post["/test"] = x => TestWithNewModel(); + Post("/test", x => TestWithNewModel()); - Get["schema"] = x => GetTemplates(); + Get("schema", x => GetTemplates()); } private int Create(CustomFormatResource customFormatResource) @@ -82,7 +82,7 @@ namespace NzbDrone.Api.Qualities _formatService.Delete(id); } - private Response GetTemplates() + private object GetTemplates() { return CustomFormatService.Templates.SelectMany(t => { @@ -92,7 +92,7 @@ namespace NzbDrone.Api.Qualities r.Simplicity = t.Key; return r; }); - }).AsResponse(); + }); } private CustomFormatTestResource Test() diff --git a/src/NzbDrone.Api/Queue/QueueActionModule.cs b/src/NzbDrone.Api/Queue/QueueActionModule.cs index 2932757f8..60384a7d7 100644 --- a/src/NzbDrone.Api/Queue/QueueActionModule.cs +++ b/src/NzbDrone.Api/Queue/QueueActionModule.cs @@ -1,6 +1,5 @@ using System; using Nancy; -using Nancy.Responses; using Radarr.Http.Extensions; using Radarr.Http.REST; using NzbDrone.Core.Download; @@ -37,12 +36,12 @@ namespace NzbDrone.Api.Queue _pendingReleaseService = pendingReleaseService; _downloadService = downloadService; - Delete[@"/(?[\d]{1,10})"] = x => Remove((int)x.Id); - Post["/import"] = x => Import(); - Post["/grab"] = x => Grab(); + Delete(@"/(?[\d]{1,10})", x => Remove((int)x.Id)); + Post("/import", x => Import()); + Post("/grab", x => Grab()); } - private Response Remove(int id) + private object Remove(int id) { var blacklist = false; var blacklistQuery = Request.Query.blacklist; @@ -58,7 +57,7 @@ namespace NzbDrone.Api.Queue { _pendingReleaseService.RemovePendingQueueItems(pendingRelease.Id); - return new object().AsResponse(); + return new object(); } var trackedDownload = GetTrackedDownload(id); @@ -82,20 +81,20 @@ namespace NzbDrone.Api.Queue _failedDownloadService.MarkAsFailed(trackedDownload.DownloadItem.DownloadId); } - return new object().AsResponse(); + return new object(); } - private JsonResponse Import() + private object Import() { var resource = Request.Body.FromJson(); var trackedDownload = GetTrackedDownload(resource.Id); _completedDownloadService.Process(trackedDownload, true); - return resource.AsResponse(); + return resource; } - private JsonResponse Grab() + private object Grab() { var resource = Request.Body.FromJson(); @@ -108,7 +107,7 @@ namespace NzbDrone.Api.Queue _downloadService.DownloadReport(pendingRelease.RemoteMovie); - return resource.AsResponse(); + return resource; } private TrackedDownload GetTrackedDownload(int queueId) diff --git a/src/NzbDrone.Api/Radarr.Api.csproj b/src/NzbDrone.Api/Radarr.Api.csproj index b428c589f..1b30f0855 100644 --- a/src/NzbDrone.Api/Radarr.Api.csproj +++ b/src/NzbDrone.Api/Radarr.Api.csproj @@ -6,13 +6,13 @@ - - - + + + - \ No newline at end of file + diff --git a/src/NzbDrone.Api/System/SystemModule.cs b/src/NzbDrone.Api/System/SystemModule.cs index cb364abb0..1108f1b38 100644 --- a/src/NzbDrone.Api/System/SystemModule.cs +++ b/src/NzbDrone.Api/System/SystemModule.cs @@ -37,13 +37,13 @@ namespace NzbDrone.Api.System _configFileProvider = configFileProvider; _database = database; _lifecycleService = lifecycleService; - Get["/status"] = x => GetStatus(); - Get["/routes"] = x => GetRoutes(); - Post["/shutdown"] = x => Shutdown(); - Post["/restart"] = x => Restart(); + Get("/status", x => GetStatus()); + Get("/routes", x => GetRoutes()); + Post("/shutdown", x => Shutdown()); + Post("/restart", x => Restart()); } - private Response GetStatus() + private object GetStatus() { return new { @@ -68,24 +68,24 @@ namespace NzbDrone.Api.System UrlBase = _configFileProvider.UrlBase, RuntimeVersion = _platformInfo.Version, RuntimeName = PlatformInfo.Platform - }.AsResponse(); + }; } - private Response GetRoutes() + private object GetRoutes() { - return _routeCacheProvider.GetCache().Values.AsResponse(); + return _routeCacheProvider.GetCache().Values; } - private Response Shutdown() + private object Shutdown() { _lifecycleService.Shutdown(); - return "".AsResponse(); + return ""; } - private Response Restart() + private object Restart() { _lifecycleService.Restart(); - return "".AsResponse(); + return ""; } } } diff --git a/src/NzbDrone.Api/Wanted/LegacyMissingModule.cs b/src/NzbDrone.Api/Wanted/LegacyMissingModule.cs index a5a503a5d..002ecf179 100644 --- a/src/NzbDrone.Api/Wanted/LegacyMissingModule.cs +++ b/src/NzbDrone.Api/Wanted/LegacyMissingModule.cs @@ -7,13 +7,13 @@ namespace NzbDrone.Api.Wanted { public LegacyMissingModule() : base("missing") { - Get["/"] = x => + Get("/", x => { string queryString = ConvertQueryParams(Request.Query); var url = string.Format("/api/wanted/missing?{0}", queryString); return Response.AsRedirect(url); - }; + }); } private string ConvertQueryParams(DynamicDictionary query) diff --git a/src/NzbDrone.Host/MainAppContainerBuilder.cs b/src/NzbDrone.Host/MainAppContainerBuilder.cs index 5dab4fb81..454c254c1 100644 --- a/src/NzbDrone.Host/MainAppContainerBuilder.cs +++ b/src/NzbDrone.Host/MainAppContainerBuilder.cs @@ -3,7 +3,6 @@ using Nancy.Bootstrapper; using Radarr.Http; using NzbDrone.Common.Composition; using NzbDrone.Common.EnvironmentInfo; -using NzbDrone.Common.Http.Dispatchers; using NzbDrone.SignalR; namespace Radarr.Host diff --git a/src/NzbDrone.Host/Radarr.Host.csproj b/src/NzbDrone.Host/Radarr.Host.csproj index bdffbaaee..0ccddfced 100644 --- a/src/NzbDrone.Host/Radarr.Host.csproj +++ b/src/NzbDrone.Host/Radarr.Host.csproj @@ -5,7 +5,7 @@ - + @@ -23,4 +23,4 @@ - \ No newline at end of file + diff --git a/src/Radarr.Api.V2/Calendar/CalendarFeedModule.cs b/src/Radarr.Api.V2/Calendar/CalendarFeedModule.cs index 6c8e0ded3..30ac460cc 100644 --- a/src/Radarr.Api.V2/Calendar/CalendarFeedModule.cs +++ b/src/Radarr.Api.V2/Calendar/CalendarFeedModule.cs @@ -26,10 +26,10 @@ namespace Radarr.Api.V2.Calendar _movieService = movieService; _tagService = tagService; - Get["/Radarr.ics"] = options => GetCalendarFeed(); + Get("/Radarr.ics", options => GetCalendarFeed()); } - private Response GetCalendarFeed() + private object GetCalendarFeed() { var pastDays = 7; var futureDays = 28; diff --git a/src/Radarr.Api.V2/Config/NamingConfigModule.cs b/src/Radarr.Api.V2/Config/NamingConfigModule.cs index fd50c8980..e500842b1 100644 --- a/src/Radarr.Api.V2/Config/NamingConfigModule.cs +++ b/src/Radarr.Api.V2/Config/NamingConfigModule.cs @@ -2,13 +2,10 @@ using System.Collections.Generic; using System.Linq; using FluentValidation; using FluentValidation.Results; -using Nancy.Responses; using NzbDrone.Common.Extensions; using NzbDrone.Core.Organizer; using Nancy.ModelBinding; -using Radarr.Http.Extensions; using Radarr.Http; -using Radarr.Http.Mapping; namespace Radarr.Api.V2.Config { @@ -33,7 +30,7 @@ namespace Radarr.Api.V2.Config GetResourceById = GetNamingConfig; UpdateResource = UpdateNamingConfig; - Get["/examples"] = x => GetExamples(this.Bind()); + Get("/examples", x => GetExamples(this.Bind())); SharedValidator.RuleFor(c => c.StandardMovieFormat).ValidMovieFormat(); SharedValidator.RuleFor(c => c.MovieFolderFormat).ValidMovieFolderFormat(); @@ -66,7 +63,7 @@ namespace Radarr.Api.V2.Config return GetNamingConfig(); } - private JsonResponse GetExamples(NamingConfigResource config) + private object GetExamples(NamingConfigResource config) { if (config.Id == 0) { @@ -86,7 +83,7 @@ namespace Radarr.Api.V2.Config ? "Invalid format" : _filenameSampleService.GetMovieFolderSample(nameSpec); - return sampleResource.AsResponse(); + return sampleResource; } private void ValidateFormatResult(NamingConfig nameSpec) diff --git a/src/Radarr.Api.V2/FileSystem/FileSystemModule.cs b/src/Radarr.Api.V2/FileSystem/FileSystemModule.cs index b5034eb71..6770d3b9a 100644 --- a/src/Radarr.Api.V2/FileSystem/FileSystemModule.cs +++ b/src/Radarr.Api.V2/FileSystem/FileSystemModule.cs @@ -23,49 +23,49 @@ namespace Radarr.Api.V2.FileSystem _fileSystemLookupService = fileSystemLookupService; _diskProvider = diskProvider; _diskScanService = diskScanService; - Get["/"] = x => GetContents(); - Get["/type"] = x => GetEntityType(); - Get["/mediafiles"] = x => GetMediaFiles(); + Get("/", x => GetContents()); + Get("/type", x => GetEntityType()); + Get("/mediafiles", x => GetMediaFiles()); } - private Response GetContents() + private object GetContents() { var pathQuery = Request.Query.path; var includeFiles = Request.GetBooleanQueryParameter("includeFiles"); var allowFoldersWithoutTrailingSlashes = Request.GetBooleanQueryParameter("allowFoldersWithoutTrailingSlashes"); - return _fileSystemLookupService.LookupContents((string)pathQuery.Value, includeFiles, allowFoldersWithoutTrailingSlashes).AsResponse(); + return _fileSystemLookupService.LookupContents((string)pathQuery.Value, includeFiles, allowFoldersWithoutTrailingSlashes); } - private Response GetEntityType() + private object GetEntityType() { var pathQuery = Request.Query.path; var path = (string)pathQuery.Value; if (_diskProvider.FileExists(path)) { - return new { type = "file" }.AsResponse(); + return new { type = "file" }; } //Return folder even if it doesn't exist on disk to avoid leaking anything from the UI about the underlying system - return new { type = "folder" }.AsResponse(); + return new { type = "folder" }; } - private Response GetMediaFiles() + private object GetMediaFiles() { var pathQuery = Request.Query.path; var path = (string)pathQuery.Value; if (!_diskProvider.FolderExists(path)) { - return new string[0].AsResponse(); + return new string[0]; } return _diskScanService.GetVideoFiles(path).Select(f => new { Path = f, RelativePath = path.GetRelativePath(f), Name = Path.GetFileName(f) - }).AsResponse(); + }); } } } diff --git a/src/Radarr.Api.V2/History/HistoryModule.cs b/src/Radarr.Api.V2/History/HistoryModule.cs index 33287d72d..025dc7ca2 100644 --- a/src/Radarr.Api.V2/History/HistoryModule.cs +++ b/src/Radarr.Api.V2/History/HistoryModule.cs @@ -28,9 +28,9 @@ namespace Radarr.Api.V2.History _failedDownloadService = failedDownloadService; GetResourcePaged = GetHistory; - Get["/since"] = x => GetHistorySince(); - Get["/movie"] = x => GetMovieHistory(); - Post["/failed"] = x => MarkAsFailed(); + Get("/since", x => GetHistorySince()); + Get("/movie", x => GetMovieHistory()); + Post("/failed", x => MarkAsFailed()); } protected HistoryResource MapToResource(NzbDrone.Core.History.History model, bool includeMovie) @@ -117,11 +117,11 @@ namespace Radarr.Api.V2.History return _historyService.GetByMovieId(movieId, eventType).Select(h => MapToResource(h, includeMovie)).ToList(); } - private Response MarkAsFailed() + private object MarkAsFailed() { var id = (int)Request.Form.Id; _failedDownloadService.MarkAsFailed(id); - return new object().AsResponse(); + return new object(); } } } diff --git a/src/Radarr.Api.V2/Indexers/ReleaseModule.cs b/src/Radarr.Api.V2/Indexers/ReleaseModule.cs index 9b003fb94..63c141f9e 100644 --- a/src/Radarr.Api.V2/Indexers/ReleaseModule.cs +++ b/src/Radarr.Api.V2/Indexers/ReleaseModule.cs @@ -47,12 +47,12 @@ namespace Radarr.Api.V2.Indexers PostValidator.RuleFor(s => s.Guid).NotEmpty(); GetResourceAll = GetReleases; - Post["/"] = x => DownloadRelease(ReadResourceFromRequest()); + Post("/", x => DownloadRelease(ReadResourceFromRequest())); _remoteMovieCache = cacheManager.GetCache(GetType(), "remoteMovies"); } - private Response DownloadRelease(ReleaseResource release) + private object DownloadRelease(ReleaseResource release) { var remoteMovie = _remoteMovieCache.Find(GetCacheKey(release)); @@ -73,7 +73,7 @@ namespace Radarr.Api.V2.Indexers throw new NzbDroneClientException(HttpStatusCode.Conflict, "Getting release from indexer failed"); } - return release.AsResponse(); + return release; } private List GetReleases() diff --git a/src/Radarr.Api.V2/Indexers/ReleasePushModule.cs b/src/Radarr.Api.V2/Indexers/ReleasePushModule.cs index dddb0eaf2..00ec73b38 100644 --- a/src/Radarr.Api.V2/Indexers/ReleasePushModule.cs +++ b/src/Radarr.Api.V2/Indexers/ReleasePushModule.cs @@ -36,10 +36,10 @@ namespace Radarr.Api.V2.Indexers PostValidator.RuleFor(s => s.Protocol).NotEmpty(); PostValidator.RuleFor(s => s.PublishDate).NotEmpty(); - Post["/push"] = x => ProcessRelease(ReadResourceFromRequest()); + Post("/push", x => ProcessRelease(ReadResourceFromRequest())); } - private Response ProcessRelease(ReleaseResource release) + private object ProcessRelease(ReleaseResource release) { _logger.Info("Release pushed: {0} - {1}", release.Title, release.DownloadUrl); @@ -59,7 +59,7 @@ namespace Radarr.Api.V2.Indexers throw new ValidationException(new List{ new ValidationFailure("Title", "Unable to parse", release.Title) }); } - return MapDecisions(new [] { firstDecision }).AsResponse(); + return MapDecisions(new [] { firstDecision }); } private void ResolveIndexer(ReleaseInfo release) diff --git a/src/Radarr.Api.V2/Logs/LogFileModuleBase.cs b/src/Radarr.Api.V2/Logs/LogFileModuleBase.cs index 7db242260..d5ac05af0 100644 --- a/src/Radarr.Api.V2/Logs/LogFileModuleBase.cs +++ b/src/Radarr.Api.V2/Logs/LogFileModuleBase.cs @@ -26,7 +26,7 @@ namespace Radarr.Api.V2.Logs _configFileProvider = configFileProvider; GetResourceAll = GetLogFilesResponse; - Get[LOGFILE_ROUTE] = options => GetLogFileResponse(options.filename); + Get(LOGFILE_ROUTE, options => GetLogFileResponse(options.filename)); } private List GetLogFilesResponse() @@ -53,7 +53,7 @@ namespace Radarr.Api.V2.Logs return result.OrderByDescending(l => l.LastWriteTime).ToList(); } - private Response GetLogFileResponse(string filename) + private object GetLogFileResponse(string filename) { LogManager.Flush(); diff --git a/src/Radarr.Api.V2/MovieFiles/MovieFileModule.cs b/src/Radarr.Api.V2/MovieFiles/MovieFileModule.cs index e9065a523..b3b64a97e 100644 --- a/src/Radarr.Api.V2/MovieFiles/MovieFileModule.cs +++ b/src/Radarr.Api.V2/MovieFiles/MovieFileModule.cs @@ -45,8 +45,8 @@ namespace Radarr.Api.V2.MovieFiles UpdateResource = SetMovieFile; DeleteResource = DeleteMovieFile; - Put["/editor"] = movieFiles => SetMovieFile(); - Delete["/bulk"] = movieFiles => DeleteMovieFiles(); + Put("/editor", movieFiles => SetMovieFile()); + Delete("/bulk", movieFiles => DeleteMovieFiles()); } private MovieFileResource GetMovieFile(int id) @@ -100,7 +100,7 @@ namespace Radarr.Api.V2.MovieFiles _mediaFileService.Update(movieFile); } - private Response SetMovieFile() + private object SetMovieFile() { var resource = Request.Body.FromJson(); var movieFiles = _mediaFileService.GetMovies(resource.MovieFileIds); @@ -123,8 +123,8 @@ namespace Radarr.Api.V2.MovieFiles var movie = _movieService.GetMovie(movieFiles.First().MovieId); - return movieFiles.ConvertAll(f => f.ToResource(movie, _qualityUpgradableSpecification)) - .AsResponse(HttpStatusCode.Accepted); + return ResponseWithCode(movieFiles.ConvertAll(f => f.ToResource(movie, _qualityUpgradableSpecification)) + , HttpStatusCode.Accepted); } private void DeleteMovieFile(int id) @@ -140,7 +140,7 @@ namespace Radarr.Api.V2.MovieFiles //_mediaFileDeletionService.Delete(series, episodeFile); } - private Response DeleteMovieFiles() + private object DeleteMovieFiles() { var resource = Request.Body.FromJson(); var movieFiles = _mediaFileService.GetMovies(resource.MovieFileIds); @@ -156,7 +156,7 @@ namespace Radarr.Api.V2.MovieFiles //_mediaFileDeletionService.DeleteEpisodeFile(movie, movieFile); } - return new object().AsResponse(); + return new object(); } public void Handle(MovieFileAddedEvent message) diff --git a/src/Radarr.Api.V2/Movies/FetchMovieListModule.cs b/src/Radarr.Api.V2/Movies/FetchMovieListModule.cs index 18ee21cbc..2c66fa538 100644 --- a/src/Radarr.Api.V2/Movies/FetchMovieListModule.cs +++ b/src/Radarr.Api.V2/Movies/FetchMovieListModule.cs @@ -20,11 +20,11 @@ namespace Radarr.Api.V2.Movies { _fetchNetImport = netImport; _movieSearch = movieSearch; - Get["/"] = x => Search(); + Get("/", x => Search()); } - private Response Search() + private object Search() { var results = _fetchNetImport.FetchAndFilter((int) Request.Query.listId, false); @@ -40,7 +40,7 @@ namespace Radarr.Api.V2.Movies } }*/ - return MapToResource(results).AsResponse(); + return MapToResource(results); } diff --git a/src/Radarr.Api.V2/Movies/MovieDiscoverModule.cs b/src/Radarr.Api.V2/Movies/MovieDiscoverModule.cs index 8cf817a30..5cb3e4df9 100644 --- a/src/Radarr.Api.V2/Movies/MovieDiscoverModule.cs +++ b/src/Radarr.Api.V2/Movies/MovieDiscoverModule.cs @@ -22,17 +22,17 @@ namespace Radarr.Api.V2.Movies { _searchProxy = searchProxy; _netImportFactory = netImportFactory; - Get["/lists"] = x => GetLists(); - Get["/{action?recommendations}"] = x => Search(x.action); + Get("/lists", x => GetLists()); + Get("/{action?recommendations}", x => Search(x.action)); } - private Response Search(string action) + private object Search(string action) { var imdbResults = _searchProxy.DiscoverNewMovies(action); - return MapToResource(imdbResults).AsResponse(); + return MapToResource(imdbResults); } - private Response GetLists() + private object GetLists() { var lists = _netImportFactory.Discoverable(); @@ -43,7 +43,7 @@ namespace Radarr.Api.V2.Movies resource.Name = definition.Definition.Name; return resource; - }).AsResponse(); + }); } private static IEnumerable MapToResource(IEnumerable movies) diff --git a/src/Radarr.Api.V2/Movies/MovieEditorModule.cs b/src/Radarr.Api.V2/Movies/MovieEditorModule.cs index 60ee36e26..3027c0524 100644 --- a/src/Radarr.Api.V2/Movies/MovieEditorModule.cs +++ b/src/Radarr.Api.V2/Movies/MovieEditorModule.cs @@ -1,12 +1,8 @@ -using System; using System.Collections.Generic; using System.Linq; using Nancy; -using Nancy.Responses; using Radarr.Http.Extensions; -using Radarr.Http.REST; using NzbDrone.Core.Movies; -using Radarr.Http.Mapping; using NzbDrone.Common.Extensions; using NzbDrone.Core.Movies.Commands; using NzbDrone.Core.Messaging.Commands; @@ -23,11 +19,11 @@ namespace Radarr.Api.V2.Movies { _movieService = movieService; _commandQueueManager = commandQueueManager; - Put["/"] = movie => SaveAll(); - Delete["/"] = movie => DeleteMovies(); + Put("/", movie => SaveAll()); + Delete("/", movie => DeleteMovies()); } - private Response SaveAll() + private object SaveAll() { var resource = Request.Body.FromJson(); var moviesToUpdate = _movieService.GetMovies(resource.MovieIds); @@ -84,12 +80,12 @@ namespace Radarr.Api.V2.Movies }); } - return _movieService.UpdateMovie(moviesToUpdate) + return ResponseWithCode(_movieService.UpdateMovie(moviesToUpdate) .ToResource() - .AsResponse(HttpStatusCode.Accepted); + , HttpStatusCode.Accepted); } - private Response DeleteMovies() + private object DeleteMovies() { var resource = Request.Body.FromJson(); @@ -98,7 +94,7 @@ namespace Radarr.Api.V2.Movies _movieService.DeleteMovie(id, false, false); } - return new object().AsResponse(); + return new object(); } } } diff --git a/src/Radarr.Api.V2/Movies/MovieImportModule.cs b/src/Radarr.Api.V2/Movies/MovieImportModule.cs index 68c0d49f4..a003a3a73 100644 --- a/src/Radarr.Api.V2/Movies/MovieImportModule.cs +++ b/src/Radarr.Api.V2/Movies/MovieImportModule.cs @@ -14,16 +14,16 @@ namespace Radarr.Api.V2.Movies : base("/movie/import") { _movieService = movieService; - Post["/"] = x => Import(); + Post("/", x => Import()); } - private Response Import() + private object Import() { var resource = Request.Body.FromJson>(); var newSeries = resource.ToModel(); - return _movieService.AddMovies(newSeries).ToResource().AsResponse(); + return _movieService.AddMovies(newSeries).ToResource(); } } } diff --git a/src/Radarr.Api.V2/Movies/MovieLookupModule.cs b/src/Radarr.Api.V2/Movies/MovieLookupModule.cs index 3aeea2a55..bf850b891 100644 --- a/src/Radarr.Api.V2/Movies/MovieLookupModule.cs +++ b/src/Radarr.Api.V2/Movies/MovieLookupModule.cs @@ -21,34 +21,34 @@ namespace Radarr.Api.V2.Movies { _movieInfo = movieInfo; _searchProxy = searchProxy; - Get["/"] = x => Search(); - Get["/tmdb"] = x => SearchByTmdbId(); - Get["/imdb"] = x => SearchByImdbId(); + Get("/", x => Search()); + Get("/tmdb", x => SearchByTmdbId()); + Get("/imdb", x => SearchByImdbId()); } - private Response SearchByTmdbId() + private object SearchByTmdbId() { int tmdbId = -1; if(Int32.TryParse(Request.Query.tmdbId, out tmdbId)) { var result = _movieInfo.GetMovieInfo(tmdbId, null, true); - return result.ToResource().AsResponse(); + return result.ToResource(); } throw new BadRequestException("Tmdb Id was not valid"); } - private Response SearchByImdbId() + private object SearchByImdbId() { string imdbId = Request.Query.imdbId; var result = _movieInfo.GetMovieInfo(imdbId); - return result.ToResource().AsResponse(); + return result.ToResource(); } - private Response Search() + private object Search() { var imdbResults = _searchProxy.SearchForNewMovie((string)Request.Query.term); - return MapToResource(imdbResults).AsResponse(); + return MapToResource(imdbResults); } private static IEnumerable MapToResource(IEnumerable movies) diff --git a/src/Radarr.Api.V2/NetImport/ListImportModule.cs b/src/Radarr.Api.V2/NetImport/ListImportModule.cs index 006c76175..ebd5c1788 100644 --- a/src/Radarr.Api.V2/NetImport/ListImportModule.cs +++ b/src/Radarr.Api.V2/NetImport/ListImportModule.cs @@ -19,16 +19,16 @@ namespace Radarr.Api.V2.NetImport { _movieService = movieService; _movieSearch = movieSearch; - Put["/"] = Movie => SaveAll(); + Put("/", Movie => SaveAll()); } - private Response SaveAll() + private object SaveAll() { var resources = Request.Body.FromJson>(); var Movies = resources.Select(MovieResource => _movieSearch.MapMovieToTmdbMovie(MovieResource.ToModel())).Where(m => m != null).DistinctBy(m => m.TmdbId).ToList(); - return _movieService.AddMovies(Movies).ToResource().AsResponse(HttpStatusCode.Accepted); + return ResponseWithCode(_movieService.AddMovies(Movies).ToResource(), HttpStatusCode.Accepted); } } } diff --git a/src/Radarr.Api.V2/ProviderModuleBase.cs b/src/Radarr.Api.V2/ProviderModuleBase.cs index af6647413..47254400e 100644 --- a/src/Radarr.Api.V2/ProviderModuleBase.cs +++ b/src/Radarr.Api.V2/ProviderModuleBase.cs @@ -26,10 +26,10 @@ namespace Radarr.Api.V2 _providerFactory = providerFactory; _resourceMapper = resourceMapper; - Get["schema"] = x => GetTemplates(); - Post["test"] = x => Test(ReadResourceFromRequest(true)); - Post["testall"] = x => TestAll(); - Post["action/{action}"] = x => RequestAction(x.action, ReadResourceFromRequest(true)); + Get("schema", x => GetTemplates()); + Post("test", x => Test(ReadResourceFromRequest(true))); + Post("testall", x => TestAll()); + Post("action/{action}", x => RequestAction(x.action, ReadResourceFromRequest(true))); GetResourceAll = GetAll; GetResourceById = GetProviderById; @@ -112,7 +112,7 @@ namespace Radarr.Api.V2 _providerFactory.Delete(id); } - private Response GetTemplates() + private object GetTemplates() { var defaultDefinitions = _providerFactory.GetDefaultDefinitions().OrderBy(p => p.ImplementationName).ToList(); @@ -133,10 +133,10 @@ namespace Radarr.Api.V2 result.Add(providerResource); } - return result.AsResponse(); + return result; } - private Response Test(TProviderResource providerResource) + private object Test(TProviderResource providerResource) { var providerDefinition = GetDefinition(providerResource, true); @@ -145,7 +145,7 @@ namespace Radarr.Api.V2 return "{}"; } - private Response TestAll() + private object TestAll() { var providerDefinitions = _providerFactory.All() .Where(c => c.Settings.Validate().IsValid && c.Enable) @@ -163,10 +163,10 @@ namespace Radarr.Api.V2 }); } - return result.AsResponse(result.Any(c => !c.IsValid) ? HttpStatusCode.BadRequest : HttpStatusCode.OK); + return ResponseWithCode(result, result.Any(c => !c.IsValid) ? HttpStatusCode.BadRequest : HttpStatusCode.OK); } - private Response RequestAction(string action, TProviderResource providerResource) + private object RequestAction(string action, TProviderResource providerResource) { var providerDefinition = GetDefinition(providerResource, true, false); diff --git a/src/Radarr.Api.V2/Qualities/CustomFormatModule.cs b/src/Radarr.Api.V2/Qualities/CustomFormatModule.cs index ed2862fae..cc8e575e8 100644 --- a/src/Radarr.Api.V2/Qualities/CustomFormatModule.cs +++ b/src/Radarr.Api.V2/Qualities/CustomFormatModule.cs @@ -48,11 +48,11 @@ namespace Radarr.Api.V2.Qualities DeleteResource = DeleteFormat; - Get["/test"] = x => Test(); + Get("/test", x => Test()); - Post["/test"] = x => TestWithNewModel(); + Post("/test", x => TestWithNewModel()); - Get["schema"] = x => GetTemplates(); + Get("schema", x => GetTemplates()); } private int Create(CustomFormatResource customFormatResource) @@ -82,7 +82,7 @@ namespace Radarr.Api.V2.Qualities _formatService.Delete(id); } - private Response GetTemplates() + private object GetTemplates() { return CustomFormatService.Templates.SelectMany(t => { @@ -92,7 +92,7 @@ namespace Radarr.Api.V2.Qualities r.Simplicity = t.Key; return r; }); - }).AsResponse(); + }); } private CustomFormatTestResource Test() diff --git a/src/Radarr.Api.V2/Queue/QueueActionModule.cs b/src/Radarr.Api.V2/Queue/QueueActionModule.cs index 62831704b..69a4be016 100644 --- a/src/Radarr.Api.V2/Queue/QueueActionModule.cs +++ b/src/Radarr.Api.V2/Queue/QueueActionModule.cs @@ -34,14 +34,14 @@ namespace Radarr.Api.V2.Queue _pendingReleaseService = pendingReleaseService; _downloadService = downloadService; - Post[@"/grab/(?[\d]{1,10})"] = x => Grab((int)x.Id); - Post["/grab/bulk"] = x => Grab(); + Post(@"/grab/(?[\d]{1,10})", x => Grab((int)x.Id)); + Post("/grab/bulk", x => Grab()); - Delete[@"/(?[\d]{1,10})"] = x => Remove((int)x.Id); - Delete["/bulk"] = x => Remove(); + Delete(@"/(?[\d]{1,10})", x => Remove((int)x.Id)); + Delete("/bulk", x => Remove()); } - private Response Grab(int id) + private object Grab(int id) { var pendingRelease = _pendingReleaseService.FindPendingQueueItem(id); @@ -52,10 +52,10 @@ namespace Radarr.Api.V2.Queue _downloadService.DownloadReport(pendingRelease.RemoteMovie); - return new object().AsResponse(); + return new object(); } - private Response Grab() + private object Grab() { var resource = Request.Body.FromJson(); @@ -71,10 +71,10 @@ namespace Radarr.Api.V2.Queue _downloadService.DownloadReport(pendingRelease.RemoteMovie); } - return new object().AsResponse(); + return new object(); } - private Response Remove(int id) + private object Remove(int id) { var blacklist = Request.GetBooleanQueryParameter("blacklist"); @@ -85,10 +85,10 @@ namespace Radarr.Api.V2.Queue _trackedDownloadService.StopTracking(trackedDownload.DownloadItem.DownloadId); } - return new object().AsResponse(); + return new object(); } - private Response Remove() + private object Remove() { var blacklist = Request.GetBooleanQueryParameter("blacklist"); @@ -107,7 +107,7 @@ namespace Radarr.Api.V2.Queue _trackedDownloadService.StopTracking(trackedDownloadIds); - return new object().AsResponse(); + return new object(); } private TrackedDownload Remove(int id, bool blacklist) diff --git a/src/Radarr.Api.V2/Queue/QueueStatusModule.cs b/src/Radarr.Api.V2/Queue/QueueStatusModule.cs index 0d110885e..0214acd97 100644 --- a/src/Radarr.Api.V2/Queue/QueueStatusModule.cs +++ b/src/Radarr.Api.V2/Queue/QueueStatusModule.cs @@ -1,6 +1,5 @@ using System; using System.Linq; -using Nancy.Responses; using NzbDrone.Common.TPL; using NzbDrone.Core.Datastore.Events; using NzbDrone.Core.Download.Pending; @@ -8,7 +7,6 @@ using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Queue; using NzbDrone.SignalR; using Radarr.Http; -using Radarr.Http.Extensions; namespace Radarr.Api.V2.Queue { @@ -29,12 +27,12 @@ namespace Radarr.Api.V2.Queue _broadcastDebounce = new Debouncer(BroadcastChange, TimeSpan.FromSeconds(5)); - Get["/"] = x => GetQueueStatusResponse(); + Get("/", x => GetQueueStatusResponse()); } - private JsonResponse GetQueueStatusResponse() + private object GetQueueStatusResponse() { - return GetQueueStatus().AsResponse(); + return GetQueueStatus(); } private QueueStatusResource GetQueueStatus() diff --git a/src/Radarr.Api.V2/Radarr.Api.V2.csproj b/src/Radarr.Api.V2/Radarr.Api.V2.csproj index ab10ed1be..a3254599c 100644 --- a/src/Radarr.Api.V2/Radarr.Api.V2.csproj +++ b/src/Radarr.Api.V2/Radarr.Api.V2.csproj @@ -6,9 +6,9 @@ - - - + + + @@ -16,4 +16,4 @@ - \ No newline at end of file + diff --git a/src/Radarr.Api.V2/RadarrV2FeedModule.cs b/src/Radarr.Api.V2/RadarrV2FeedModule.cs index f71e28cca..55a5374bf 100644 --- a/src/Radarr.Api.V2/RadarrV2FeedModule.cs +++ b/src/Radarr.Api.V2/RadarrV2FeedModule.cs @@ -1,8 +1,8 @@ -using Nancy; +using Radarr.Http; namespace Radarr.Api.V2 { - public abstract class RadarrV2FeedModule : NancyModule + public abstract class RadarrV2FeedModule : RadarrModule { protected RadarrV2FeedModule(string resource) : base("/feed/v2/" + resource.Trim('/')) diff --git a/src/Radarr.Api.V2/RadarrV2Module.cs b/src/Radarr.Api.V2/RadarrV2Module.cs index 6d05e5562..97d522d4a 100644 --- a/src/Radarr.Api.V2/RadarrV2Module.cs +++ b/src/Radarr.Api.V2/RadarrV2Module.cs @@ -1,8 +1,8 @@ -using Nancy; +using Radarr.Http; namespace Radarr.Api.V2 { - public abstract class RadarrV2Module : NancyModule + public abstract class RadarrV2Module : RadarrModule { protected RadarrV2Module(string resource) : base("/api/v2/" + resource.Trim('/')) diff --git a/src/Radarr.Api.V2/System/Backup/BackupModule.cs b/src/Radarr.Api.V2/System/Backup/BackupModule.cs index ed9257735..49cde0f36 100644 --- a/src/Radarr.Api.V2/System/Backup/BackupModule.cs +++ b/src/Radarr.Api.V2/System/Backup/BackupModule.cs @@ -32,8 +32,8 @@ namespace Radarr.Api.V2.System.Backup GetResourceAll = GetBackupFiles; DeleteResource = DeleteBackup; - Post[@"/restore/(?[\d]{1,10})"] = x => Restore((int)x.Id); - Post["/restore/upload"] = x => UploadAndRestore(); + Post(@"/restore/(?[\d]{1,10})", x => Restore((int)x.Id)); + Post("/restore/upload", x => UploadAndRestore()); } public List GetBackupFiles() @@ -65,7 +65,7 @@ namespace Radarr.Api.V2.System.Backup _diskProvider.DeleteFile(path); } - public Response Restore(int id) + public object Restore(int id) { var backup = GetBackup(id); @@ -81,10 +81,10 @@ namespace Radarr.Api.V2.System.Backup return new { RestartRequired = true - }.AsResponse(); + }; } - public Response UploadAndRestore() + public object UploadAndRestore() { var files = Context.Request.Files.ToList(); @@ -112,7 +112,7 @@ namespace Radarr.Api.V2.System.Backup return new { RestartRequired = true - }.AsResponse(); + }; } private string GetBackupPath(NzbDrone.Core.Backup.Backup backup) diff --git a/src/Radarr.Api.V2/System/SystemModule.cs b/src/Radarr.Api.V2/System/SystemModule.cs index 6957cce4c..419fc4759 100644 --- a/src/Radarr.Api.V2/System/SystemModule.cs +++ b/src/Radarr.Api.V2/System/SystemModule.cs @@ -39,13 +39,13 @@ namespace Radarr.Api.V2.System _configFileProvider = configFileProvider; _database = database; _lifecycleService = lifecycleService; - Get["/status"] = x => GetStatus(); - Get["/routes"] = x => GetRoutes(); - Post["/shutdown"] = x => Shutdown(); - Post["/restart"] = x => Restart(); + Get("/status", x => GetStatus()); + Get("/routes", x => GetRoutes()); + Post("/shutdown", x => Shutdown()); + Post("/restart", x => Restart()); } - private Response GetStatus() + private object GetStatus() { return new { @@ -73,24 +73,24 @@ namespace Radarr.Api.V2.System RuntimeVersion = _platformInfo.Version, RuntimeName = PlatformInfo.Platform, StartTime = _runtimeInfo.StartTime - }.AsResponse(); + }; } - private Response GetRoutes() + private object GetRoutes() { - return _routeCacheProvider.GetCache().Values.AsResponse(); + return _routeCacheProvider.GetCache().Values; } - private Response Shutdown() + private object Shutdown() { Task.Factory.StartNew(() => _lifecycleService.Shutdown()); - return new { ShuttingDown = true }.AsResponse(); + return new { ShuttingDown = true }; } - private Response Restart() + private object Restart() { Task.Factory.StartNew(() => _lifecycleService.Restart()); - return new { Restarting = true }.AsResponse(); + return new { Restarting = true }; } } } diff --git a/src/Radarr.Http/Authentication/1tews5g3.gd1~ b/src/Radarr.Http/Authentication/1tews5g3.gd1~ deleted file mode 100644 index 7eeeec032..000000000 --- a/src/Radarr.Http/Authentication/1tews5g3.gd1~ +++ /dev/null @@ -1,62 +0,0 @@ -using Nancy; -using Nancy.Authentication.Basic; -using Nancy.Authentication.Forms; -using Nancy.Bootstrapper; -using Nancy.Cryptography; -using NzbDrone.Api.Extensions.Pipelines; -using NzbDrone.Core.Configuration; - -namespace NzbDrone.Api.Authentication -{ - public class EnableAuthInNancy : IRegisterNancyPipeline - { - private readonly IAuthenticationService _authenticationService; - private readonly IConfigService _configService; - private readonly IConfigFileProvider _configFileProvider; - - public EnableAuthInNancy(IAuthenticationService authenticationService, - IConfigService configService, - IConfigFileProvider configFileProvider) - { - _authenticationService = authenticationService; - _configService = configService; - _configFileProvider = configFileProvider; - } - - public void Register(IPipelines pipelines) - { - RegisterFormsAuth(pipelines); - pipelines.EnableBasicAuthentication(new BasicAuthenticationConfiguration(_authenticationService, "Sonarr")); - pipelines.BeforeRequest.AddItemToEndOfPipeline(RequiresAuthentication); - } - - private Response RequiresAuthentication(NancyContext context) - { - Response response = null; - - if (!_authenticationService.IsAuthenticated(context)) - { - response = new Response { StatusCode = HttpStatusCode.Unauthorized }; - } - - return response; - } - - private void RegisterFormsAuth(IPipelines pipelines) - { - var cryptographyConfiguration = new CryptographyConfiguration( - new RijndaelEncryptionProvider(new PassphraseKeyGenerator(_configService.RijndaelPassphrase, - new byte[] {1, 2, 3, 4, 5, 6, 7, 8})), - new DefaultHmacProvider(new PassphraseKeyGenerator(_configService.HmacPassphrase, - new byte[] {1, 2, 3, 4, 5, 6, 7, 8})) - ); - - FormsAuthentication.Enable(pipelines, new FormsAuthenticationConfiguration - { - RedirectUrl = "~/login", - UserMapper = _authenticationService, - CryptographyConfiguration = cryptographyConfiguration - }); - } - } -} diff --git a/src/Radarr.Http/Authentication/AuthenticationModule.cs b/src/Radarr.Http/Authentication/AuthenticationModule.cs index b7eac47d2..a4a8d9a42 100644 --- a/src/Radarr.Http/Authentication/AuthenticationModule.cs +++ b/src/Radarr.Http/Authentication/AuthenticationModule.cs @@ -3,9 +3,6 @@ using Nancy; using Nancy.Authentication.Forms; using Nancy.Extensions; using Nancy.ModelBinding; -using NLog; -using NzbDrone.Common.Instrumentation; -using NzbDrone.Core.Authentication; using NzbDrone.Core.Configuration; namespace Radarr.Http.Authentication @@ -19,8 +16,8 @@ namespace Radarr.Http.Authentication { _authService = authService; _configFileProvider = configFileProvider; - Post["/login"] = x => Login(this.Bind()); - Get["/logout"] = x => Logout(); + Post("/login", x => Login(this.Bind())); + Get("/logout", x => Logout()); } private Response Login(LoginResource resource) diff --git a/src/Radarr.Http/Authentication/AuthenticationService.cs b/src/Radarr.Http/Authentication/AuthenticationService.cs index 8ccc847f3..214c0e82c 100644 --- a/src/Radarr.Http/Authentication/AuthenticationService.cs +++ b/src/Radarr.Http/Authentication/AuthenticationService.cs @@ -1,12 +1,12 @@ using System; using System.Linq; +using System.Security.Claims; +using System.Security.Principal; using Nancy; using Nancy.Authentication.Basic; using Nancy.Authentication.Forms; -using Nancy.Security; using NLog; using NzbDrone.Common.Extensions; -using NzbDrone.Common.Instrumentation; using NzbDrone.Core.Authentication; using NzbDrone.Core.Configuration; using Radarr.Http.Extensions; @@ -26,7 +26,7 @@ namespace Radarr.Http.Authentication public class AuthenticationService : IAuthenticationService { private static readonly Logger _authLogger = LogManager.GetLogger("Auth"); - private static readonly NzbDroneUser AnonymousUser = new NzbDroneUser { UserName = "Anonymous" }; + private const string AnonymousUser = "Anonymous"; private readonly IUserService _userService; private readonly NancyContext _nancyContext; @@ -80,15 +80,15 @@ namespace Radarr.Http.Authentication if (context.CurrentUser != null) { - LogLogout(context, context.CurrentUser.UserName); + LogLogout(context, context.CurrentUser.Identity.Name); } } - public IUserIdentity Validate(string username, string password) + public ClaimsPrincipal Validate(string username, string password) { if (AUTH_METHOD == AuthenticationType.None) { - return AnonymousUser; + return new ClaimsPrincipal(new GenericIdentity(AnonymousUser)); } var user = _userService.FindUser(username, password); @@ -101,7 +101,7 @@ namespace Radarr.Http.Authentication LogSuccess(_context, username); } - return new NzbDroneUser { UserName = user.Username }; + return new ClaimsPrincipal(new GenericIdentity(user.Username)); } LogFailure(_context, username); @@ -109,18 +109,18 @@ namespace Radarr.Http.Authentication return null; } - public IUserIdentity GetUserFromIdentifier(Guid identifier, NancyContext context) + public ClaimsPrincipal GetUserFromIdentifier(Guid identifier, NancyContext context) { if (AUTH_METHOD == AuthenticationType.None) { - return AnonymousUser; + return new ClaimsPrincipal(new GenericIdentity(AnonymousUser)); } var user = _userService.FindUser(identifier); if (user != null) { - return new NzbDroneUser { UserName = user.Username }; + return new ClaimsPrincipal(new GenericIdentity(user.Username)); } LogInvalidated(_context); diff --git a/src/Radarr.Http/Authentication/EnableAuthInNancy.cs b/src/Radarr.Http/Authentication/EnableAuthInNancy.cs index 7cff32801..48da0683a 100644 --- a/src/Radarr.Http/Authentication/EnableAuthInNancy.cs +++ b/src/Radarr.Http/Authentication/EnableAuthInNancy.cs @@ -76,7 +76,7 @@ namespace Radarr.Http.Authentication FormsAuthentication.FormsAuthenticationCookieName = "RadarrAuth"; var cryptographyConfiguration = new CryptographyConfiguration( - new RijndaelEncryptionProvider(new PassphraseKeyGenerator(_configService.RijndaelPassphrase, Encoding.ASCII.GetBytes(_configService.RijndaelSalt))), + new AesEncryptionProvider(new PassphraseKeyGenerator(_configService.RijndaelPassphrase, Encoding.ASCII.GetBytes(_configService.RijndaelSalt))), new DefaultHmacProvider(new PassphraseKeyGenerator(_configService.HmacPassphrase, Encoding.ASCII.GetBytes(_configService.HmacSalt))) ); @@ -99,7 +99,7 @@ namespace Radarr.Http.Authentication context.Response.Headers["Location"].StartsWith($"{_configFileProvider.UrlBase}/login", StringComparison.InvariantCultureIgnoreCase)) || context.Response.StatusCode == HttpStatusCode.Unauthorized) { - context.Response = new { Error = "Unauthorized" }.AsResponse(HttpStatusCode.Unauthorized); + context.Response = new { Error = "Unauthorized" }.AsResponse(context, HttpStatusCode.Unauthorized); } } } diff --git a/src/Radarr.Http/Authentication/NzbDroneUser.cs b/src/Radarr.Http/Authentication/NzbDroneUser.cs deleted file mode 100644 index 65297fd82..000000000 --- a/src/Radarr.Http/Authentication/NzbDroneUser.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Collections.Generic; -using Nancy.Security; - -namespace Radarr.Http.Authentication -{ - public class NzbDroneUser : IUserIdentity - { - public string UserName { get; set; } - - public IEnumerable Claims { get; set; } - } -} diff --git a/src/Radarr.Http/ErrorManagement/ErrorHandler.cs b/src/Radarr.Http/ErrorManagement/ErrorHandler.cs index dd528ea31..901984785 100644 --- a/src/Radarr.Http/ErrorManagement/ErrorHandler.cs +++ b/src/Radarr.Http/ErrorManagement/ErrorHandler.cs @@ -14,7 +14,9 @@ namespace Radarr.Http.ErrorManagement public void Handle(HttpStatusCode statusCode, NancyContext context) { if (statusCode == HttpStatusCode.SeeOther || statusCode == HttpStatusCode.OK) + { return; + } if (statusCode == HttpStatusCode.Continue) { @@ -23,13 +25,17 @@ namespace Radarr.Http.ErrorManagement } if (statusCode == HttpStatusCode.Unauthorized) + { return; + } if (context.Response.ContentType == "text/html" || context.Response.ContentType == "text/plain") + { context.Response = new ErrorModel - { - Message = statusCode.ToString() - }.AsResponse(statusCode); + { + Message = statusCode.ToString() + }.AsResponse(context, statusCode); + } } } -} \ No newline at end of file +} diff --git a/src/Radarr.Http/ErrorManagement/RadarrErrorPipeline.cs b/src/Radarr.Http/ErrorManagement/RadarrErrorPipeline.cs index 7171454a9..fbaf8b320 100644 --- a/src/Radarr.Http/ErrorManagement/RadarrErrorPipeline.cs +++ b/src/Radarr.Http/ErrorManagement/RadarrErrorPipeline.cs @@ -27,14 +27,14 @@ namespace Radarr.Http.ErrorManagement if (exception is ApiException apiException) { _logger.Warn(apiException, "API Error"); - return apiException.ToErrorResponse(); + return apiException.ToErrorResponse(context); } if (exception is ValidationException validationException) { _logger.Warn("Invalid request {0}", validationException.Message); - return validationException.Errors.AsResponse(HttpStatusCode.BadRequest); + return validationException.Errors.AsResponse(context, HttpStatusCode.BadRequest); } if (exception is NzbDroneClientException clientException) @@ -43,7 +43,7 @@ namespace Radarr.Http.ErrorManagement { Message = exception.Message, Description = exception.ToString() - }.AsResponse((HttpStatusCode)clientException.StatusCode); + }.AsResponse(context, (HttpStatusCode)clientException.StatusCode); } if (exception is ModelNotFoundException notFoundException) @@ -52,7 +52,7 @@ namespace Radarr.Http.ErrorManagement { Message = exception.Message, Description = exception.ToString() - }.AsResponse(HttpStatusCode.NotFound); + }.AsResponse(context, HttpStatusCode.NotFound); } if (exception is ModelConflictException conflictException) @@ -61,7 +61,7 @@ namespace Radarr.Http.ErrorManagement { Message = exception.Message, Description = exception.ToString() - }.AsResponse(HttpStatusCode.Conflict); + }.AsResponse(context, HttpStatusCode.Conflict); } if (exception is SQLiteException sqLiteException) @@ -72,7 +72,7 @@ namespace Radarr.Http.ErrorManagement return new ErrorModel { Message = exception.Message, - }.AsResponse(HttpStatusCode.Conflict); + }.AsResponse(context, HttpStatusCode.Conflict); } _logger.Error(sqLiteException, "[{0} {1}]", context.Request.Method, context.Request.Path); @@ -84,7 +84,7 @@ namespace Radarr.Http.ErrorManagement { Message = exception.Message, Description = exception.ToString() - }.AsResponse(HttpStatusCode.InternalServerError); + }.AsResponse(context, HttpStatusCode.InternalServerError); } } -} \ No newline at end of file +} diff --git a/src/Radarr.Http/Exceptions/ApiException.cs b/src/Radarr.Http/Exceptions/ApiException.cs index 9e379c9f2..49088ca01 100644 --- a/src/Radarr.Http/Exceptions/ApiException.cs +++ b/src/Radarr.Http/Exceptions/ApiException.cs @@ -19,9 +19,9 @@ namespace Radarr.Http.Exceptions Content = content; } - public JsonResponse ToErrorResponse() + public JsonResponse ToErrorResponse(NancyContext context) { - return new ErrorModel(this).AsResponse(StatusCode); + return new ErrorModel(this).AsResponse(context, StatusCode); } private static string GetMessage(HttpStatusCode statusCode, object content) diff --git a/src/Radarr.Http/Extensions/NancyJsonSerializer.cs b/src/Radarr.Http/Extensions/NancyJsonSerializer.cs index 971cedfaf..70d91e7ad 100644 --- a/src/Radarr.Http/Extensions/NancyJsonSerializer.cs +++ b/src/Radarr.Http/Extensions/NancyJsonSerializer.cs @@ -1,22 +1,23 @@ using System.Collections.Generic; using System.IO; using Nancy; +using Nancy.Responses.Negotiation; using NzbDrone.Common.Serializer; namespace Radarr.Http.Extensions { public class NancyJsonSerializer : ISerializer { - public bool CanSerialize(string contentType) + public bool CanSerialize(MediaRange contentType) { - return true; + return contentType == "application/json"; } - public void Serialize(string contentType, TModel model, Stream outputStream) + public void Serialize(MediaRange contentType, TModel model, Stream outputStream) { Json.Serialize(model, outputStream); } public IEnumerable Extensions { get; private set; } } -} \ No newline at end of file +} diff --git a/src/Radarr.Http/Extensions/ReqResExtensions.cs b/src/Radarr.Http/Extensions/ReqResExtensions.cs index 1cf27c697..6326d907a 100644 --- a/src/Radarr.Http/Extensions/ReqResExtensions.cs +++ b/src/Radarr.Http/Extensions/ReqResExtensions.cs @@ -32,9 +32,9 @@ namespace Radarr.Http.Extensions return Json.Deserialize(value, type); } - public static JsonResponse AsResponse(this TModel model, HttpStatusCode statusCode = HttpStatusCode.OK) + public static JsonResponse AsResponse(this TModel model, NancyContext context, HttpStatusCode statusCode = HttpStatusCode.OK) { - var response = new JsonResponse(model, NancySerializer) { StatusCode = statusCode }; + var response = new JsonResponse(model, NancySerializer, context.Environment) { StatusCode = statusCode }; response.Headers.DisableCache(); return response; @@ -59,4 +59,4 @@ namespace Radarr.Http.Extensions return headers; } } -} \ No newline at end of file +} diff --git a/src/Radarr.Http/Frontend/InitializeJsModule.cs b/src/Radarr.Http/Frontend/InitializeJsModule.cs index 27b032ecf..21455f787 100644 --- a/src/Radarr.Http/Frontend/InitializeJsModule.cs +++ b/src/Radarr.Http/Frontend/InitializeJsModule.cs @@ -27,7 +27,7 @@ namespace Radarr.Http.Frontend _apiKey = configFileProvider.ApiKey; _urlBase = configFileProvider.UrlBase; - Get["/initialize.js"] = x => Index(); + Get("/initialize.js", x => Index()); } private Response Index() diff --git a/src/Radarr.Http/Frontend/Mappers/LoginHtmlMapper.cs b/src/Radarr.Http/Frontend/Mappers/LoginHtmlMapper.cs index 4bfeb05ae..2cd6c5a55 100644 --- a/src/Radarr.Http/Frontend/Mappers/LoginHtmlMapper.cs +++ b/src/Radarr.Http/Frontend/Mappers/LoginHtmlMapper.cs @@ -1,6 +1,5 @@ using System; using System.IO; -using Nancy; using NLog; using NzbDrone.Common.Disk; using NzbDrone.Common.EnvironmentInfo; diff --git a/src/Radarr.Http/Frontend/StaticResourceModule.cs b/src/Radarr.Http/Frontend/StaticResourceModule.cs index 3fbde24cf..5661f6276 100644 --- a/src/Radarr.Http/Frontend/StaticResourceModule.cs +++ b/src/Radarr.Http/Frontend/StaticResourceModule.cs @@ -18,8 +18,8 @@ namespace Radarr.Http.Frontend _requestMappers = requestMappers; _logger = logger; - Get["/{resource*}"] = x => Index(); - Get["/"] = x => Index(); + Get("/{resource*}", x => Index()); + Get("/", x => Index()); } private Response Index() diff --git a/src/Radarr.Http/REST/RestModule.cs b/src/Radarr.Http/REST/RestModule.cs index ba2f9f2c2..214742513 100644 --- a/src/Radarr.Http/REST/RestModule.cs +++ b/src/Radarr.Http/REST/RestModule.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using FluentValidation; using Nancy; +using Nancy.Responses.Negotiation; using Newtonsoft.Json; using NzbDrone.Core.Datastore; using Radarr.Http.Extensions; @@ -72,13 +73,13 @@ namespace Radarr.Http.REST set { _deleteResource = value; - Delete[ID_ROUTE] = options => + Delete(ID_ROUTE, options => { ValidateId(options.Id); DeleteResource((int)options.Id); - return new object().AsResponse(); - }; + return new object(); + }); } } @@ -88,7 +89,7 @@ namespace Radarr.Http.REST set { _getResourceById = value; - Get[ID_ROUTE] = options => + Get(ID_ROUTE, options => { ValidateId(options.Id); try @@ -100,13 +101,13 @@ namespace Radarr.Http.REST return new NotFoundResponse(); } - return resource.AsResponse(); + return resource; } catch (ModelNotFoundException) { return new NotFoundResponse(); } - }; + }); } } @@ -117,11 +118,11 @@ namespace Radarr.Http.REST { _getResourceAll = value; - Get[ROOT_ROUTE] = options => + Get(ROOT_ROUTE, options => { var resource = GetResourceAll(); - return resource.AsResponse(); - }; + return resource; + }); } } @@ -132,11 +133,11 @@ namespace Radarr.Http.REST { _getResourcePaged = value; - Get[ROOT_ROUTE] = options => + Get(ROOT_ROUTE, options => { var resource = GetResourcePaged(ReadPagingResourceFromRequest()); - return resource.AsResponse(); - }; + return resource; + }); } } @@ -147,11 +148,11 @@ namespace Radarr.Http.REST { _getResourceSingle = value; - Get[ROOT_ROUTE] = options => + Get(ROOT_ROUTE, options => { var resource = GetResourceSingle(); - return resource.AsResponse(); - }; + return resource; + }); } } @@ -161,12 +162,11 @@ namespace Radarr.Http.REST set { _createResource = value; - Post[ROOT_ROUTE] = options => + Post(ROOT_ROUTE, options => { var id = CreateResource(ReadResourceFromRequest()); - return GetResourceById(id).AsResponse(HttpStatusCode.Created); - }; - + return ResponseWithCode(GetResourceById(id), HttpStatusCode.Created); + }); } } @@ -176,23 +176,28 @@ namespace Radarr.Http.REST set { _updateResource = value; - Put[ROOT_ROUTE] = options => + Put(ROOT_ROUTE, options => { var resource = ReadResourceFromRequest(); UpdateResource(resource); - return GetResourceById(resource.Id).AsResponse(HttpStatusCode.Accepted); - }; + return ResponseWithCode(GetResourceById(resource.Id), HttpStatusCode.Accepted); + }); - Put[ID_ROUTE] = options => + Put(ID_ROUTE, options => { var resource = ReadResourceFromRequest(); resource.Id = options.Id; UpdateResource(resource); - return GetResourceById(resource.Id).AsResponse(HttpStatusCode.Accepted); - }; + return ResponseWithCode(GetResourceById(resource.Id), HttpStatusCode.Accepted); + }); } } + protected Negotiator ResponseWithCode(object model, HttpStatusCode statusCode) + { + return Negotiate.WithModel(model).WithStatusCode(statusCode); + } + protected TResource ReadResourceFromRequest(bool skipValidate = false) { TResource resource; diff --git a/src/Radarr.Http/Radarr.Http.csproj b/src/Radarr.Http/Radarr.Http.csproj index c02247f7f..9110a81df 100644 --- a/src/Radarr.Http/Radarr.Http.csproj +++ b/src/Radarr.Http/Radarr.Http.csproj @@ -5,9 +5,9 @@ - - - + + + @@ -20,4 +20,4 @@ ..\Libraries\Sqlite\System.Data.SQLite.dll - \ No newline at end of file + diff --git a/src/Radarr.Http/RadarrBootstrapper.cs b/src/Radarr.Http/RadarrBootstrapper.cs index 5e518f894..0b3fc1227 100644 --- a/src/Radarr.Http/RadarrBootstrapper.cs +++ b/src/Radarr.Http/RadarrBootstrapper.cs @@ -1,12 +1,13 @@ +using System; using System.Linq; +using Nancy; using Nancy.Bootstrapper; using Nancy.Diagnostics; +using Nancy.Responses.Negotiation; using NLog; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Instrumentation; using NzbDrone.Core.Instrumentation; -using NzbDrone.Core.Lifecycle; -using NzbDrone.Core.Messaging.Events; using Radarr.Http.Extensions.Pipelines; using TinyIoC; @@ -51,7 +52,19 @@ namespace Radarr.Http return _tinyIoCContainer; } - protected override DiagnosticsConfiguration DiagnosticsConfiguration => new DiagnosticsConfiguration { Password = @"password" }; + protected override Func InternalConfiguration + { + get + { + // We don't support Xml Serialization atm + return NancyInternalConfiguration.WithOverrides(x => x.ResponseProcessors.Remove(typeof(XmlProcessor))); + } + } + + public override void Configure(Nancy.Configuration.INancyEnvironment environment) + { + environment.Diagnostics(password: @"password"); + } protected override byte[] FavIcon => null; } diff --git a/src/Radarr.Http/RadarrModule.cs b/src/Radarr.Http/RadarrModule.cs new file mode 100644 index 000000000..2c1cf362d --- /dev/null +++ b/src/Radarr.Http/RadarrModule.cs @@ -0,0 +1,18 @@ +using Nancy; +using Nancy.Responses.Negotiation; + +namespace Radarr.Http +{ + public abstract class RadarrModule : NancyModule + { + protected RadarrModule(string resource) + : base(resource) + { + } + + protected Negotiator ResponseWithCode(object model, HttpStatusCode statusCode) + { + return Negotiate.WithModel(model).WithStatusCode(statusCode); + } + } +} diff --git a/src/Radarr.Http/TinyIoCNancyBootstrapper.cs b/src/Radarr.Http/TinyIoCNancyBootstrapper.cs index bd065547b..ed9bdf89f 100644 --- a/src/Radarr.Http/TinyIoCNancyBootstrapper.cs +++ b/src/Radarr.Http/TinyIoCNancyBootstrapper.cs @@ -6,6 +6,7 @@ using System.Reflection; using Nancy; using Nancy.Diagnostics; using Nancy.Bootstrapper; +using Nancy.Configuration; namespace Radarr.Http { @@ -52,6 +53,47 @@ namespace Radarr.Http return this.ApplicationContainer.Resolve(); } + // + // Summary: + // Gets the Nancy.Configuration.INancyEnvironmentConfigurator used by th. + // + // Returns: + // An Nancy.Configuration.INancyEnvironmentConfigurator instance. + protected override INancyEnvironmentConfigurator GetEnvironmentConfigurator() + { + return this.ApplicationContainer.Resolve(); + } + + // + // Summary: + // Get the Nancy.Configuration.INancyEnvironment instance. + // + // Returns: + // An configured Nancy.Configuration.INancyEnvironment instance. + // + // Remarks: + // The boostrapper must be initialised (Nancy.Bootstrapper.INancyBootstrapper.Initialise) + // prior to calling this. + public override INancyEnvironment GetEnvironment() + { + return this.ApplicationContainer.Resolve(); + } + + // + // Summary: + // Registers an Nancy.Configuration.INancyEnvironment instance in the container. + // + // Parameters: + // container: + // The container to register into. + // + // environment: + // The Nancy.Configuration.INancyEnvironment instance to register. + protected override void RegisterNancyEnvironment(TinyIoCContainer container, INancyEnvironment environment) + { + ApplicationContainer.Register(environment); + } + /// /// Create a default, unconfigured, container ///