From 2e2e38d9799edb195c6552597dbb7451c539bf2c Mon Sep 17 00:00:00 2001 From: MasterDraco Date: Wed, 12 Mar 2025 22:38:56 +0000 Subject: [PATCH] fix: Fix type mismatch errors and nullable warnings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- src/Api/Controllers/ConfigController.cs | 10 ++++++---- src/Api/Controllers/TorrentsController.cs | 4 ++-- src/Services/ConfigService.cs | 10 +++++----- src/Services/MetricsService.cs | 8 ++++++-- src/Services/PostProcessor.cs | 13 ++++++++++--- 5 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/Api/Controllers/ConfigController.cs b/src/Api/Controllers/ConfigController.cs index 8fb7841..dbc3eb1 100644 --- a/src/Api/Controllers/ConfigController.cs +++ b/src/Api/Controllers/ConfigController.cs @@ -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 { ".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 { "torrent-added", "torrent-completed", "torrent-error" }, DefaultView = "dashboard", ConfirmBeforeDelete = true, MaxItemsPerPage = 25, diff --git a/src/Api/Controllers/TorrentsController.cs b/src/Api/Controllers/TorrentsController.cs index 66e9bcf..10ac986 100644 --- a/src/Api/Controllers/TorrentsController.cs +++ b/src/Api/Controllers/TorrentsController.cs @@ -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; } } \ No newline at end of file diff --git a/src/Services/ConfigService.cs b/src/Services/ConfigService.cs index 1e1936f..cdc75e7 100644 --- a/src/Services/ConfigService.cs +++ b/src/Services/ConfigService.cs @@ -17,7 +17,7 @@ namespace TransmissionRssManager.Services { private readonly ILogger _logger; private readonly string _configFilePath; - private AppConfig _cachedConfig; + private AppConfig? _cachedConfig; private readonly object _lockObject = new object(); public ConfigService(ILogger 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, diff --git a/src/Services/MetricsService.cs b/src/Services/MetricsService.cs index 91ba461..ce45fa4 100644 --- a/src/Services/MetricsService.cs +++ b/src/Services/MetricsService.cs @@ -95,8 +95,12 @@ namespace TransmissionRssManager.Services { try { - var driveInfo = new System.IO.DriveInfo(System.IO.Path.GetPathRoot(downloadDir)); - availableSpace = driveInfo.AvailableFreeSpace; + var root = System.IO.Path.GetPathRoot(downloadDir); + if (!string.IsNullOrEmpty(root)) + { + var driveInfo = new System.IO.DriveInfo(root); + availableSpace = driveInfo.AvailableFreeSpace; + } } catch (Exception ex) { diff --git a/src/Services/PostProcessor.cs b/src/Services/PostProcessor.cs index 8a60939..677b4da 100644 --- a/src/Services/PostProcessor.cs +++ b/src/Services/PostProcessor.cs @@ -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)) {