mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-20 05:13:18 -07:00
merge
This commit is contained in:
commit
0e2f5bbf98
50 changed files with 1832 additions and 176 deletions
|
@ -1,7 +1,29 @@
|
|||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
#region Copyright
|
||||
// /************************************************************************
|
||||
// Copyright (c) 2016 Jamie Rees
|
||||
// File: AdminModule.cs
|
||||
// Created By: Jamie Rees
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining
|
||||
// a copy of this software and associated documentation files (the
|
||||
// "Software"), to deal in the Software without restriction, including
|
||||
// without limitation the rights to use, copy, modify, merge, publish,
|
||||
// distribute, sublicense, and/or sell copies of the Software, and to
|
||||
// permit persons to whom the Software is furnished to do so, subject to
|
||||
// the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
// ************************************************************************/
|
||||
#endregion
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Web.UI;
|
||||
|
@ -9,18 +31,20 @@ using Nancy;
|
|||
using Nancy.Extensions;
|
||||
using Nancy.ModelBinding;
|
||||
using Nancy.Security;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
using RequestPlex.Api;
|
||||
using RequestPlex.Core;
|
||||
using RequestPlex.Store;
|
||||
using RequestPlex.Core.SettingModels;
|
||||
using RequestPlex.UI.Models;
|
||||
|
||||
namespace RequestPlex.UI.Modules
|
||||
{
|
||||
public class AdminModule : NancyModule
|
||||
{
|
||||
public AdminModule()
|
||||
private ISettingsService<RequestPlexSettings> Service { get; set; }
|
||||
public AdminModule(ISettingsService<RequestPlexSettings> service)
|
||||
{
|
||||
Service = service;
|
||||
#if !DEBUG
|
||||
this.RequiresAuthentication();
|
||||
#endif
|
||||
|
@ -41,8 +65,8 @@ namespace RequestPlex.UI.Modules
|
|||
dynamic model = new ExpandoObject();
|
||||
model.Errored = Request.Query.error.HasValue;
|
||||
model.Port = null;
|
||||
var s = new SettingsService();
|
||||
var settings = s.GetSettings();
|
||||
|
||||
var settings = Service.GetSettings();
|
||||
if (settings != null)
|
||||
{
|
||||
model.Port = settings.Port;
|
||||
|
@ -54,10 +78,9 @@ namespace RequestPlex.UI.Modules
|
|||
|
||||
private Response SaveAdmin()
|
||||
{
|
||||
var model = this.Bind<SettingsModel>();
|
||||
var model = this.Bind<RequestPlexSettings>();
|
||||
|
||||
var s = new SettingsService();
|
||||
s.SaveSettings(model);
|
||||
Service.SaveSettings(model);
|
||||
|
||||
|
||||
return Context.GetRedirect("~/admin");
|
||||
|
@ -74,20 +97,19 @@ namespace RequestPlex.UI.Modules
|
|||
|
||||
var plex = new PlexApi();
|
||||
var model = plex.GetToken(user.username, user.password);
|
||||
var s = new SettingsService();
|
||||
var oldSettings = s.GetSettings();
|
||||
var oldSettings = Service.GetSettings();
|
||||
if (oldSettings != null)
|
||||
{
|
||||
oldSettings.PlexAuthToken = model.user.authentication_token;
|
||||
s.SaveSettings(oldSettings);
|
||||
Service.SaveSettings(oldSettings);
|
||||
}
|
||||
else
|
||||
{
|
||||
var newModel = new SettingsModel
|
||||
var newModel = new RequestPlexSettings
|
||||
{
|
||||
PlexAuthToken = model.user.authentication_token
|
||||
};
|
||||
s.SaveSettings(newModel);
|
||||
Service.SaveSettings(newModel);
|
||||
}
|
||||
|
||||
return Context.GetRedirect("~/admin");
|
||||
|
@ -96,8 +118,7 @@ namespace RequestPlex.UI.Modules
|
|||
|
||||
private Response GetUsers()
|
||||
{
|
||||
var s = new SettingsService();
|
||||
var token = s.GetSettings().PlexAuthToken;
|
||||
var token = Service.GetSettings().PlexAuthToken;
|
||||
var api = new PlexApi();
|
||||
var users = api.GetUsers(token);
|
||||
var usernames = users.User.Select(x => x.Username);
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
using Nancy;
|
||||
using Nancy.Extensions;
|
||||
using Nancy.Responses;
|
||||
|
||||
namespace RequestPlex.UI.Modules
|
||||
{
|
||||
|
@ -6,8 +8,8 @@ namespace RequestPlex.UI.Modules
|
|||
{
|
||||
public IndexModule()
|
||||
{
|
||||
Get["/"] = parameters => View["Index"];
|
||||
Get["/Index"] = parameters => View["Index"];
|
||||
Get["/"] = parameters => Context.GetRedirect("~/search");
|
||||
Get["/Index"] = parameters => Context.GetRedirect("~/search");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,12 +1,43 @@
|
|||
using System.Linq;
|
||||
|
||||
using Nancy;
|
||||
using Nancy.Responses.Negotiation;
|
||||
|
||||
using RequestPlex.Api;
|
||||
using RequestPlex.Core;
|
||||
using RequestPlex.Core.SettingModels;
|
||||
using RequestPlex.Store;
|
||||
|
||||
namespace RequestPlex.UI.Modules
|
||||
{
|
||||
public class RequestsModule : NancyModule
|
||||
{
|
||||
public RequestsModule()
|
||||
private IRepository<RequestedModel> Service { get; set; }
|
||||
public RequestsModule(IRepository<RequestedModel> service)
|
||||
{
|
||||
Get["requests/"] = _ => "Hello!";
|
||||
Service = service;
|
||||
|
||||
Get["requests/"] = _ => LoadRequests();
|
||||
Get["requests/movies"] = _ => GetMovies();
|
||||
Get["requests/tvshows"] = _ => GetTvShows();
|
||||
}
|
||||
|
||||
|
||||
private Negotiator LoadRequests()
|
||||
{
|
||||
return View["Requests/Index"];
|
||||
}
|
||||
|
||||
private Response GetMovies()
|
||||
{
|
||||
var dbMovies = Service.GetAll().Where(x => x.Type == RequestType.Movie);
|
||||
return Response.AsJson(dbMovies);
|
||||
}
|
||||
|
||||
private Response GetTvShows()
|
||||
{
|
||||
var dbTv = Service.GetAll().Where(x => x.Type == RequestType.TvShow);
|
||||
return Response.AsJson(dbTv);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -37,7 +37,7 @@ namespace RequestPlex.UI.Modules
|
|||
Post["search/request/tv"] = parameters =>
|
||||
{
|
||||
var tvShowId = (int)Request.Form.tvId;
|
||||
var latest = (bool)Request.Form.latestSeason;
|
||||
var latest = (bool)Request.Form.latest;
|
||||
return RequestTvShow(tvShowId, latest);
|
||||
};
|
||||
}
|
||||
|
@ -49,7 +49,6 @@ namespace RequestPlex.UI.Modules
|
|||
|
||||
private Response SearchMovie(string searchTerm)
|
||||
{
|
||||
var s = new SettingsService();
|
||||
var api = new TheMovieDbApi();
|
||||
var movies = api.SearchMovie(searchTerm);
|
||||
var result = movies.Result;
|
||||
|
@ -87,14 +86,25 @@ namespace RequestPlex.UI.Modules
|
|||
{
|
||||
return Response.AsJson(new { Result = false, Message = "Movie has already been requested!" });
|
||||
}
|
||||
|
||||
s.AddRequest(movieId, RequestType.Movie);
|
||||
return Response.AsJson(new { Result = true });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Requests the tv show.
|
||||
/// </summary>
|
||||
/// <param name="showId">The show identifier.</param>
|
||||
/// <param name="latest">if set to <c>true</c> [latest].</param>
|
||||
/// <returns></returns>
|
||||
private Response RequestTvShow(int showId, bool latest)
|
||||
{
|
||||
// Latest send to Sonarr and no need to store in DB
|
||||
var s = new SettingsService();
|
||||
if (s.CheckRequest(showId))
|
||||
{
|
||||
return Response.AsJson(new { Result = false, Message = "TV Show has already been requested!" });
|
||||
}
|
||||
s.AddRequest(showId, RequestType.TvShow);
|
||||
return Response.AsJson(new {Result = true });
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue