mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-21 05:43:19 -07:00
more borken build
This commit is contained in:
parent
b7f63ed1ce
commit
c4fcc4f2f2
22 changed files with 584 additions and 78 deletions
|
@ -1,9 +1,9 @@
|
||||||
;https://docs.microsoft.com/en-us/dotnet/articles/core/deploying/
|
;https://docs.microsoft.com/en-us/dotnet/articles/core/deploying/
|
||||||
cd ..
|
cd ..
|
||||||
dotnet restore
|
dotnet restore
|
||||||
dotnet publish -c Release -r win10-x64
|
dotnet publish -c Release /p:AppRuntimeIdentifier=win10-x64
|
||||||
dotnet publish -c Release -r osx.10.12-x64
|
dotnet publish -c Release /p:AppRuntimeIdentifier=osx.10.12-x64
|
||||||
dotnet publish -c Release -r ubuntu.16.10-x64
|
dotnet publish -c Release /p:AppRuntimeIdentifier=ubuntu.16.10-x64
|
||||||
dotnet publish -c Release -r debian.8-x64
|
dotnet publish -c Release /p:AppRuntimeIdentifier=debian.8-x64
|
||||||
|
|
||||||
exit
|
exit
|
14
Ombi/Ombi.Core/Settings/ISettingsService.cs
Normal file
14
Ombi/Ombi.Core/Settings/ISettingsService.cs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Ombi.Core.Settings
|
||||||
|
{
|
||||||
|
public interface ISettingsService<T>
|
||||||
|
{
|
||||||
|
T GetSettings();
|
||||||
|
Task<T> GetSettingsAsync();
|
||||||
|
bool SaveSettings(T model);
|
||||||
|
Task<bool> SaveSettingsAsync(T model);
|
||||||
|
bool Delete(T model);
|
||||||
|
Task<bool> DeleteAsync(T model);
|
||||||
|
}
|
||||||
|
}
|
7
Ombi/Ombi.Core/Settings/Models/Settings.cs
Normal file
7
Ombi/Ombi.Core/Settings/Models/Settings.cs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
namespace Ombi.Core.Settings.Models
|
||||||
|
{
|
||||||
|
public class Settings
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
}
|
||||||
|
}
|
129
Ombi/Ombi.Core/Settings/SettingsService.cs
Normal file
129
Ombi/Ombi.Core/Settings/SettingsService.cs
Normal file
|
@ -0,0 +1,129 @@
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using Ombi.Helpers;
|
||||||
|
using Ombi.Store.Entities;
|
||||||
|
using Ombi.Store.Repository;
|
||||||
|
|
||||||
|
namespace Ombi.Core.Settings
|
||||||
|
{
|
||||||
|
public class SettingsServiceV2<T> : ISettingsService<T>
|
||||||
|
where T : Models.Settings, new()
|
||||||
|
{
|
||||||
|
|
||||||
|
public SettingsServiceV2(ISettingsRepository repo)
|
||||||
|
{
|
||||||
|
Repo = repo;
|
||||||
|
EntityName = typeof(T).Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ISettingsRepository Repo { get; }
|
||||||
|
private string EntityName { get; }
|
||||||
|
|
||||||
|
public T GetSettings()
|
||||||
|
{
|
||||||
|
var result = Repo.Get(EntityName);
|
||||||
|
if (result == null)
|
||||||
|
{
|
||||||
|
return new T();
|
||||||
|
}
|
||||||
|
result.Content = DecryptSettings(result);
|
||||||
|
var obj = string.IsNullOrEmpty(result.Content) ? null : JsonConvert.DeserializeObject<T>(result.Content, SerializerSettings.Settings);
|
||||||
|
|
||||||
|
var model = obj;
|
||||||
|
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<T> GetSettingsAsync()
|
||||||
|
{
|
||||||
|
var result = await Repo.GetAsync(EntityName).ConfigureAwait(false);
|
||||||
|
if (result == null)
|
||||||
|
{
|
||||||
|
return new T();
|
||||||
|
}
|
||||||
|
result.Content = DecryptSettings(result);
|
||||||
|
return string.IsNullOrEmpty(result.Content) ? null : JsonConvert.DeserializeObject<T>(result.Content, SerializerSettings.Settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool SaveSettings(T model)
|
||||||
|
{
|
||||||
|
var entity = Repo.Get(EntityName);
|
||||||
|
|
||||||
|
if (entity == null)
|
||||||
|
{
|
||||||
|
var newEntity = model;
|
||||||
|
|
||||||
|
var settings = new GlobalSettings { SettingsName = EntityName, Content = JsonConvert.SerializeObject(newEntity, SerializerSettings.Settings) };
|
||||||
|
settings.Content = EncryptSettings(settings);
|
||||||
|
var insertResult = Repo.Insert(settings);
|
||||||
|
|
||||||
|
return insertResult != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
var modified = model;
|
||||||
|
modified.Id = entity.Id;
|
||||||
|
|
||||||
|
var globalSettings = new GlobalSettings { SettingsName = EntityName, Content = JsonConvert.SerializeObject(modified, SerializerSettings.Settings), Id = entity.Id };
|
||||||
|
globalSettings.Content = EncryptSettings(globalSettings);
|
||||||
|
Repo.Update(globalSettings);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<bool> SaveSettingsAsync(T model)
|
||||||
|
{
|
||||||
|
var entity = await Repo.GetAsync(EntityName);
|
||||||
|
|
||||||
|
if (entity == null)
|
||||||
|
{
|
||||||
|
var newEntity = model;
|
||||||
|
|
||||||
|
var settings = new GlobalSettings { SettingsName = EntityName, Content = JsonConvert.SerializeObject(newEntity, SerializerSettings.Settings) };
|
||||||
|
settings.Content = EncryptSettings(settings);
|
||||||
|
var insertResult = await Repo.InsertAsync(settings).ConfigureAwait(false);
|
||||||
|
|
||||||
|
return insertResult != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var modified = model;
|
||||||
|
modified.Id = entity.Id;
|
||||||
|
|
||||||
|
var globalSettings = new GlobalSettings { SettingsName = EntityName, Content = JsonConvert.SerializeObject(modified, SerializerSettings.Settings), Id = entity.Id };
|
||||||
|
globalSettings.Content = EncryptSettings(globalSettings);
|
||||||
|
await Repo.UpdateAsync(globalSettings).ConfigureAwait(false);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Delete(T model)
|
||||||
|
{
|
||||||
|
var entity = Repo.Get(EntityName);
|
||||||
|
if (entity != null)
|
||||||
|
{
|
||||||
|
Repo.Delete(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task DeleteAsync(T model)
|
||||||
|
{
|
||||||
|
var entity = Repo.Get(EntityName);
|
||||||
|
if (entity != null)
|
||||||
|
{
|
||||||
|
await Repo.DeleteAsync(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private string EncryptSettings(GlobalSettings settings)
|
||||||
|
{
|
||||||
|
return StringCipher.Encrypt(settings.Content, settings.SettingsName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private string DecryptSettings(GlobalSettings settings)
|
||||||
|
{
|
||||||
|
return StringCipher.Decrypt(settings.Content, settings.SettingsName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
57
Ombi/Ombi.DependencyInjection/IocExtensions.cs
Normal file
57
Ombi/Ombi.DependencyInjection/IocExtensions.cs
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
using Ombi.Core;
|
||||||
|
using Ombi.Core.Engine;
|
||||||
|
using Ombi.Core.Models.Requests;
|
||||||
|
using Ombi.Core.Requests.Models;
|
||||||
|
using Ombi.Core.Settings;
|
||||||
|
using Ombi.Store.Context;
|
||||||
|
using Ombi.Store.Repository;
|
||||||
|
using Ombi.TheMovieDbApi;
|
||||||
|
|
||||||
|
namespace Ombi.DependencyInjection
|
||||||
|
{
|
||||||
|
[SuppressMessage("ReSharper", "MemberCanBePrivate.Global")]
|
||||||
|
public static class IocExtensions
|
||||||
|
{
|
||||||
|
public static IServiceCollection RegisterDependencies(this IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.RegisterEngines();
|
||||||
|
services.RegisterApi();
|
||||||
|
services.RegisterServices();
|
||||||
|
services.RegisterStore();
|
||||||
|
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IServiceCollection RegisterEngines(this IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddTransient<IMovieEngine, MovieEngine>();
|
||||||
|
services.AddTransient<IRequestEngine, RequestEngine>();
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IServiceCollection RegisterApi(this IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddTransient<IMovieDbApi, TheMovieDbApi.TheMovieDbApi>();
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static IServiceCollection RegisterStore(this IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddEntityFrameworkSqlite().AddDbContext<OmbiContext>();
|
||||||
|
|
||||||
|
services.AddTransient<IOmbiContext, OmbiContext>();
|
||||||
|
services.AddTransient<IRequestRepository, RequestJsonRepository>();
|
||||||
|
services.AddTransient<ISettingsRepository, SettingsJsonRepository>();
|
||||||
|
services.AddTransient(typeof(ISettingsService<>), typeof(SettingsServiceV2<>));
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
public static IServiceCollection RegisterServices(this IServiceCollection services)
|
||||||
|
{
|
||||||
|
services.AddTransient<IRequestService, JsonRequestService>();
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netstandard1.4</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\Ombi.Core\Ombi.Core.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Reference Include="Microsoft.Extensions.DependencyInjection.Abstractions">
|
||||||
|
<HintPath>..\..\..\..\..\.nuget\packages\microsoft.extensions.dependencyinjection.abstractions\1.1.0\lib\netstandard1.0\Microsoft.Extensions.DependencyInjection.Abstractions.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
15
Ombi/Ombi.Helpers/SerializerSettings.cs
Normal file
15
Ombi/Ombi.Helpers/SerializerSettings.cs
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace Ombi.Helpers
|
||||||
|
{
|
||||||
|
public static class SerializerSettings
|
||||||
|
{
|
||||||
|
public static readonly JsonSerializerSettings Settings = new JsonSerializerSettings
|
||||||
|
{
|
||||||
|
Formatting = Formatting.None,
|
||||||
|
//TypeNameHandling = TypeNameHandling.Objects,
|
||||||
|
//TypeNameAssemblyFormat = FormatterAssemblyStyle.Simple,
|
||||||
|
NullValueHandling = NullValueHandling.Ignore
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
120
Ombi/Ombi.Helpers/StringCipher.cs
Normal file
120
Ombi/Ombi.Helpers/StringCipher.cs
Normal file
|
@ -0,0 +1,120 @@
|
||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Ombi.Helpers
|
||||||
|
{
|
||||||
|
public class StringCipher
|
||||||
|
{
|
||||||
|
// This constant determines the number of iterations for the password bytes generation function.
|
||||||
|
private const int DerivationIterations = 1000;
|
||||||
|
// This constant is used to determine the keysize of the encryption algorithm in bits.
|
||||||
|
// We divide this by 8 within the code below to get the equivalent number of bytes.
|
||||||
|
private const int Keysize = 256;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Decrypts the specified cipher text.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="cipherText">The cipher text.</param>
|
||||||
|
/// <param name="passPhrase">The pass phrase.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string Decrypt(string cipherText, string passPhrase)
|
||||||
|
{
|
||||||
|
// Get the complete stream of bytes that represent:
|
||||||
|
// [32 bytes of Salt] + [32 bytes of IV] + [n bytes of CipherText]
|
||||||
|
var cipherTextBytesWithSaltAndIv = Convert.FromBase64String(cipherText);
|
||||||
|
// Get the saltbytes by extracting the first 32 bytes from the supplied cipherText bytes.
|
||||||
|
var saltStringBytes = cipherTextBytesWithSaltAndIv.Take(Keysize / 8).ToArray();
|
||||||
|
// Get the IV bytes by extracting the next 32 bytes from the supplied cipherText bytes.
|
||||||
|
var ivStringBytes = cipherTextBytesWithSaltAndIv.Skip(Keysize / 8).Take(Keysize / 8).ToArray();
|
||||||
|
// Get the actual cipher text bytes by removing the first 64 bytes from the cipherText string.
|
||||||
|
var cipherTextBytes = cipherTextBytesWithSaltAndIv.Skip((Keysize / 8) * 2).Take(cipherTextBytesWithSaltAndIv.Length - ((Keysize / 8) * 2)).ToArray();
|
||||||
|
|
||||||
|
using (var password = new Rfc2898DeriveBytes(passPhrase, saltStringBytes, DerivationIterations))
|
||||||
|
{
|
||||||
|
var keyBytes = password.GetBytes(Keysize / 8);
|
||||||
|
var aes = Aes.Create();
|
||||||
|
using (var symmetricKey = new RijndaelManaged())
|
||||||
|
{
|
||||||
|
symmetricKey.BlockSize = 256;
|
||||||
|
symmetricKey.Mode = CipherMode.CBC;
|
||||||
|
symmetricKey.Padding = PaddingMode.PKCS7;
|
||||||
|
using (var decryptor = symmetricKey.CreateDecryptor(keyBytes, ivStringBytes))
|
||||||
|
{
|
||||||
|
using (var memoryStream = new MemoryStream(cipherTextBytes))
|
||||||
|
{
|
||||||
|
using (var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read))
|
||||||
|
{
|
||||||
|
var plainTextBytes = new byte[cipherTextBytes.Length];
|
||||||
|
var decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);
|
||||||
|
memoryStream.Close();
|
||||||
|
cryptoStream.Close();
|
||||||
|
return Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Encrypts the specified plain text.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="plainText">The plain text.</param>
|
||||||
|
/// <param name="passPhrase">The pass phrase.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
public static string Encrypt(string plainText, string passPhrase)
|
||||||
|
{
|
||||||
|
// Salt and IV is randomly generated each time, but is preprended to encrypted cipher text
|
||||||
|
// so that the same Salt and IV values can be used when decrypting.
|
||||||
|
var saltStringBytes = Generate256BitsOfRandomEntropy();
|
||||||
|
var ivStringBytes = Generate256BitsOfRandomEntropy();
|
||||||
|
var plainTextBytes = Encoding.UTF8.GetBytes(plainText);
|
||||||
|
using (var password = new Rfc2898DeriveBytes(passPhrase, saltStringBytes, DerivationIterations))
|
||||||
|
{
|
||||||
|
var keyBytes = password.GetBytes(Keysize / 8);
|
||||||
|
using (var symmetricKey = new RijndaelManaged())
|
||||||
|
{
|
||||||
|
symmetricKey.BlockSize = 256;
|
||||||
|
symmetricKey.Mode = CipherMode.CBC;
|
||||||
|
symmetricKey.Padding = PaddingMode.PKCS7;
|
||||||
|
using (var encryptor = symmetricKey.CreateEncryptor(keyBytes, ivStringBytes))
|
||||||
|
{
|
||||||
|
using (var memoryStream = new MemoryStream())
|
||||||
|
{
|
||||||
|
using (var cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write))
|
||||||
|
{
|
||||||
|
cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
|
||||||
|
cryptoStream.FlushFinalBlock();
|
||||||
|
// Create the final bytes as a concatenation of the random salt bytes, the random iv bytes and the cipher bytes.
|
||||||
|
var cipherTextBytes = saltStringBytes;
|
||||||
|
cipherTextBytes = cipherTextBytes.Concat(ivStringBytes).ToArray();
|
||||||
|
cipherTextBytes = cipherTextBytes.Concat(memoryStream.ToArray()).ToArray();
|
||||||
|
memoryStream.Close();
|
||||||
|
cryptoStream.Close();
|
||||||
|
return Convert.ToBase64String(cipherTextBytes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generate256s the bits of random entropy.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
private static byte[] Generate256BitsOfRandomEntropy()
|
||||||
|
{
|
||||||
|
var randomBytes = new byte[32]; // 32 Bytes will give us 256 bits.
|
||||||
|
using (var rngCsp = new RNGCryptoServiceProvider())
|
||||||
|
{
|
||||||
|
// Fill the array with cryptographically secure random bytes.
|
||||||
|
rngCsp.GetBytes(randomBytes);
|
||||||
|
}
|
||||||
|
return randomBytes;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,5 +11,6 @@ namespace Ombi.Store.Context
|
||||||
int SaveChanges();
|
int SaveChanges();
|
||||||
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default(CancellationToken));
|
Task<int> SaveChangesAsync(CancellationToken cancellationToken = default(CancellationToken));
|
||||||
DbSet<RequestBlobs> Requests { get; set; }
|
DbSet<RequestBlobs> Requests { get; set; }
|
||||||
|
DbSet<GlobalSettings> Settings { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,17 +5,17 @@ namespace Ombi.Store.Context
|
||||||
{
|
{
|
||||||
public class OmbiContext : DbContext, IOmbiContext
|
public class OmbiContext : DbContext, IOmbiContext
|
||||||
{
|
{
|
||||||
private static bool _created = false;
|
private static bool _created;
|
||||||
public OmbiContext()
|
public OmbiContext()
|
||||||
{
|
{
|
||||||
if(!_created)
|
if (_created) return;
|
||||||
{
|
|
||||||
_created = true;
|
_created = true;
|
||||||
//Database.EnsureDeleted();
|
Database.EnsureCreated();
|
||||||
Database.EnsureCreated();
|
Database.Migrate();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
public DbSet<RequestBlobs> Requests { get; set; }
|
public DbSet<RequestBlobs> Requests { get; set; }
|
||||||
|
public DbSet<GlobalSettings> Settings { get; set; }
|
||||||
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
{
|
{
|
||||||
|
|
11
Ombi/Ombi.Store/Entities/GlobalSettings.cs
Normal file
11
Ombi/Ombi.Store/Entities/GlobalSettings.cs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace Ombi.Store.Entities
|
||||||
|
{
|
||||||
|
[Table("GlobalSettings")]
|
||||||
|
public class GlobalSettings : Entity
|
||||||
|
{
|
||||||
|
public string Content { get; set; }
|
||||||
|
public string SettingsName { get; set; }
|
||||||
|
}
|
||||||
|
}
|
49
Ombi/Ombi.Store/Repository/ISettingsRepository.cs
Normal file
49
Ombi/Ombi.Store/Repository/ISettingsRepository.cs
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Ombi.Store.Entities;
|
||||||
|
|
||||||
|
namespace Ombi.Store.Repository
|
||||||
|
{
|
||||||
|
public interface ISettingsRepository
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Inserts the specified entity.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">The entity.</param>
|
||||||
|
GlobalSettings Insert(GlobalSettings entity);
|
||||||
|
Task<GlobalSettings> InsertAsync(GlobalSettings entity);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets all.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
IEnumerable<GlobalSettings> GetAll();
|
||||||
|
Task<IEnumerable<GlobalSettings>> GetAllAsync();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the specified identifier.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="settingsName">Name of the settings.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
GlobalSettings Get(string settingsName);
|
||||||
|
Task<GlobalSettings> GetAsync(string settingsName);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Deletes the specified entity.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">The entity.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task DeleteAsync(GlobalSettings entity);
|
||||||
|
void Delete(GlobalSettings entity);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Updates the specified entity.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="entity">The entity.</param>
|
||||||
|
/// <returns></returns>
|
||||||
|
Task UpdateAsync(GlobalSettings entity);
|
||||||
|
void Update(GlobalSettings entity);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
84
Ombi/Ombi.Store/Repository/SettingsJsonRepository.cs
Normal file
84
Ombi/Ombi.Store/Repository/SettingsJsonRepository.cs
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Ombi.Store.Context;
|
||||||
|
using Ombi.Store.Entities;
|
||||||
|
|
||||||
|
namespace Ombi.Store.Repository
|
||||||
|
{
|
||||||
|
public class SettingsJsonRepository : ISettingsRepository
|
||||||
|
{
|
||||||
|
public SettingsJsonRepository(IOmbiContext ctx)
|
||||||
|
{
|
||||||
|
Db = ctx;
|
||||||
|
}
|
||||||
|
|
||||||
|
private IOmbiContext Db { get; }
|
||||||
|
|
||||||
|
public GlobalSettings Insert(GlobalSettings entity)
|
||||||
|
{
|
||||||
|
|
||||||
|
var settings = Db.Settings.Add(entity);
|
||||||
|
Db.SaveChanges();
|
||||||
|
return settings.Entity;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<GlobalSettings> InsertAsync(GlobalSettings entity)
|
||||||
|
{
|
||||||
|
|
||||||
|
var settings = await Db.Settings.AddAsync(entity).ConfigureAwait(false);
|
||||||
|
await Db.SaveChangesAsync().ConfigureAwait(false);
|
||||||
|
return settings.Entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<GlobalSettings> GetAll()
|
||||||
|
{
|
||||||
|
|
||||||
|
var page = Db.Settings.ToList();
|
||||||
|
return page;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<IEnumerable<GlobalSettings>> GetAllAsync()
|
||||||
|
{
|
||||||
|
var page = await Db.Settings.ToListAsync();
|
||||||
|
return page;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GlobalSettings Get(string pageName)
|
||||||
|
{
|
||||||
|
return Db.Settings.FirstOrDefault(x => x.SettingsName == pageName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task<GlobalSettings> GetAsync(string settingsName)
|
||||||
|
{
|
||||||
|
return await Db.Settings.FirstOrDefaultAsync(x => x.SettingsName == settingsName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task DeleteAsync(GlobalSettings entity)
|
||||||
|
{
|
||||||
|
Db.Settings.Remove(entity);
|
||||||
|
await Db.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task UpdateAsync(GlobalSettings entity)
|
||||||
|
{
|
||||||
|
Db.Settings.Update(entity);
|
||||||
|
await Db.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Delete(GlobalSettings entity)
|
||||||
|
{
|
||||||
|
Db.Settings.Remove(entity);
|
||||||
|
Db.SaveChanges();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(GlobalSettings entity)
|
||||||
|
{
|
||||||
|
Db.Settings.Update(entity);
|
||||||
|
Db.SaveChanges();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,6 +24,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ombi.Helpers", "Ombi.Helper
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ombi.Store", "Ombi.Store\Ombi.Store.csproj", "{68086581-1EFD-4390-8100-47F87D1CB628}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Ombi.Store", "Ombi.Store\Ombi.Store.csproj", "{68086581-1EFD-4390-8100-47F87D1CB628}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ombi.DependencyInjection", "Ombi.DependencyInjection\Ombi.DependencyInjection.csproj", "{B39E4558-C557-48E7-AA74-19C5CD809617}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
@ -54,6 +56,10 @@ Global
|
||||||
{68086581-1EFD-4390-8100-47F87D1CB628}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{68086581-1EFD-4390-8100-47F87D1CB628}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{68086581-1EFD-4390-8100-47F87D1CB628}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{68086581-1EFD-4390-8100-47F87D1CB628}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{68086581-1EFD-4390-8100-47F87D1CB628}.Release|Any CPU.Build.0 = Release|Any CPU
|
{68086581-1EFD-4390-8100-47F87D1CB628}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{B39E4558-C557-48E7-AA74-19C5CD809617}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{B39E4558-C557-48E7-AA74-19C5CD809617}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{B39E4558-C557-48E7-AA74-19C5CD809617}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{B39E4558-C557-48E7-AA74-19C5CD809617}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|
|
@ -19,12 +19,19 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="ViewModels\" />
|
|
||||||
<Folder Include="wwwroot\**" />
|
<Folder Include="wwwroot\**" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Remove="ViewModels\**" />
|
||||||
|
<Content Remove="ViewModels\**" />
|
||||||
|
<EmbeddedResource Remove="ViewModels\**" />
|
||||||
|
<None Remove="ViewModels\**" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Ombi.Core\Ombi.Core.csproj" />
|
<ProjectReference Include="..\Ombi.Core\Ombi.Core.csproj" />
|
||||||
|
<ProjectReference Include="..\Ombi.DependencyInjection\Ombi.DependencyInjection.csproj" />
|
||||||
<ProjectReference Include="..\Ombi.TheMovieDbApi\Ombi.TheMovieDbApi.csproj" />
|
<ProjectReference Include="..\Ombi.TheMovieDbApi\Ombi.TheMovieDbApi.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -1,8 +1,4 @@
|
||||||
using System;
|
using System.IO;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
|
@ -12,13 +8,8 @@ using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.FileProviders;
|
using Microsoft.Extensions.FileProviders;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Ombi.Core;
|
using Ombi.DependencyInjection;
|
||||||
using Ombi.Core.Engine;
|
|
||||||
using Ombi.Core.Models.Requests;
|
|
||||||
using Ombi.Core.Requests.Models;
|
|
||||||
using Ombi.Store.Context;
|
using Ombi.Store.Context;
|
||||||
using Ombi.Store.Repository;
|
|
||||||
using Ombi.TheMovieDbApi;
|
|
||||||
|
|
||||||
namespace Ombi
|
namespace Ombi
|
||||||
{
|
{
|
||||||
|
@ -28,17 +19,11 @@ namespace Ombi
|
||||||
{
|
{
|
||||||
var builder = new ConfigurationBuilder()
|
var builder = new ConfigurationBuilder()
|
||||||
.SetBasePath(env.ContentRootPath)
|
.SetBasePath(env.ContentRootPath)
|
||||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
|
.AddJsonFile("appsettings.json", false, true)
|
||||||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
|
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", true)
|
||||||
.AddEnvironmentVariables();
|
.AddEnvironmentVariables();
|
||||||
Configuration = builder.Build();
|
Configuration = builder.Build();
|
||||||
|
|
||||||
using (var ctx = new OmbiContext())
|
|
||||||
{
|
|
||||||
ctx.Database.EnsureCreated();
|
|
||||||
ctx.Database.Migrate();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public IConfigurationRoot Configuration { get; }
|
public IConfigurationRoot Configuration { get; }
|
||||||
|
@ -48,13 +33,7 @@ namespace Ombi
|
||||||
{
|
{
|
||||||
// Add framework services.
|
// Add framework services.
|
||||||
services.AddMvc();
|
services.AddMvc();
|
||||||
services.AddEntityFrameworkSqlite().AddDbContext<OmbiContext>();
|
services.RegisterDependencies(); // Ioc and EF
|
||||||
services.AddTransient<IMovieEngine, MovieEngine>();
|
|
||||||
services.AddTransient<IRequestEngine, RequestEngine>();
|
|
||||||
services.AddTransient<IMovieDbApi, TheMovieDbApi.TheMovieDbApi>();
|
|
||||||
services.AddTransient<IRequestService, JsonRequestService>();
|
|
||||||
services.AddTransient<IOmbiContext, OmbiContext>();
|
|
||||||
services.AddTransient<IRequestRepository, RequestJsonRepository>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
|
@ -66,7 +45,6 @@ namespace Ombi
|
||||||
if (env.IsDevelopment())
|
if (env.IsDevelopment())
|
||||||
{
|
{
|
||||||
app.UseDeveloperExceptionPage();
|
app.UseDeveloperExceptionPage();
|
||||||
app.UseBrowserLink();
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,32 +15,13 @@
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
<li ><a [routerLink]="['/search']"><i class="fa fa-search"></i> Search</a></li>
|
<li ><a [routerLink]="['/search']"><i class="fa fa-search"></i> Search</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
<ul class="nav navbar-nav">
|
||||||
|
<li ><a [routerLink]="['/settings/ombi']"><i class="fa fa-search"></i> Settings</a></li>
|
||||||
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<!--<nav class="navbar navbar-toggleable-md navbar-light bg-faded">
|
|
||||||
<button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
|
||||||
<span class="navbar-toggler-icon"></span>
|
|
||||||
</button>
|
|
||||||
<a class="navbar-brand" [routerLink]="['/']">Ombi</a>
|
|
||||||
<div class="collapse navbar-collapse" id="navbarNav">
|
|
||||||
<ul class="navbar-nav">
|
|
||||||
<li class="nav-item active">
|
|
||||||
<a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" href="#">Features</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link" href="#">Pricing</a>
|
|
||||||
</li>
|
|
||||||
<li class="nav-item">
|
|
||||||
<a class="nav-link disabled" href="#">Disabled</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
</nav>-->
|
|
||||||
|
|
||||||
|
|
||||||
<div class="container" style="padding-top: 5%">
|
<div class="container" style="padding-top: 5%">
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import { Component } from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
import { MenuItem } from 'primeng/components/common/api';
|
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ombi',
|
selector: 'ombi',
|
||||||
|
@ -7,17 +6,5 @@ import { MenuItem } from 'primeng/components/common/api';
|
||||||
templateUrl: './app.component.html'
|
templateUrl: './app.component.html'
|
||||||
})
|
})
|
||||||
export class AppComponent {
|
export class AppComponent {
|
||||||
private items: MenuItem[];
|
|
||||||
ngOnInit() {
|
|
||||||
this.items = [
|
|
||||||
{
|
|
||||||
label: 'Ombi',
|
|
||||||
routerLink: ['/']
|
|
||||||
},
|
|
||||||
{
|
|
||||||
label: 'Search',
|
|
||||||
routerLink: ['/search']
|
|
||||||
},
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -15,8 +15,10 @@ import { PageNotFoundComponent } from './errors/not-found.component';
|
||||||
import { SearchService } from './services/search.service';
|
import { SearchService } from './services/search.service';
|
||||||
import { RequestService } from './services/request.service';
|
import { RequestService } from './services/request.service';
|
||||||
|
|
||||||
|
// Modules
|
||||||
|
import { SettingsModule } from './settings/settings.module';
|
||||||
|
|
||||||
import { ButtonModule } from 'primeng/primeng';
|
import { ButtonModule } from 'primeng/primeng';
|
||||||
import { MenubarModule } from 'primeng/components/menubar/menubar';
|
|
||||||
import { GrowlModule } from 'primeng/components/growl/growl';
|
import { GrowlModule } from 'primeng/components/growl/growl';
|
||||||
|
|
||||||
const routes: Routes = [
|
const routes: Routes = [
|
||||||
|
@ -30,10 +32,10 @@ const routes: Routes = [
|
||||||
BrowserModule,
|
BrowserModule,
|
||||||
BrowserAnimationsModule,
|
BrowserAnimationsModule,
|
||||||
HttpModule,
|
HttpModule,
|
||||||
MenubarModule,
|
|
||||||
GrowlModule,
|
GrowlModule,
|
||||||
ButtonModule,
|
ButtonModule,
|
||||||
FormsModule
|
FormsModule,
|
||||||
|
SettingsModule
|
||||||
],
|
],
|
||||||
declarations: [
|
declarations: [
|
||||||
AppComponent,
|
AppComponent,
|
||||||
|
|
1
Ombi/Ombi/app/settings/ombi/ombi.component.html
Normal file
1
Ombi/Ombi/app/settings/ombi/ombi.component.html
Normal file
|
@ -0,0 +1 @@
|
||||||
|
|
11
Ombi/Ombi/app/settings/ombi/ombi.component.ts
Normal file
11
Ombi/Ombi/app/settings/ombi/ombi.component.ts
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
import { Component } from '@angular/core';
|
||||||
|
@Component({
|
||||||
|
selector: 'ombi',
|
||||||
|
moduleId: module.id,
|
||||||
|
templateUrl: './ombi.component.html',
|
||||||
|
})
|
||||||
|
export class OmbiComponent {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
29
Ombi/Ombi/app/settings/settings.module.ts
Normal file
29
Ombi/Ombi/app/settings/settings.module.ts
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
import { NgModule, } from '@angular/core';
|
||||||
|
import { CommonModule } from '@angular/common';
|
||||||
|
import { FormsModule } from '@angular/forms';
|
||||||
|
import { RouterModule, Routes } from '@angular/router';
|
||||||
|
|
||||||
|
import { OmbiComponent } from './ombi/ombi.component'
|
||||||
|
|
||||||
|
|
||||||
|
const routes: Routes = [
|
||||||
|
{ path: 'Settings/Ombi', component: OmbiComponent }
|
||||||
|
];
|
||||||
|
|
||||||
|
@NgModule({
|
||||||
|
imports: [
|
||||||
|
CommonModule,
|
||||||
|
FormsModule,
|
||||||
|
RouterModule.forChild(routes),
|
||||||
|
|
||||||
|
],
|
||||||
|
declarations: [
|
||||||
|
OmbiComponent
|
||||||
|
],
|
||||||
|
exports: [
|
||||||
|
RouterModule
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
]
|
||||||
|
})
|
||||||
|
export class SettingsModule { }
|
Loading…
Add table
Add a link
Reference in a new issue