Update database settings retrieval.

This commit is contained in:
Roger Far 2021-07-20 22:53:55 -06:00
parent 697cd58023
commit e4c001b0ce
17 changed files with 180 additions and 161 deletions

View file

@ -9,12 +9,10 @@ namespace RdtClient.Data.Data
public class DownloadData
{
private readonly DataContext _dataContext;
private readonly TorrentData _torrentData;
public DownloadData(DataContext dataContext, TorrentData torrentData)
public DownloadData(DataContext dataContext)
{
_dataContext = dataContext;
_torrentData = torrentData;
}
public async Task<Download> GetById(Guid downloadId)
@ -48,7 +46,7 @@ namespace RdtClient.Data.Data
await _dataContext.SaveChangesAsync();
await _torrentData.VoidCache();
await TorrentData.VoidCache();
return download;
}
@ -62,7 +60,7 @@ namespace RdtClient.Data.Data
await _dataContext.SaveChangesAsync();
await _torrentData.VoidCache();
await TorrentData.VoidCache();
}
public async Task UpdateDownloadStarted(Guid downloadId, DateTimeOffset? dateTime)
@ -74,7 +72,7 @@ namespace RdtClient.Data.Data
await _dataContext.SaveChangesAsync();
await _torrentData.VoidCache();
await TorrentData.VoidCache();
}
public async Task UpdateDownloadFinished(Guid downloadId, DateTimeOffset? dateTime)
@ -91,7 +89,7 @@ namespace RdtClient.Data.Data
await _dataContext.SaveChangesAsync();
await _torrentData.VoidCache();
await TorrentData.VoidCache();
}
public async Task UpdateUnpackingQueued(Guid downloadId, DateTimeOffset? dateTime)
@ -103,7 +101,7 @@ namespace RdtClient.Data.Data
await _dataContext.SaveChangesAsync();
await _torrentData.VoidCache();
await TorrentData.VoidCache();
}
public async Task UpdateUnpackingStarted(Guid downloadId, DateTimeOffset? dateTime)
@ -115,7 +113,7 @@ namespace RdtClient.Data.Data
await _dataContext.SaveChangesAsync();
await _torrentData.VoidCache();
await TorrentData.VoidCache();
}
public async Task UpdateUnpackingFinished(Guid downloadId, DateTimeOffset? dateTime)
@ -127,7 +125,7 @@ namespace RdtClient.Data.Data
await _dataContext.SaveChangesAsync();
await _torrentData.VoidCache();
await TorrentData.VoidCache();
}
public async Task UpdateCompleted(Guid downloadId, DateTimeOffset? dateTime)
@ -139,7 +137,7 @@ namespace RdtClient.Data.Data
await _dataContext.SaveChangesAsync();
await _torrentData.VoidCache();
await TorrentData.VoidCache();
}
public async Task UpdateError(Guid downloadId, String error)
@ -151,7 +149,7 @@ namespace RdtClient.Data.Data
await _dataContext.SaveChangesAsync();
await _torrentData.VoidCache();
await TorrentData.VoidCache();
}
public async Task UpdateRetryCount(Guid downloadId, Int32 retryCount)
@ -163,7 +161,7 @@ namespace RdtClient.Data.Data
await _dataContext.SaveChangesAsync();
await _torrentData.VoidCache();
await TorrentData.VoidCache();
}
public async Task DeleteForTorrent(Guid torrentId)
@ -176,7 +174,7 @@ namespace RdtClient.Data.Data
await _dataContext.SaveChangesAsync();
await _torrentData.VoidCache();
await TorrentData.VoidCache();
}
public async Task Reset(Guid downloadId)
@ -198,7 +196,7 @@ namespace RdtClient.Data.Data
await _dataContext.SaveChangesAsync();
await _torrentData.VoidCache();
await TorrentData.VoidCache();
}
}
}

View file

@ -5,12 +5,12 @@ using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using RdtClient.Data.Models.Data;
using RdtClient.Data.Models.Internal;
namespace RdtClient.Data.Data
{
public class SettingData
{
private static IList<Setting> _settingCache;
private static readonly SemaphoreSlim _settingCacheLock = new(1);
private readonly DataContext _dataContext;
@ -20,20 +20,37 @@ namespace RdtClient.Data.Data
_dataContext = dataContext;
}
public static DbSettings Get { get; private set; }
public async Task ResetCache()
{
var allSettings = await _dataContext.Settings.AsNoTracking().ToListAsync();
String GetString(String name) => allSettings.FirstOrDefault(m => m.SettingId == name)?.Value;
Int32 GetInt32(String name) => Int32.Parse(allSettings.FirstOrDefault(m => m.SettingId == name)?.Value ?? "0");
Get = new DbSettings
{
RealDebridApiKey = GetString("RealDebridApiKey"),
DownloadPath = GetString("DownloadPath"),
DownloadClient = GetString("DownloadClient"),
TempPath = GetString("TempPath"),
MappedPath = GetString("MappedPath"),
DownloadLimit = GetInt32("DownloadLimit"),
UnpackLimit = GetInt32("UnpackLimit"),
MinFileSize = GetInt32("MinFileSize"),
OnlyDownloadAvailableFiles = GetInt32("OnlyDownloadAvailableFiles"),
DownloadChunkCount = GetInt32("DownloadChunkCount"),
DownloadMaxSpeed = GetInt32("DownloadMaxSpeed"),
ProxyServer = GetString("ProxyServer"),
LogLevel = GetString("LogLevel"),
Categories = GetString("Categories")
};
}
public async Task<IList<Setting>> GetAll()
{
await _settingCacheLock.WaitAsync();
try
{
_settingCache ??= await _dataContext.Settings.AsNoTracking().ToListAsync();
return _settingCache;
}
finally
{
_settingCacheLock.Release();
}
return await _dataContext.Settings.AsNoTracking().ToListAsync();
}
public async Task Update(IList<Setting> settings)
@ -56,7 +73,7 @@ namespace RdtClient.Data.Data
await _dataContext.SaveChangesAsync();
_settingCache = null;
await ResetCache();
}
finally
{
@ -81,7 +98,7 @@ namespace RdtClient.Data.Data
await _dataContext.SaveChangesAsync();
_settingCache = null;
await ResetCache();
}
finally
{

View file

@ -202,7 +202,7 @@ namespace RdtClient.Data.Data
await VoidCache();
}
public async Task VoidCache()
public static async Task VoidCache()
{
await _torrentCacheLock.WaitAsync();

View file

@ -0,0 +1,22 @@
using System;
namespace RdtClient.Data.Models.Internal
{
public class DbSettings
{
public String RealDebridApiKey { get; set; }
public String DownloadPath { get; set; }
public String DownloadClient { get; set; }
public String TempPath { get; set; }
public String MappedPath { get; set; }
public Int32 DownloadLimit { get; set; }
public Int32 UnpackLimit { get; set; }
public Int32 MinFileSize { get; set; }
public Int32 OnlyDownloadAvailableFiles { get; set; }
public Int32 DownloadChunkCount { get; set; }
public Int32 DownloadMaxSpeed { get; set; }
public String ProxyServer { get; set; }
public String LogLevel { get; set; }
public String Categories { get; set; }
}
}

View file

@ -14,6 +14,8 @@ namespace RdtClient.Service
services.AddScoped<Settings>();
services.AddScoped<Torrents>();
services.AddScoped<TorrentRunner>();
services.AddHostedService<Startup>();
}
}
}

View file

@ -14,6 +14,7 @@
<PackageReference Include="Serilog.Exceptions" Version="7.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
<PackageReference Include="SharpCompress" Version="0.28.3" />
<PackageReference Include="StreamJsonRpc" Version="2.8.21" />
</ItemGroup>
<ItemGroup>

View file

@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Threading.Tasks;
using Downloader;
using RdtClient.Data.Models.Data;
using RdtClient.Data.Models.Internal;
using RdtClient.Service.Helpers;
namespace RdtClient.Service.Services
@ -34,7 +34,7 @@ namespace RdtClient.Service.Services
public Int64 BytesTotal { get; private set; }
public Int64 BytesDone { get; private set; }
public async Task Start(IList<Setting> settings)
public async Task Start(DbSettings settings)
{
BytesDone = 0;
BytesTotal = 0;
@ -56,11 +56,9 @@ namespace RdtClient.Service.Services
var uri = new Uri(_download.Link);
await Task.Factory.StartNew(async delegate
await Task.Run(async delegate
{
var downloadClientSetting = settings.GetString("DownloadClient");
switch (downloadClientSetting)
switch (settings.DownloadClient)
{
case "Simple":
await DownloadSimple(uri, filePath);
@ -69,7 +67,7 @@ namespace RdtClient.Service.Services
await DownloadMultiPart(filePath, settings);
break;
default:
throw new Exception($"Unknown download client {downloadClientSetting}");
throw new Exception($"Unknown download client {settings.DownloadClient}");
}
});
}
@ -126,30 +124,30 @@ namespace RdtClient.Service.Services
}
}
private async Task DownloadMultiPart(String filePath, IList<Setting> settings)
private async Task DownloadMultiPart(String filePath, DbSettings settings)
{
try
{
var settingTempPath = settings.GetString("TempPath");
var settingTempPath = settings.TempPath;
if (String.IsNullOrWhiteSpace(settingTempPath))
{
settingTempPath = Path.GetTempPath();
}
var settingDownloadChunkCount = settings.GetNumber("DownloadChunkCount");
var settingDownloadChunkCount = settings.DownloadChunkCount;
if (settingDownloadChunkCount <= 0)
{
settingDownloadChunkCount = 1;
}
var settingDownloadMaxSpeed = settings.GetNumber("DownloadMaxSpeed");
var settingDownloadMaxSpeed = settings.DownloadMaxSpeed;
if (settingDownloadMaxSpeed <= 0)
{
settingDownloadMaxSpeed = 0;
}
settingDownloadMaxSpeed = settingDownloadMaxSpeed * 1024 * 1024;
var settingProxyServer = settings.GetString("ProxyServer");
var settingProxyServer = settings.ProxyServer;
var downloadOpt = new DownloadConfiguration
{

View file

@ -180,7 +180,7 @@ namespace RdtClient.Service.Services
WebUiUsername = ""
};
var savePath = await AppDefaultSavePath();
var savePath = AppDefaultSavePath();
preferences.SavePath = savePath;
preferences.TempPath = $"{savePath}temp{Path.DirectorySeparatorChar}";
@ -195,9 +195,9 @@ namespace RdtClient.Service.Services
return preferences;
}
public async Task<String> AppDefaultSavePath()
public String AppDefaultSavePath()
{
var downloadPath = await _settings.GetString("MappedPath");
var downloadPath = Settings.Get.MappedPath;
downloadPath = downloadPath.TrimEnd('\\')
.TrimEnd('/');
@ -208,7 +208,7 @@ namespace RdtClient.Service.Services
public async Task<IList<TorrentInfo>> TorrentInfo()
{
var savePath = await AppDefaultSavePath();
var savePath = AppDefaultSavePath();
var results = new List<TorrentInfo>();
@ -337,7 +337,7 @@ namespace RdtClient.Service.Services
public async Task<TorrentProperties> TorrentProperties(String hash)
{
var savePath = await AppDefaultSavePath();
var savePath = AppDefaultSavePath();
var torrent = await _torrents.GetByHash(hash);
@ -388,11 +388,11 @@ namespace RdtClient.Service.Services
SeedsTotal = 100,
ShareRatio = 9999,
TimeElapsed = (Int64) (DateTimeOffset.UtcNow - torrent.Added).TotalSeconds,
TotalDownloaded = bytesTotal,
TotalDownloadedSession = bytesTotal,
TotalDownloaded = bytesDone,
TotalDownloadedSession = bytesDone,
TotalSize = bytesTotal,
TotalUploaded = bytesTotal,
TotalUploadedSession = bytesTotal,
TotalUploaded = bytesDone,
TotalUploadedSession = bytesDone,
TotalWasted = 0,
UpLimit = -1,
UpSpeed = speed,
@ -416,22 +416,16 @@ namespace RdtClient.Service.Services
public async Task TorrentsAddMagnet(String magnetLink, String category)
{
var onlyDownloadAvailableFilesSetting = await _settings.GetNumber("OnlyDownloadAvailableFiles");
var minFileSizeSetting = await _settings.GetNumber("MinFileSize");
var downloadAction = Settings.Get.OnlyDownloadAvailableFiles == 1 ? TorrentDownloadAction.DownloadAvailableFiles : TorrentDownloadAction.DownloadAll;
var downloadAction = onlyDownloadAvailableFilesSetting == 1 ? TorrentDownloadAction.DownloadAvailableFiles : TorrentDownloadAction.DownloadAll;
await _torrents.UploadMagnet(magnetLink, category, downloadAction, TorrentFinishedAction.None, minFileSizeSetting, null);
await _torrents.UploadMagnet(magnetLink, category, downloadAction, TorrentFinishedAction.None, Settings.Get.MinFileSize, null);
}
public async Task TorrentsAddFile(Byte[] fileBytes, String category)
{
var onlyDownloadAvailableFilesSetting = await _settings.GetNumber("OnlyDownloadAvailableFiles");
var minFileSizeSetting = await _settings.GetNumber("MinFileSize");
var downloadAction = Settings.Get.OnlyDownloadAvailableFiles == 1 ? TorrentDownloadAction.DownloadAvailableFiles : TorrentDownloadAction.DownloadAll;
var downloadAction = onlyDownloadAvailableFilesSetting == 1 ? TorrentDownloadAction.DownloadAvailableFiles : TorrentDownloadAction.DownloadAll;
await _torrents.UploadFile(fileBytes, category, downloadAction, TorrentFinishedAction.None, minFileSizeSetting, null);
await _torrents.UploadFile(fileBytes, category, downloadAction, TorrentFinishedAction.None, Settings.Get.MinFileSize, null);
}
public async Task TorrentsSetCategory(String hash, String category)
@ -448,9 +442,7 @@ namespace RdtClient.Service.Services
.Distinct()
.ToList();
var categorySetting = await _settings.GetString("Categories");
var categories = categorySetting.Split(",", StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
var categories = Settings.Get.Categories.Split(",", StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
torrentsToGroup.AddRange(categories);
@ -471,7 +463,7 @@ namespace RdtClient.Service.Services
public async Task CategoryCreate(String category)
{
var categoriesSetting = await _settings.GetString("Categories");
var categoriesSetting = Settings.Get.Categories;
if (String.IsNullOrWhiteSpace(categoriesSetting))
{
@ -494,7 +486,7 @@ namespace RdtClient.Service.Services
public async Task CategoryRemove(String category)
{
var categoriesSetting = await _settings.GetString("Categories");
var categoriesSetting = Settings.Get.Categories;
if (String.IsNullOrWhiteSpace(categoriesSetting))
{

View file

@ -2,11 +2,11 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using RdtClient.Data.Data;
using RdtClient.Data.Models.Data;
using RdtClient.Data.Models.Internal;
namespace RdtClient.Service.Services
{
@ -19,6 +19,8 @@ namespace RdtClient.Service.Services
_settingData = settingData;
}
public static DbSettings Get => SettingData.Get;
public async Task<IList<Setting>> GetAll()
{
return await _settingData.GetAll();
@ -34,32 +36,6 @@ namespace RdtClient.Service.Services
await _settingData.UpdateString(key, value);
}
public async Task<String> GetString(String key)
{
var settings = await GetAll();
var setting = settings.FirstOrDefault(m => m.SettingId == key);
if (setting == null)
{
throw new Exception($"Setting with key {key} not found");
}
return setting.Value;
}
public async Task<Int32> GetNumber(String key)
{
var settings = await GetAll();
var setting = settings.FirstOrDefault(m => m.SettingId == key);
if (setting == null)
{
throw new Exception($"Setting with key {key} not found");
}
return Int32.Parse(setting.Value);
}
public async Task TestPath(String path)
{
if (String.IsNullOrWhiteSpace(path))
@ -82,9 +58,7 @@ namespace RdtClient.Service.Services
public async Task<Double> TestDownloadSpeed(CancellationToken cancellationToken)
{
var downloadPath = await GetString("DownloadPath");
var settings = await GetAll();
var downloadPath = Get.DownloadPath;
var testFilePath = Path.Combine(downloadPath, "testDefault.rar");
@ -104,7 +78,7 @@ namespace RdtClient.Service.Services
var downloadClient = new DownloadClient(download, download.Torrent, downloadPath);
await downloadClient.Start(settings);
await downloadClient.Start(Get);
while (!downloadClient.Finished)
{
@ -136,7 +110,7 @@ namespace RdtClient.Service.Services
public async Task<Double> TestWriteSpeed()
{
var downloadPath = await GetString("DownloadPath");
var downloadPath = Get.DownloadPath;
var testFilePath = Path.Combine(downloadPath, "test.tmp");
@ -161,7 +135,7 @@ namespace RdtClient.Service.Services
{
rnd.NextBytes(buffer);
fileStream.Write(buffer, 0, buffer.Length);
await fileStream.WriteAsync(buffer.AsMemory(0, buffer.Length));
}
watch.Stop();
@ -182,7 +156,7 @@ namespace RdtClient.Service.Services
{
try
{
var tempPath = GetString("TempPath").Result;
var tempPath = Get.TempPath;
if (!String.IsNullOrWhiteSpace(tempPath))
{
@ -199,5 +173,10 @@ namespace RdtClient.Service.Services
// ignored
}
}
public async Task ResetCache()
{
await _settingData.ResetCache();
}
}
}

View file

@ -64,7 +64,7 @@ namespace RdtClient.Service.Services
if (read > 0)
{
fileStream.Write(buffer, 0, read);
await fileStream.WriteAsync(buffer.AsMemory(0, read));
BytesDone = fileStream.Length;
BytesTotal = responseLength;

View file

@ -0,0 +1,32 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace RdtClient.Service.Services
{
public class Startup : IHostedService
{
private readonly IServiceProvider _serviceProvider;
public Startup(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
public async Task StartAsync(CancellationToken cancellationToken)
{
using var scope = _serviceProvider.CreateScope();
var settings = scope.ServiceProvider.GetRequiredService<Settings>();
await settings.ResetCache();
settings.Clean();
}
public Task StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
}
}

View file

@ -6,7 +6,6 @@ using System.Linq;
using System.Threading.Tasks;
using System.Web;
using RdtClient.Data.Enums;
using RdtClient.Service.Helpers;
using Serilog;
namespace RdtClient.Service.Services
@ -21,13 +20,11 @@ namespace RdtClient.Service.Services
public static readonly ConcurrentDictionary<Guid, UnpackClient> ActiveUnpackClients = new();
private readonly Downloads _downloads;
private readonly RemoteService _remoteService;
private readonly Settings _settings;
private readonly Torrents _torrents;
public TorrentRunner(Settings settings, Torrents torrents, Downloads downloads, RemoteService remoteService)
public TorrentRunner(Torrents torrents, Downloads downloads, RemoteService remoteService)
{
_settings = settings;
_torrents = torrents;
_downloads = downloads;
_remoteService = remoteService;
@ -65,29 +62,26 @@ namespace RdtClient.Service.Services
sw.Start();
Log.Debug("TorrentRunner Tick Start");
var settings = await _settings.GetAll();
var settingApiKey = settings.GetString("RealDebridApiKey");
if (String.IsNullOrWhiteSpace(settingApiKey))
if (String.IsNullOrWhiteSpace(Settings.Get.RealDebridApiKey))
{
Log.Debug($"No RealDebridApiKey set!");
return;
}
var settingDownloadLimit = settings.GetNumber("DownloadLimit");
var settingDownloadLimit = Settings.Get.DownloadLimit;
if (settingDownloadLimit < 1)
{
settingDownloadLimit = 1;
}
var settingUnpackLimit = settings.GetNumber("UnpackLimit");
var settingUnpackLimit = Settings.Get.UnpackLimit;
if (settingUnpackLimit < 1)
{
settingUnpackLimit = 1;
}
var settingDownloadPath = settings.GetString("DownloadPath");
var settingDownloadPath = Settings.Get.DownloadPath;
if (String.IsNullOrWhiteSpace(settingDownloadPath))
{
return;
@ -253,7 +247,7 @@ namespace RdtClient.Service.Services
{
Log.Debug($"Added download {download.DownloadId} to active downloads");
await downloadClient.Start(settings);
await downloadClient.Start(Settings.Get);
Log.Debug($"Download {download.DownloadId} started");
}

View file

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using MonoTorrent;
@ -21,19 +22,32 @@ namespace RdtClient.Service.Services
private static readonly SemaphoreSlim RealDebridUpdateLock = new(1, 1);
private static RdNetClient _rdtNetClient;
private readonly Downloads _downloads;
private readonly Settings _settings;
private readonly IHttpClientFactory _httpClientFactory;
private readonly TorrentData _torrentData;
public Torrents(TorrentData torrentData, Settings settings, Downloads downloads)
public Torrents(IHttpClientFactory httpClientFactory, TorrentData torrentData, Downloads downloads)
{
_httpClientFactory = httpClientFactory;
_torrentData = torrentData;
_settings = settings;
_downloads = downloads;
}
private RdNetClient GetRdNetClient()
{
var apiKey = Settings.Get.RealDebridApiKey;
if (String.IsNullOrWhiteSpace(apiKey))
{
throw new Exception("Real-Debrid API Key not set in the settings");
}
var rdtNetClient = new RdNetClient(null, _httpClientFactory.CreateClient());
rdtNetClient.UseApiAuthentication(apiKey);
return rdtNetClient;
}
public async Task<IList<Torrent>> Get()
{
var torrents = await _torrentData.Get();
@ -207,7 +221,7 @@ namespace RdtClient.Service.Services
if (deleteLocalFiles)
{
var downloadPath = await DownloadPath(torrent);
var downloadPath = DownloadPath(torrent);
downloadPath = Path.Combine(downloadPath, torrent.RdName);
if (Directory.Exists(downloadPath))
@ -244,7 +258,7 @@ namespace RdtClient.Service.Services
var torrent = await GetById(torrentId);
var download = await _downloads.GetById(downloadId);
var downloadPath = await DownloadPath(torrent);
var downloadPath = DownloadPath(torrent);
var filePath = DownloadHelper.GetDownloadPath(downloadPath, torrent, download);
@ -311,11 +325,6 @@ namespace RdtClient.Service.Services
await _downloads.UpdateError(downloadId, null);
}
public void Reset()
{
_rdtNetClient = null;
}
public async Task<Profile> GetProfile()
{
var user = await GetRdNetClient().User.GetAsync();
@ -472,25 +481,6 @@ namespace RdtClient.Service.Services
await _torrentData.UpdateFilesSelected(torrentId, datetime);
}
private RdNetClient GetRdNetClient()
{
if (_rdtNetClient == null)
{
var apiKey = _settings.GetString("RealDebridApiKey")
.Result;
if (String.IsNullOrWhiteSpace(apiKey))
{
throw new Exception("Real-Debrid API Key not set in the settings");
}
_rdtNetClient = new RdNetClient();
_rdtNetClient.UseApiAuthentication(apiKey);
}
return _rdtNetClient;
}
public async Task<Torrent> GetById(Guid torrentId)
{
var torrent = await _torrentData.GetById(torrentId);
@ -558,9 +548,9 @@ namespace RdtClient.Service.Services
}
}
private async Task<String> DownloadPath(Torrent torrent)
private String DownloadPath(Torrent torrent)
{
var settingDownloadPath = await _settings.GetString("DownloadPath");
var settingDownloadPath = Settings.Get.DownloadPath;
if (!String.IsNullOrWhiteSpace(torrent.Category))
{

View file

@ -50,7 +50,7 @@ namespace RdtClient.Service.Services
throw new Exception("Invalid download path");
}
await Task.Factory.StartNew(async delegate
await Task.Run(async delegate
{
if (!_cancelled)
{

View file

@ -125,9 +125,9 @@ namespace RdtClient.Web.Controllers
[Route("app/defaultSavePath")]
[HttpGet]
[HttpPost]
public async Task<ActionResult<AppPreferences>> AppDefaultSavePath()
public ActionResult<AppPreferences> AppDefaultSavePath()
{
var result = await _qBittorrent.AppDefaultSavePath();
var result = _qBittorrent.AppDefaultSavePath();
return Ok(result);
}

View file

@ -37,12 +37,8 @@ namespace RdtClient.Web.Controllers
public async Task<ActionResult> Update([FromBody] SettingsControllerUpdateRequest request)
{
await _settings.Update(request.Settings);
_torrents.Reset();
var logLevelSetting = await _settings.GetString("LogLevel");
if (!Enum.TryParse<LogEventLevel>(logLevelSetting, out var logLevel))
if (!Enum.TryParse<LogEventLevel>(Settings.Get.LogLevel, out var logLevel))
{
logLevel = LogEventLevel.Information;
}

View file

@ -91,7 +91,7 @@ namespace RdtClient.Web
Service.DiConfig.Config(services);
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger<Startup> logger, Settings settings)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger<Startup> logger)
{
if (env.IsDevelopment())
{
@ -133,8 +133,6 @@ namespace RdtClient.Web
spa.Options.DefaultPage = "/index.html";
});
});
settings.Clean();
}
}
}