Add category support by saving the categories in the settings table now.
This commit is contained in:
parent
3a2d33435e
commit
0e1e547c71
5 changed files with 118 additions and 30 deletions
|
|
@ -129,6 +129,12 @@ namespace RdtClient.Data.Data
|
||||||
SettingId = "LogLevel",
|
SettingId = "LogLevel",
|
||||||
Type = "String",
|
Type = "String",
|
||||||
Value = "Warning"
|
Value = "Warning"
|
||||||
|
},
|
||||||
|
new Setting
|
||||||
|
{
|
||||||
|
SettingId = "Categories",
|
||||||
|
Type = "String",
|
||||||
|
Value = ""
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
@ -11,6 +12,7 @@ namespace RdtClient.Data.Data
|
||||||
{
|
{
|
||||||
Task<IList<Setting>> GetAll();
|
Task<IList<Setting>> GetAll();
|
||||||
Task Update(IList<Setting> settings);
|
Task Update(IList<Setting> settings);
|
||||||
|
Task UpdateString(String key, String value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class SettingData : ISettingData
|
public class SettingData : ISettingData
|
||||||
|
|
@ -68,5 +70,30 @@ namespace RdtClient.Data.Data
|
||||||
_settingCacheLock.Release();
|
_settingCacheLock.Release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task UpdateString(String key, String value)
|
||||||
|
{
|
||||||
|
await _settingCacheLock.WaitAsync();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var dbSetting = await _dataContext.Settings.FirstOrDefaultAsync(m => m.SettingId == key);
|
||||||
|
|
||||||
|
if (dbSetting == null)
|
||||||
|
{
|
||||||
|
throw new Exception($"Cannot find setting with key {key}");
|
||||||
|
}
|
||||||
|
|
||||||
|
dbSetting.Value = value;
|
||||||
|
|
||||||
|
await _dataContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
_settingCache = null;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_settingCacheLock.Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@ namespace RdtClient.Service.Services
|
||||||
Task TorrentsAddFile(Byte[] fileBytes, String category, Boolean autoDelete);
|
Task TorrentsAddFile(Byte[] fileBytes, String category, Boolean autoDelete);
|
||||||
Task TorrentsSetCategory(String hash, String category);
|
Task TorrentsSetCategory(String hash, String category);
|
||||||
Task<IDictionary<String, TorrentCategory>> TorrentsCategories();
|
Task<IDictionary<String, TorrentCategory>> TorrentsCategories();
|
||||||
|
Task CategoryCreate(String category);
|
||||||
|
Task CategoryRemove(String category);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class QBittorrent : IQBittorrent
|
public class QBittorrent : IQBittorrent
|
||||||
|
|
@ -454,6 +456,12 @@ namespace RdtClient.Service.Services
|
||||||
.Distinct()
|
.Distinct()
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
|
var categorySetting = await _settings.GetString("Categories");
|
||||||
|
|
||||||
|
var categories = categorySetting.Split(",", StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||||
|
|
||||||
|
torrentsToGroup.AddRange(categories);
|
||||||
|
|
||||||
var results = new Dictionary<String, TorrentCategory>();
|
var results = new Dictionary<String, TorrentCategory>();
|
||||||
|
|
||||||
if (torrentsToGroup.Count > 0)
|
if (torrentsToGroup.Count > 0)
|
||||||
|
|
@ -468,5 +476,46 @@ namespace RdtClient.Service.Services
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task CategoryCreate(String category)
|
||||||
|
{
|
||||||
|
var categoriesSetting = await _settings.GetString("Categories");
|
||||||
|
|
||||||
|
if (String.IsNullOrWhiteSpace(categoriesSetting))
|
||||||
|
{
|
||||||
|
categoriesSetting = category;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var categoryList = categoriesSetting.Split(",", StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||||
|
|
||||||
|
if (!categoryList.Contains(category))
|
||||||
|
{
|
||||||
|
categoryList.Add(category);
|
||||||
|
}
|
||||||
|
|
||||||
|
categoriesSetting = String.Join(",", categoryList);
|
||||||
|
}
|
||||||
|
|
||||||
|
await _settings.UpdateString("Categories", categoriesSetting);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task CategoryRemove(String category)
|
||||||
|
{
|
||||||
|
var categoriesSetting = await _settings.GetString("Categories");
|
||||||
|
|
||||||
|
if (String.IsNullOrWhiteSpace(categoriesSetting))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var categoryList = categoriesSetting.Split(",", StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||||
|
|
||||||
|
categoryList = categoryList.Where(m => m != category).ToList();
|
||||||
|
|
||||||
|
categoriesSetting = String.Join(",", categoryList);
|
||||||
|
|
||||||
|
await _settings.UpdateString("Categories", categoriesSetting);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -14,6 +14,7 @@ namespace RdtClient.Service.Services
|
||||||
{
|
{
|
||||||
Task<IList<Setting>> GetAll();
|
Task<IList<Setting>> GetAll();
|
||||||
Task Update(IList<Setting> settings);
|
Task Update(IList<Setting> settings);
|
||||||
|
Task UpdateString(String key, String value);
|
||||||
Task<String> GetString(String key);
|
Task<String> GetString(String key);
|
||||||
Task<Int32> GetNumber(String key);
|
Task<Int32> GetNumber(String key);
|
||||||
Task TestPath(String path);
|
Task TestPath(String path);
|
||||||
|
|
@ -41,6 +42,11 @@ namespace RdtClient.Service.Services
|
||||||
await _settingData.Update(settings);
|
await _settingData.Update(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task UpdateString(String key, String value)
|
||||||
|
{
|
||||||
|
await _settingData.UpdateString(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<String> GetString(String key)
|
public async Task<String> GetString(String key)
|
||||||
{
|
{
|
||||||
var settings = await GetAll();
|
var settings = await GetAll();
|
||||||
|
|
|
||||||
|
|
@ -322,24 +322,6 @@ namespace RdtClient.Web.Controllers
|
||||||
{
|
{
|
||||||
var categories = await _qBittorrent.TorrentsCategories();
|
var categories = await _qBittorrent.TorrentsCategories();
|
||||||
|
|
||||||
if (!categories.ContainsKey("radarr"))
|
|
||||||
{
|
|
||||||
categories.Add("radarr", new TorrentCategory
|
|
||||||
{
|
|
||||||
Name = "radarr",
|
|
||||||
SavePath = ""
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!categories.ContainsKey("sonarr"))
|
|
||||||
{
|
|
||||||
categories.Add("sonarr", new TorrentCategory
|
|
||||||
{
|
|
||||||
Name = "sonarr",
|
|
||||||
SavePath = ""
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok(categories);
|
return Ok(categories);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -347,26 +329,34 @@ namespace RdtClient.Web.Controllers
|
||||||
[Route("torrents/createCategory")]
|
[Route("torrents/createCategory")]
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult TorrentsCreateCategory()
|
public async Task<ActionResult> TorrentsCreateCategory([FromForm] QBTorrentsCreateCategoryRequest request)
|
||||||
{
|
{
|
||||||
return Ok();
|
if (String.IsNullOrWhiteSpace(request.Category))
|
||||||
}
|
{
|
||||||
|
return BadRequest("category name is empty");
|
||||||
|
}
|
||||||
|
|
||||||
[Authorize]
|
await _qBittorrent.CategoryCreate(request.Category.Trim());
|
||||||
[Route("torrents/editCategory")]
|
|
||||||
[HttpGet]
|
|
||||||
[HttpPost]
|
|
||||||
public ActionResult TorrentsEditCategory()
|
|
||||||
{
|
|
||||||
return Ok();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[Authorize]
|
[Authorize]
|
||||||
[Route("torrents/removeCategories")]
|
[Route("torrents/removeCategories")]
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public ActionResult TorrentsRemoveCategories()
|
public async Task<ActionResult> TorrentsRemoveCategories([FromForm] QBTorrentsRemoveCategoryRequest request)
|
||||||
{
|
{
|
||||||
|
if (String.IsNullOrWhiteSpace(request.Categories))
|
||||||
|
{
|
||||||
|
return Ok();
|
||||||
|
}
|
||||||
|
|
||||||
|
var categories = request.Categories.Split('\n', StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
|
foreach (var category in categories)
|
||||||
|
{
|
||||||
|
await _qBittorrent.CategoryRemove(category.Trim());
|
||||||
|
}
|
||||||
|
|
||||||
return Ok();
|
return Ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -408,4 +398,14 @@ namespace RdtClient.Web.Controllers
|
||||||
public String Hashes { get; set; }
|
public String Hashes { get; set; }
|
||||||
public String Category { get; set; }
|
public String Category { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class QBTorrentsCreateCategoryRequest
|
||||||
|
{
|
||||||
|
public String Category { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class QBTorrentsRemoveCategoryRequest
|
||||||
|
{
|
||||||
|
public String Categories { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
Reference in a new issue