fix: Fix type mismatch errors and nullable warnings

- Updated type conversions for MinimumSeedRatio from float to int
- Fixed UserPreferencesConfig references to use UserPreferences class
- Added null checks for Path operations in PostProcessor
- Changed arrays to Lists for MediaExtensions and NotificationEvents
- Added null checks in MetricsService for DriveInfo paths
- Added default values for nullable string properties
- Fixed missing using statements

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
MasterDraco 2025-03-12 22:38:56 +00:00
parent f21639455d
commit 2e2e38d979
5 changed files with 29 additions and 16 deletions

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
@ -7,6 +8,7 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using TransmissionRssManager.Core;
using TransmissionRssManager.Services;
namespace TransmissionRssManager.Api.Controllers
{
@ -178,20 +180,20 @@ namespace TransmissionRssManager.Api.Controllers
Enabled = false,
ExtractArchives = true,
OrganizeMedia = true,
MinimumSeedRatio = 1.0f,
MediaExtensions = new[] { ".mp4", ".mkv", ".avi", ".mov", ".wmv", ".m4v", ".mpg", ".mpeg", ".flv", ".webm" },
MinimumSeedRatio = 1,
MediaExtensions = new List<string> { ".mp4", ".mkv", ".avi", ".mov", ".wmv", ".m4v", ".mpg", ".mpeg", ".flv", ".webm" },
AutoOrganizeByMediaType = true,
RenameFiles = false,
CompressCompletedFiles = false,
DeleteCompletedAfterDays = 0
},
UserPreferences = new UserPreferencesConfig
UserPreferences = new UserPreferences
{
EnableDarkMode = true,
AutoRefreshUIEnabled = true,
AutoRefreshIntervalSeconds = 30,
NotificationsEnabled = true,
NotificationEvents = new[] { "torrent-added", "torrent-completed", "torrent-error" },
NotificationEvents = new List<string> { "torrent-added", "torrent-completed", "torrent-error" },
DefaultView = "dashboard",
ConfirmBeforeDelete = true,
MaxItemsPerPage = 25,

View File

@ -83,7 +83,7 @@ namespace TransmissionRssManager.Api.Controllers
public class AddTorrentRequest
{
public string Url { get; set; }
public string DownloadDir { get; set; }
public string Url { get; set; } = string.Empty;
public string DownloadDir { get; set; } = string.Empty;
}
}

View File

@ -17,7 +17,7 @@ namespace TransmissionRssManager.Services
{
private readonly ILogger<ConfigService> _logger;
private readonly string _configFilePath;
private AppConfig _cachedConfig;
private AppConfig? _cachedConfig;
private readonly object _lockObject = new object();
public ConfigService(ILogger<ConfigService> logger)
@ -407,9 +407,9 @@ namespace TransmissionRssManager.Services
Enabled = false,
ExtractArchives = true,
OrganizeMedia = true,
MinimumSeedRatio = 1.0f
MinimumSeedRatio = 1
},
UserPreferences = new UserPreferencesConfig
UserPreferences = new UserPreferences
{
EnableDarkMode = true,
AutoRefreshUIEnabled = true,
@ -436,10 +436,10 @@ namespace TransmissionRssManager.Services
Enabled = false,
ExtractArchives = true,
OrganizeMedia = true,
MinimumSeedRatio = 1.0f
MinimumSeedRatio = 1
};
config.UserPreferences ??= new UserPreferencesConfig
config.UserPreferences ??= new UserPreferences
{
EnableDarkMode = true,
AutoRefreshUIEnabled = true,

View File

@ -95,9 +95,13 @@ namespace TransmissionRssManager.Services
{
try
{
var driveInfo = new System.IO.DriveInfo(System.IO.Path.GetPathRoot(downloadDir));
var root = System.IO.Path.GetPathRoot(downloadDir);
if (!string.IsNullOrEmpty(root))
{
var driveInfo = new System.IO.DriveInfo(root);
availableSpace = driveInfo.AvailableFreeSpace;
}
}
catch (Exception ex)
{
_logger.LogWarning(ex, $"Error getting available disk space for {downloadDir}");

View File

@ -119,9 +119,16 @@ namespace TransmissionRssManager.Services
{
_logger.LogInformation($"Extracting archive: {archiveFile}");
var extractDir = Path.Combine(
Path.GetDirectoryName(archiveFile),
Path.GetFileNameWithoutExtension(archiveFile));
var dirName = Path.GetDirectoryName(archiveFile);
var fileName = Path.GetFileNameWithoutExtension(archiveFile);
if (dirName == null)
{
_logger.LogWarning($"Could not get directory name for archive: {archiveFile}");
continue;
}
var extractDir = Path.Combine(dirName, fileName);
if (!Directory.Exists(extractDir))
{