mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-28 13:01:28 +02:00
(Apprise) Change BaseUrl to ServerUrl
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
using System.Data;
|
||||
using Dapper;
|
||||
using FluentMigrator;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Datastore.Migration.Framework;
|
||||
|
||||
namespace NzbDrone.Core.Datastore.Migration
|
||||
{
|
||||
[Migration(031)]
|
||||
public class apprise_server_url : NzbDroneMigrationBase
|
||||
{
|
||||
protected override void MainDbUpgrade()
|
||||
{
|
||||
Execute.WithConnection(MigrateToServerUrl);
|
||||
}
|
||||
|
||||
private void MigrateToServerUrl(IDbConnection conn, IDbTransaction tran)
|
||||
{
|
||||
using var selectCommand = conn.CreateCommand();
|
||||
selectCommand.Transaction = tran;
|
||||
selectCommand.CommandText = "SELECT \"Id\", \"Settings\" FROM \"Notifications\" WHERE \"Implementation\" = 'Apprise'";
|
||||
|
||||
using var reader = selectCommand.ExecuteReader();
|
||||
|
||||
while (reader.Read())
|
||||
{
|
||||
var id = reader.GetInt32(0);
|
||||
var settings = reader.GetString(1);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(settings))
|
||||
{
|
||||
var jsonObject = Json.Deserialize<JObject>(settings);
|
||||
|
||||
if (jsonObject.ContainsKey("baseUrl"))
|
||||
{
|
||||
jsonObject.Add("serverUrl", jsonObject.Value<string>("baseUrl"));
|
||||
jsonObject.Remove("baseUrl");
|
||||
}
|
||||
|
||||
settings = jsonObject.ToJson();
|
||||
}
|
||||
|
||||
var parameters = new { Settings = settings, Id = id };
|
||||
conn.Execute("UPDATE Notifications SET Settings = @Settings WHERE Id = @Id", parameters, transaction: tran);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -35,7 +35,7 @@ namespace NzbDrone.Core.Notifications.Apprise
|
||||
Type = (AppriseNotificationType)settings.NotificationType
|
||||
};
|
||||
|
||||
var requestBuilder = new HttpRequestBuilder(settings.BaseUrl.TrimEnd('/', ' '))
|
||||
var requestBuilder = new HttpRequestBuilder(settings.ServerUrl.TrimEnd('/', ' '))
|
||||
.Post()
|
||||
.Accept(HttpAccept.Json);
|
||||
|
||||
|
@@ -12,26 +12,26 @@ namespace NzbDrone.Core.Notifications.Apprise
|
||||
{
|
||||
public AppriseSettingsValidator()
|
||||
{
|
||||
RuleFor(c => c.BaseUrl).IsValidUrl();
|
||||
RuleFor(c => c.ServerUrl).IsValidUrl();
|
||||
|
||||
RuleFor(c => c.ConfigurationKey).NotEmpty()
|
||||
.When(c => c.StatelessUrls.IsNullOrWhiteSpace())
|
||||
.WithMessage("Use either Configuration Key or Stateless Urls");
|
||||
.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");
|
||||
.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");
|
||||
.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");
|
||||
.WithMessage("Stateless URLs do not support tags");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,13 +45,13 @@ namespace NzbDrone.Core.Notifications.Apprise
|
||||
Tags = Array.Empty<string>();
|
||||
}
|
||||
|
||||
[FieldDefinition(1, Label = "Apprise Base URL", Type = FieldType.Url, Placeholder = "http://localhost:8000", HelpText = "Apprise server Base URL, including http(s):// and port if needed", HelpLink = "https://github.com/caronc/apprise-api")]
|
||||
public string BaseUrl { get; set; }
|
||||
[FieldDefinition(1, Label = "Apprise Server URL", Type = FieldType.Url, Placeholder = "http://localhost:8000", HelpText = "Apprise server URL, including http(s):// and port if needed", HelpLink = "https://github.com/caronc/apprise-api")]
|
||||
public string ServerUrl { get; set; }
|
||||
|
||||
[FieldDefinition(2, Label = "Apprise Configuration Key", Type = FieldType.Textbox, HelpText = "Configuration Key for the Persistent Storage Solution. Leave empty if Stateless Urls is used.", HelpLink = "https://github.com/caronc/apprise-api#persistent-storage-solution")]
|
||||
[FieldDefinition(2, Label = "Apprise Configuration Key", Type = FieldType.Textbox, HelpText = "Configuration Key for the Persistent Storage Solution. Leave empty if Stateless URLs is used.", HelpLink = "https://github.com/caronc/apprise-api#persistent-storage-solution")]
|
||||
public string ConfigurationKey { get; set; }
|
||||
|
||||
[FieldDefinition(3, Label = "Apprise Stateless Urls", Type = FieldType.Textbox, HelpText = "One or more URLs separated by commas identifying where the notification should be sent to. Leave empty if Persistent Storage is used.", HelpLink = "https://github.com/caronc/apprise#productivity-based-notifications")]
|
||||
[FieldDefinition(3, Label = "Apprise Stateless URLs", Type = FieldType.Textbox, HelpText = "One or more URLs separated by commas identifying where the notification should be sent to. Leave empty if Persistent Storage is used.", HelpLink = "https://github.com/caronc/apprise#productivity-based-notifications")]
|
||||
public string StatelessUrls { get; set; }
|
||||
|
||||
[FieldDefinition(4, Label = "Apprise Notification Type", Type = FieldType.Select, SelectOptions = typeof(AppriseNotificationType))]
|
||||
@@ -60,10 +60,10 @@ namespace NzbDrone.Core.Notifications.Apprise
|
||||
[FieldDefinition(5, Label = "Apprise Tags", Type = FieldType.Tag, HelpText = "Optionally notify only those tagged accordingly.")]
|
||||
public IEnumerable<string> Tags { get; set; }
|
||||
|
||||
[FieldDefinition(6, Label = "Auth Username", Type = FieldType.Textbox, HelpText = "HTTP Basic Auth Username", Privacy = PrivacyLevel.UserName)]
|
||||
[FieldDefinition(6, Label = "Username", Type = FieldType.Textbox, HelpText = "HTTP Basic Auth Username", Privacy = PrivacyLevel.UserName)]
|
||||
public string AuthUsername { get; set; }
|
||||
|
||||
[FieldDefinition(7, Label = "Auth Password", Type = FieldType.Password, HelpText = "HTTP Basic Auth Password", Privacy = PrivacyLevel.Password)]
|
||||
[FieldDefinition(7, Label = "Password", Type = FieldType.Password, HelpText = "HTTP Basic Auth Password", Privacy = PrivacyLevel.Password)]
|
||||
public string AuthPassword { get; set; }
|
||||
|
||||
public NzbDroneValidationResult Validate()
|
||||
|
Reference in New Issue
Block a user