mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-15 01:32:55 -07:00
#1513 Added storage path
This commit is contained in:
parent
e735df5d0a
commit
d9ab803a11
5 changed files with 48 additions and 13 deletions
|
@ -1,9 +1,11 @@
|
|||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Security.Principal;
|
||||
using Hangfire;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
|
@ -99,8 +101,7 @@ namespace Ombi.DependencyInjection
|
|||
services.AddTransient<ICouchPotatoApi, CouchPotatoApi>();
|
||||
}
|
||||
|
||||
public static void RegisterStore(this IServiceCollection services)
|
||||
{
|
||||
public static void RegisterStore(this IServiceCollection services) {
|
||||
services.AddEntityFrameworkSqlite().AddDbContext<OmbiContext>();
|
||||
|
||||
services.AddScoped<IOmbiContext, OmbiContext>(); // https://docs.microsoft.com/en-us/aspnet/core/data/entity-framework-6
|
||||
|
|
13
src/Ombi.Helpers/StoragePathSingleton.cs
Normal file
13
src/Ombi.Helpers/StoragePathSingleton.cs
Normal file
|
@ -0,0 +1,13 @@
|
|||
namespace Ombi.Helpers
|
||||
{
|
||||
public class StoragePathSingleton
|
||||
{
|
||||
private static StoragePathSingleton instance;
|
||||
|
||||
private StoragePathSingleton() { }
|
||||
|
||||
public static StoragePathSingleton Instance => instance ?? (instance = new StoragePathSingleton());
|
||||
|
||||
public string StoragePath { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
@ -18,8 +19,6 @@ namespace Ombi.Store.Context
|
|||
_created = true;
|
||||
Database.Migrate();
|
||||
|
||||
// Add the notifcation templates
|
||||
|
||||
}
|
||||
|
||||
public DbSet<NotificationTemplates> NotificationTemplates { get; set; }
|
||||
|
@ -44,7 +43,8 @@ namespace Ombi.Store.Context
|
|||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
optionsBuilder.UseSqlite("Data Source=Ombi.db");
|
||||
var i = StoragePathSingleton.Instance;
|
||||
optionsBuilder.UseSqlite($"Data Source={Path.Combine(i.StoragePath,"Ombi.db")}");
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
|
|
|
@ -9,6 +9,8 @@ using Ombi.Store.Entities;
|
|||
using CommandLine;
|
||||
using CommandLine.Text;
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Ombi.Helpers;
|
||||
|
||||
namespace Ombi
|
||||
{
|
||||
|
@ -33,6 +35,8 @@ namespace Ombi
|
|||
UrlArgs = host;
|
||||
|
||||
var urlValue = string.Empty;
|
||||
var instance = StoragePathSingleton.Instance;
|
||||
instance.StoragePath = storagePath ?? string.Empty;
|
||||
using (var ctx = new OmbiContext())
|
||||
{
|
||||
var config = ctx.ApplicationConfigurations.ToList();
|
||||
|
|
|
@ -16,6 +16,7 @@ using Microsoft.AspNetCore.HttpOverrides;
|
|||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.SpaServices.Webpack;
|
||||
using Microsoft.AspNetCore.StaticFiles;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
@ -36,6 +37,7 @@ namespace Ombi
|
|||
{
|
||||
public class Startup
|
||||
{
|
||||
public static StoragePathSingleton StoragePath => StoragePathSingleton.Instance;
|
||||
public Startup(IHostingEnvironment env)
|
||||
{
|
||||
Console.WriteLine(env.ContentRootPath);
|
||||
|
@ -48,11 +50,24 @@ namespace Ombi
|
|||
|
||||
//if (env.IsDevelopment())
|
||||
//{
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.MinimumLevel.Debug()
|
||||
.WriteTo.RollingFile(Path.Combine(env.ContentRootPath, "Logs", "log-{Date}.txt"))
|
||||
.WriteTo.SQLite("Ombi.db", "Logs", LogEventLevel.Debug)
|
||||
.CreateLogger();
|
||||
Serilog.ILogger config;
|
||||
if (string.IsNullOrEmpty(StoragePath.StoragePath))
|
||||
{
|
||||
config = new LoggerConfiguration()
|
||||
.MinimumLevel.Debug()
|
||||
.WriteTo.SQLite("Ombi.db", "Logs", LogEventLevel.Debug)
|
||||
.CreateLogger();
|
||||
}
|
||||
else
|
||||
{
|
||||
config = new LoggerConfiguration()
|
||||
.MinimumLevel.Debug()
|
||||
.WriteTo.SQLite(Path.Combine(StoragePath.StoragePath, "Ombi.db"), "Logs", LogEventLevel.Debug)
|
||||
.CreateLogger();
|
||||
}
|
||||
Log.Logger = config;
|
||||
|
||||
|
||||
//}
|
||||
//if (env.IsProduction())
|
||||
//{
|
||||
|
@ -69,6 +84,7 @@ namespace Ombi
|
|||
// This method gets called by the runtime. Use this method to add services to the container.
|
||||
public IServiceProvider ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
|
||||
// Add framework services.
|
||||
services.AddDbContext<OmbiContext>();
|
||||
|
||||
|
@ -113,6 +129,7 @@ namespace Ombi
|
|||
x.UseConsole();
|
||||
});
|
||||
|
||||
|
||||
// Build the intermediate service provider
|
||||
return services.BuildServiceProvider();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue