mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-08 14:10:50 -07:00
Making the configuration actually do something. Setting a default configuration if there is no DB
This commit is contained in:
parent
c49e9a386b
commit
f2399d6407
10 changed files with 171 additions and 75 deletions
|
@ -32,7 +32,7 @@ namespace PlexRequests.Core.SettingModels
|
||||||
|
|
||||||
public bool SearchForMovies { get; set; }
|
public bool SearchForMovies { get; set; }
|
||||||
public bool SearchForTvShows { get; set; }
|
public bool SearchForTvShows { get; set; }
|
||||||
public bool RequireApprovial { get; set; }
|
public bool RequireApproval { get; set; }
|
||||||
public int WeeklyRequestLimit { get; set; }
|
public int WeeklyRequestLimit { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,10 @@
|
||||||
// ************************************************************************/
|
// ************************************************************************/
|
||||||
#endregion
|
#endregion
|
||||||
using Mono.Data.Sqlite;
|
using Mono.Data.Sqlite;
|
||||||
|
using PlexRequests.Core.SettingModels;
|
||||||
|
using PlexRequests.Helpers;
|
||||||
using PlexRequests.Store;
|
using PlexRequests.Store;
|
||||||
|
using PlexRequests.Store.Repository;
|
||||||
|
|
||||||
namespace PlexRequests.Core
|
namespace PlexRequests.Core
|
||||||
{
|
{
|
||||||
|
@ -36,9 +38,29 @@ namespace PlexRequests.Core
|
||||||
public string SetupDb()
|
public string SetupDb()
|
||||||
{
|
{
|
||||||
var db = new DbConfiguration(new SqliteFactory());
|
var db = new DbConfiguration(new SqliteFactory());
|
||||||
db.CheckDb();
|
var created = db.CheckDb();
|
||||||
TableCreation.CreateTables(db.DbConnection());
|
TableCreation.CreateTables(db.DbConnection());
|
||||||
|
|
||||||
|
if (created)
|
||||||
|
{
|
||||||
|
CreateDefaultSettingsPage();
|
||||||
|
}
|
||||||
|
|
||||||
return db.DbConnection().ConnectionString;
|
return db.DbConnection().ConnectionString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void CreateDefaultSettingsPage()
|
||||||
|
{
|
||||||
|
var defaultSettings = new PlexRequestSettings
|
||||||
|
{
|
||||||
|
RequireApproval = true,
|
||||||
|
SearchForMovies = true,
|
||||||
|
SearchForTvShows = true,
|
||||||
|
WeeklyRequestLimit = 0
|
||||||
|
};
|
||||||
|
var s = new SettingsServiceV2<PlexRequestSettings>(new JsonRepository(new DbConfiguration(new SqliteFactory()), new MemoryCacheProvider()));
|
||||||
|
s.SaveSettings(defaultSettings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,8 @@ using System.IO;
|
||||||
using Mono.Data.Sqlite;
|
using Mono.Data.Sqlite;
|
||||||
|
|
||||||
using NLog;
|
using NLog;
|
||||||
|
using PlexRequests.Helpers;
|
||||||
|
using PlexRequests.Store.Repository;
|
||||||
|
|
||||||
namespace PlexRequests.Store
|
namespace PlexRequests.Store
|
||||||
{
|
{
|
||||||
|
@ -44,14 +46,16 @@ namespace PlexRequests.Store
|
||||||
|
|
||||||
private SqliteFactory Factory { get; set; }
|
private SqliteFactory Factory { get; set; }
|
||||||
|
|
||||||
public virtual void CheckDb()
|
public virtual bool CheckDb()
|
||||||
{
|
{
|
||||||
Log.Trace("Checking DB");
|
Log.Trace("Checking DB");
|
||||||
if (!File.Exists(DbFile))
|
if (!File.Exists(DbFile))
|
||||||
{
|
{
|
||||||
Log.Trace("DB doesn't exist, creating a new one");
|
Log.Trace("DB doesn't exist, creating a new one");
|
||||||
CreateDatabase();
|
CreateDatabase();
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string DbFile = "RequestPlex.sqlite";
|
public string DbFile = "RequestPlex.sqlite";
|
||||||
|
|
|
@ -33,7 +33,7 @@ namespace PlexRequests.Store
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks the database.
|
/// Checks the database.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void CheckDb();
|
bool CheckDb();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the database connection.
|
/// Returns the database connection.
|
||||||
|
|
|
@ -30,7 +30,8 @@ using Humanizer;
|
||||||
|
|
||||||
using Nancy;
|
using Nancy;
|
||||||
using Nancy.Responses.Negotiation;
|
using Nancy.Responses.Negotiation;
|
||||||
|
using PlexRequests.Core;
|
||||||
|
using PlexRequests.Core.SettingModels;
|
||||||
using PlexRequests.Store;
|
using PlexRequests.Store;
|
||||||
using PlexRequests.UI.Models;
|
using PlexRequests.UI.Models;
|
||||||
|
|
||||||
|
@ -38,10 +39,11 @@ namespace PlexRequests.UI.Modules
|
||||||
{
|
{
|
||||||
public class RequestsModule : BaseModule
|
public class RequestsModule : BaseModule
|
||||||
{
|
{
|
||||||
private IRepository<RequestedModel> Service { get; set; }
|
|
||||||
public RequestsModule(IRepository<RequestedModel> service) : base("requests")
|
public RequestsModule(IRepository<RequestedModel> service, ISettingsService<PlexRequestSettings> prSettings) : base("requests")
|
||||||
{
|
{
|
||||||
Service = service;
|
Service = service;
|
||||||
|
PrSettings = prSettings;
|
||||||
|
|
||||||
Get["/"] = _ => LoadRequests();
|
Get["/"] = _ => LoadRequests();
|
||||||
Get["/movies"] = _ => GetMovies();
|
Get["/movies"] = _ => GetMovies();
|
||||||
|
@ -52,11 +54,13 @@ namespace PlexRequests.UI.Modules
|
||||||
return DeleteRequest((int)Request.Form.id, convertedType);
|
return DeleteRequest((int)Request.Form.id, convertedType);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
private IRepository<RequestedModel> Service { get; }
|
||||||
|
private ISettingsService<PlexRequestSettings> PrSettings { get; }
|
||||||
|
|
||||||
private Negotiator LoadRequests()
|
private Negotiator LoadRequests()
|
||||||
{
|
{
|
||||||
return View["Requests/Index"];
|
var settings = PrSettings.GetSettings();
|
||||||
|
return View["Requests/Index", settings];
|
||||||
}
|
}
|
||||||
|
|
||||||
private Response GetMovies()
|
private Response GetMovies()
|
||||||
|
|
|
@ -43,9 +43,10 @@ namespace PlexRequests.UI.Modules
|
||||||
{
|
{
|
||||||
public class SearchModule : BaseModule
|
public class SearchModule : BaseModule
|
||||||
{
|
{
|
||||||
public SearchModule(ICacheProvider cache, ISettingsService<CouchPotatoSettings> cpSettings) : base("search")
|
public SearchModule(ICacheProvider cache, ISettingsService<CouchPotatoSettings> cpSettings, ISettingsService<PlexRequestSettings> prSettings) : base("search")
|
||||||
{
|
{
|
||||||
CpService = cpSettings;
|
CpService = cpSettings;
|
||||||
|
PrService = prSettings;
|
||||||
MovieApi = new TheMovieDbApi();
|
MovieApi = new TheMovieDbApi();
|
||||||
TvApi = new TheTvDbApi();
|
TvApi = new TheTvDbApi();
|
||||||
Cache = cache;
|
Cache = cache;
|
||||||
|
@ -64,14 +65,17 @@ namespace PlexRequests.UI.Modules
|
||||||
private TheMovieDbApi MovieApi { get; }
|
private TheMovieDbApi MovieApi { get; }
|
||||||
private TheTvDbApi TvApi { get; }
|
private TheTvDbApi TvApi { get; }
|
||||||
private ICacheProvider Cache { get; }
|
private ICacheProvider Cache { get; }
|
||||||
private ISettingsService<CouchPotatoSettings> CpService { get; set; }
|
private ISettingsService<CouchPotatoSettings> CpService { get; }
|
||||||
|
private ISettingsService<PlexRequestSettings> PrService { get; }
|
||||||
private static Logger Log = LogManager.GetCurrentClassLogger();
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||||
private string AuthToken => Cache.GetOrSet(CacheKeys.TvDbToken, TvApi.Authenticate, 50);
|
private string AuthToken => Cache.GetOrSet(CacheKeys.TvDbToken, TvApi.Authenticate, 50);
|
||||||
|
|
||||||
private Negotiator RequestLoad()
|
private Negotiator RequestLoad()
|
||||||
{
|
{
|
||||||
|
var settings = PrService.GetSettings();
|
||||||
|
|
||||||
Log.Trace("Loading Index");
|
Log.Trace("Loading Index");
|
||||||
return View["Search/Index"];
|
return View["Search/Index", settings];
|
||||||
}
|
}
|
||||||
|
|
||||||
private Response SearchMovie(string searchTerm)
|
private Response SearchMovie(string searchTerm)
|
||||||
|
@ -148,14 +152,14 @@ namespace PlexRequests.UI.Modules
|
||||||
return Response.AsJson(new { Result = false, Message = "Movie has already been requested!" });
|
return Response.AsJson(new { Result = false, Message = "Movie has already been requested!" });
|
||||||
}
|
}
|
||||||
Log.Trace("movie with id {0} doesnt exists", movieId);
|
Log.Trace("movie with id {0} doesnt exists", movieId);
|
||||||
var settings = CpService.GetSettings();
|
var cpSettings = CpService.GetSettings();
|
||||||
if (settings.ApiKey == null)
|
if (cpSettings.ApiKey == null)
|
||||||
{
|
{
|
||||||
Log.Warn("CP apiKey is null");
|
Log.Warn("CP apiKey is null");
|
||||||
return Response.AsJson(new { Result = false, Message = "CouchPotato is not yet configured, If you are the Admin, please log in." });
|
return Response.AsJson(new { Result = false, Message = "CouchPotato is not yet configured, If you are the Admin, please log in." });
|
||||||
}
|
}
|
||||||
Log.Trace("Settings: ");
|
Log.Trace("Settings: ");
|
||||||
Log.Trace(settings.DumpJson);
|
Log.Trace(cpSettings.DumpJson);
|
||||||
|
|
||||||
var movieApi = new TheMovieDbApi();
|
var movieApi = new TheMovieDbApi();
|
||||||
var movieInfo = movieApi.GetMovieInformation(movieId).Result;
|
var movieInfo = movieApi.GetMovieInformation(movieId).Result;
|
||||||
|
@ -173,16 +177,22 @@ namespace PlexRequests.UI.Modules
|
||||||
ReleaseDate = movieInfo.ReleaseDate ?? DateTime.MinValue,
|
ReleaseDate = movieInfo.ReleaseDate ?? DateTime.MinValue,
|
||||||
Status = movieInfo.Status,
|
Status = movieInfo.Status,
|
||||||
RequestedDate = DateTime.Now,
|
RequestedDate = DateTime.Now,
|
||||||
Approved = false
|
Approved = false,
|
||||||
|
RequestedBy = Session[SessionKeys.UsernameKey].ToString()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
var settings = PrService.GetSettings();
|
||||||
|
if (!settings.RequireApproval)
|
||||||
|
{
|
||||||
var cp = new CouchPotatoApi();
|
var cp = new CouchPotatoApi();
|
||||||
Log.Trace("Adding movie to CP");
|
Log.Trace("Adding movie to CP (No approval required)");
|
||||||
var result = cp.AddMovie(model.ImdbId, settings.ApiKey, model.Title, settings.FullUri);
|
var result = cp.AddMovie(model.ImdbId, cpSettings.ApiKey, model.Title, cpSettings.FullUri);
|
||||||
Log.Trace("Adding movie to CP result {0}", result);
|
Log.Trace("Adding movie to CP result {0}", result);
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
Log.Trace("Adding movie to database requests");
|
model.Approved = true;
|
||||||
|
Log.Trace("Adding movie to database requests (No approval required)");
|
||||||
s.AddRequest(movieId, model);
|
s.AddRequest(movieId, model);
|
||||||
|
|
||||||
return Response.AsJson(new { Result = true });
|
return Response.AsJson(new { Result = true });
|
||||||
|
@ -190,6 +200,20 @@ namespace PlexRequests.UI.Modules
|
||||||
return Response.AsJson(new { Result = false, Message = "Something went wrong adding the movie to CouchPotato! Please check your settings." });
|
return Response.AsJson(new { Result = false, Message = "Something went wrong adding the movie to CouchPotato! Please check your settings." });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Log.Trace("Adding movie to database requests");
|
||||||
|
s.AddRequest(movieId, model);
|
||||||
|
return Response.AsJson(new { Result = true });
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Fatal(e);
|
||||||
|
|
||||||
|
return Response.AsJson(new { Result = false, Message = "Something went wrong adding the movie to CouchPotato! Please check your settings." });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Requests the tv show.
|
/// Requests the tv show.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -223,7 +247,8 @@ namespace PlexRequests.UI.Modules
|
||||||
ReleaseDate = firstAir,
|
ReleaseDate = firstAir,
|
||||||
Status = showInfo.status,
|
Status = showInfo.status,
|
||||||
RequestedDate = DateTime.Now,
|
RequestedDate = DateTime.Now,
|
||||||
Approved = false
|
Approved = false,
|
||||||
|
RequestedBy = Session[SessionKeys.UsernameKey].ToString()
|
||||||
};
|
};
|
||||||
|
|
||||||
s.AddRequest(showId, model);
|
s.AddRequest(showId, model);
|
||||||
|
|
|
@ -54,6 +54,23 @@
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="RequireApproval" class="col-lg-2 control-label">Require approval of requests</label>
|
||||||
|
|
||||||
|
<div class="col-lg-10 checkbox">
|
||||||
|
<label>
|
||||||
|
@if (Model.RequireApproval)
|
||||||
|
{
|
||||||
|
<input type="checkbox" id="RequireApproval" name="RequireApproval" checked="checked">
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
<input type="checkbox" id="RequireApproval" name="RequireApproval">
|
||||||
|
}
|
||||||
|
</label>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="WeeklyRequestLimit" class="col-lg-2 control-label">Weekly Request Limit</label>
|
<label for="WeeklyRequestLimit" class="col-lg-2 control-label">Weekly Request Limit</label>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<div class="col-lg-3 col-md-3 col-sm-4">
|
<div class="col-lg-3 col-md-3 col-sm-4">
|
||||||
<div class="list-group table-of-contents">
|
<div class="list-group table-of-contents">
|
||||||
<a class="list-group-item" href="/admin">Request Plex Settings</a>
|
<a class="list-group-item" href="/admin">Plex Request Settings</a>
|
||||||
<a class="list-group-item" href="/admin/authentication">Authentication</a>
|
<a class="list-group-item" href="/admin/authentication">Authentication</a>
|
||||||
<a class="list-group-item" href="/admin/couchpotato">CouchPotato Settings</a>
|
<a class="list-group-item" href="/admin/couchpotato">CouchPotato Settings</a>
|
||||||
<a class="list-group-item" href="/admin/sonarr">Sonarr Settings</a>
|
<a class="list-group-item" href="/admin/sonarr">Sonarr Settings</a>
|
||||||
|
|
|
@ -3,14 +3,21 @@
|
||||||
<h4>Below you can see yours and all other requests, as well as their download and approval status.</h4>
|
<h4>Below you can see yours and all other requests, as well as their download and approval status.</h4>
|
||||||
<!-- Nav tabs -->
|
<!-- Nav tabs -->
|
||||||
<ul id="nav-tabs" class="nav nav-tabs" role="tablist">
|
<ul id="nav-tabs" class="nav nav-tabs" role="tablist">
|
||||||
|
@if (Model.SearchForMovies)
|
||||||
|
{
|
||||||
<li role="presentation" class="active"><a href="#MoviesTab" aria-controls="home" role="tab" data-toggle="tab">Movies</a></li>
|
<li role="presentation" class="active"><a href="#MoviesTab" aria-controls="home" role="tab" data-toggle="tab">Movies</a></li>
|
||||||
|
}
|
||||||
|
@if (Model.SearchForTvShows)
|
||||||
|
{
|
||||||
<li role="presentation"><a href="#TvShowTab" aria-controls="profile" role="tab" data-toggle="tab">TV Shows</a></li>
|
<li role="presentation"><a href="#TvShowTab" aria-controls="profile" role="tab" data-toggle="tab">TV Shows</a></li>
|
||||||
|
}
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<!-- Tab panes -->
|
<!-- Tab panes -->
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
|
@if (Model.SearchForMovies)
|
||||||
|
{
|
||||||
<!-- Movie tab -->
|
<!-- Movie tab -->
|
||||||
<div role="tabpanel" class="tab-pane active" id="MoviesTab">
|
<div role="tabpanel" class="tab-pane active" id="MoviesTab">
|
||||||
<br />
|
<br />
|
||||||
|
@ -19,7 +26,10 @@
|
||||||
<div id="movieList">
|
<div id="movieList">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
@if (Model.SearchForTvShows)
|
||||||
|
{
|
||||||
<!-- TV tab -->
|
<!-- TV tab -->
|
||||||
<div role="tabpanel" class="tab-pane" id="TvShowTab">
|
<div role="tabpanel" class="tab-pane" id="TvShowTab">
|
||||||
<br />
|
<br />
|
||||||
|
@ -28,6 +38,7 @@
|
||||||
<div id="tvList">
|
<div id="tvList">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,16 +1,23 @@
|
||||||
<div>
|
<div>
|
||||||
<h2>Search</h2>
|
<h2>Search</h2>
|
||||||
<h4>Want to wacth something that is not currently on Plex?! No problem! Just search for it below and request it!</h4>
|
<h4>Want to watch something that is not currently on Plex?! No problem! Just search for it below and request it!</h4>
|
||||||
<!-- Nav tabs -->
|
<!-- Nav tabs -->
|
||||||
<ul id="nav-tabs" class="nav nav-tabs" role="tablist">
|
<ul id="nav-tabs" class="nav nav-tabs" role="tablist">
|
||||||
|
@if (Model.SearchForMovies)
|
||||||
|
{
|
||||||
<li role="presentation" class="active"><a href="#MoviesTab" aria-controls="home" role="tab" data-toggle="tab">Movies</a></li>
|
<li role="presentation" class="active"><a href="#MoviesTab" aria-controls="home" role="tab" data-toggle="tab">Movies</a></li>
|
||||||
|
}
|
||||||
|
@if (Model.SearchForTvShows)
|
||||||
|
{
|
||||||
<li role="presentation"><a href="#TvShowTab" aria-controls="profile" role="tab" data-toggle="tab">TV Shows</a></li>
|
<li role="presentation"><a href="#TvShowTab" aria-controls="profile" role="tab" data-toggle="tab">TV Shows</a></li>
|
||||||
|
}
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<!-- Tab panes -->
|
<!-- Tab panes -->
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
|
@if (Model.SearchForMovies)
|
||||||
|
{
|
||||||
<!-- Movie tab -->
|
<!-- Movie tab -->
|
||||||
<div role="tabpanel" class="tab-pane active" id="MoviesTab">
|
<div role="tabpanel" class="tab-pane active" id="MoviesTab">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
|
@ -25,7 +32,11 @@
|
||||||
<div id="movieList">
|
<div id="movieList">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@if (Model.SearchForTvShows)
|
||||||
|
{
|
||||||
<!-- TV tab -->
|
<!-- TV tab -->
|
||||||
<div role="tabpanel" class="tab-pane" id="TvShowTab">
|
<div role="tabpanel" class="tab-pane" id="TvShowTab">
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
|
@ -40,8 +51,10 @@
|
||||||
<div id="tvList">
|
<div id="tvList">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue