コード例 #1
0
        public async Task <IActionResult> SaveAsync([FromBody] RadarrSettingsModel model)
        {
            var movieSettings = new MoviesSettings
            {
                Client  = DownloadClient.Radarr,
                Command = model.Command.Trim()
            };

            var radarrSetting = new RadarrSettingsModel
            {
                Hostname             = model.Hostname.Trim(),
                ApiKey               = model.ApiKey.Trim(),
                BaseUrl              = model.BaseUrl.Trim(),
                Port                 = model.Port,
                MoviePath            = model.MoviePath,
                MovieProfile         = model.MovieProfile,
                MovieMinAvailability = model.MovieMinAvailability,
                MovieTags            = model.MovieTags ?? Array.Empty <int>(),
                AnimePath            = model.AnimePath,
                AnimeProfile         = model.AnimeProfile,
                AnimeMinAvailability = model.AnimeMinAvailability,
                AnimeTags            = model.AnimeTags ?? Array.Empty <int>(),
                SearchNewRequests    = model.SearchNewRequests,
                MonitorNewRequests   = model.MonitorNewRequests,
                UseSSL               = model.UseSSL,
                Version              = model.Version
            };

            DownloadClientsSettingsRepository.SetRadarr(movieSettings, radarrSetting);

            return(Ok(new { ok = true }));
        }
コード例 #2
0
        public async Task <IActionResult> SaveAsync([FromBody] RadarrSettingsModel model)
        {
            var movieSettings = new MoviesSettings
            {
                Client = DownloadClient.Radarr
            };

            if (!model.Categories.Any())
            {
                return(BadRequest($"At least one category is required."));
            }

            if (model.Categories.Any(x => string.IsNullOrWhiteSpace(x.Name)))
            {
                return(BadRequest($"A category name is required."));
            }

            foreach (var category in model.Categories)
            {
                category.Name = category.Name.Trim();
                category.Tags = category.Tags;
            }

            if (new HashSet <string>(model.Categories.Select(x => x.Name.ToLower())).Count != model.Categories.Length)
            {
                return(BadRequest($"All categories must have different names."));
            }

            if (new HashSet <int>(model.Categories.Select(x => x.Id)).Count != model.Categories.Length)
            {
                return(BadRequest($"All categories must have different ids."));
            }

            if (model.Categories.Any(x => !Regex.IsMatch(x.Name, @"^[\w-]{1,32}$")))
            {
                return(BadRequest($"Invalid categorie names, make sure they only contain alphanumeric characters, dashes and underscores. (No spaces, etc)"));
            }

            var radarrSetting = new RadarrSettingsModel
            {
                Hostname           = model.Hostname.Trim(),
                ApiKey             = model.ApiKey.Trim(),
                BaseUrl            = model.BaseUrl.Trim(),
                Port               = model.Port,
                Categories         = model.Categories,
                SearchNewRequests  = model.SearchNewRequests,
                MonitorNewRequests = model.MonitorNewRequests,
                UseSSL             = model.UseSSL,
                Version            = model.Version
            };

            DownloadClientsSettingsRepository.SetRadarr(movieSettings, radarrSetting);

            return(Ok(new { ok = true }));
        }