2023-04-23 02:42:41 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using FluentValidation;
|
|
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
using NzbDrone.Core.Annotations;
|
|
|
|
using NzbDrone.Core.ThingiProvider;
|
|
|
|
using NzbDrone.Core.Validation;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Notifications.Apprise
|
|
|
|
{
|
|
|
|
public class AppriseSettingsValidator : AbstractValidator<AppriseSettings>
|
|
|
|
{
|
|
|
|
public AppriseSettingsValidator()
|
|
|
|
{
|
|
|
|
RuleFor(c => c.ServerUrl).IsValidUrl();
|
|
|
|
|
|
|
|
RuleFor(c => c.ConfigurationKey).NotEmpty()
|
|
|
|
.When(c => c.StatelessUrls.IsNullOrWhiteSpace())
|
|
|
|
.WithMessage("Use either Configuration Key or Stateless URLs");
|
|
|
|
|
|
|
|
RuleFor(c => c.ConfigurationKey).Matches("^[a-z0-9-]*$")
|
|
|
|
.WithMessage("Allowed characters a-z, 0-9 and -");
|
|
|
|
|
|
|
|
RuleFor(c => c.StatelessUrls).NotEmpty()
|
|
|
|
.When(c => c.ConfigurationKey.IsNullOrWhiteSpace())
|
|
|
|
.WithMessage("Use either Configuration Key or Stateless URLs");
|
|
|
|
|
|
|
|
RuleFor(c => c.StatelessUrls).Empty()
|
|
|
|
.When(c => c.ConfigurationKey.IsNotNullOrWhiteSpace())
|
|
|
|
.WithMessage("Use either Configuration Key or Stateless URLs");
|
|
|
|
|
|
|
|
RuleFor(c => c.Tags).Empty()
|
|
|
|
.When(c => c.StatelessUrls.IsNotNullOrWhiteSpace())
|
|
|
|
.WithMessage("Stateless URLs do not support tags");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public class AppriseSettings : IProviderConfig
|
|
|
|
{
|
|
|
|
private static readonly AppriseSettingsValidator Validator = new ();
|
|
|
|
|
|
|
|
public AppriseSettings()
|
|
|
|
{
|
|
|
|
NotificationType = (int)AppriseNotificationType.Info;
|
|
|
|
Tags = Array.Empty<string>();
|
|
|
|
}
|
|
|
|
|
2024-01-03 20:41:16 +00:00
|
|
|
[FieldDefinition(1, Label = "NotificationsAppriseSettingsServerUrl", Type = FieldType.Url, Placeholder = "http://localhost:8000", HelpText = "NotificationsAppriseSettingsServerUrlHelpText", HelpLink = "https://github.com/caronc/apprise-api")]
|
2023-04-23 02:42:41 +00:00
|
|
|
public string ServerUrl { get; set; }
|
|
|
|
|
2024-01-03 20:41:16 +00:00
|
|
|
[FieldDefinition(2, Label = "NotificationsAppriseSettingsConfigurationKey", Type = FieldType.Textbox, HelpText = "NotificationsAppriseSettingsConfigurationKeyHelpText", HelpLink = "https://github.com/caronc/apprise-api#persistent-storage-solution")]
|
2023-04-23 02:42:41 +00:00
|
|
|
public string ConfigurationKey { get; set; }
|
|
|
|
|
2024-01-03 20:41:16 +00:00
|
|
|
[FieldDefinition(3, Label = "NotificationsAppriseSettingsStatelessUrls", Type = FieldType.Textbox, HelpText = "NotificationsAppriseSettingsStatelessUrlsHelpText", HelpLink = "https://github.com/caronc/apprise#productivity-based-notifications")]
|
2023-04-23 02:42:41 +00:00
|
|
|
public string StatelessUrls { get; set; }
|
|
|
|
|
2024-01-03 20:41:16 +00:00
|
|
|
[FieldDefinition(4, Label = "NotificationsAppriseSettingsNotificationType", Type = FieldType.Select, SelectOptions = typeof(AppriseNotificationType))]
|
2023-04-23 02:42:41 +00:00
|
|
|
public int NotificationType { get; set; }
|
|
|
|
|
2024-01-03 20:41:16 +00:00
|
|
|
[FieldDefinition(5, Label = "NotificationsAppriseSettingsTags", Type = FieldType.Tag, HelpText = "NotificationsAppriseSettingsTagsHelpText")]
|
2023-04-23 02:42:41 +00:00
|
|
|
public IEnumerable<string> Tags { get; set; }
|
|
|
|
|
2024-01-03 20:41:16 +00:00
|
|
|
[FieldDefinition(6, Label = "Username", Type = FieldType.Textbox, HelpText = "NotificationsAppriseSettingsUsernameHelpText", Privacy = PrivacyLevel.UserName)]
|
2023-04-23 02:42:41 +00:00
|
|
|
public string AuthUsername { get; set; }
|
|
|
|
|
2024-01-03 20:41:16 +00:00
|
|
|
[FieldDefinition(7, Label = "Password", Type = FieldType.Password, HelpText = "NotificationsAppriseSettingsPasswordHelpText", Privacy = PrivacyLevel.Password)]
|
2023-04-23 02:42:41 +00:00
|
|
|
public string AuthPassword { get; set; }
|
|
|
|
|
|
|
|
public NzbDroneValidationResult Validate()
|
|
|
|
{
|
|
|
|
return new NzbDroneValidationResult(Validator.Validate(this));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|