Skip to content

Commit

Permalink
Implement option to trim leading/trailing whitespace from message body (
Browse files Browse the repository at this point in the history
  • Loading branch information
danielztolnai authored Mar 24, 2024
1 parent 01ce5b2 commit a9171e8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions Jellyfin.Plugin.Webhook/Configuration/Web/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ <h2 class="sectionTitle">Webhook</h2>
<input is="emby-checkbox" type="checkbox" data-name="chkSendAllProperties"/>
<span>Send All Properties (ignores template)</span>
</label>
<label class="checkboxContainer">
<input is="emby-checkbox" type="checkbox" data-name="chkTrimWhitespace"/>
<span>Trim leading and trailing whitespace from message body before sending</span>
</label>
<label class="checkboxContainer">
<input is="emby-checkbox" type="checkbox" data-name="chkSkipEmptyMessageBody"/>
<span>Do not send when message body is empty</span>
Expand Down
2 changes: 2 additions & 0 deletions Jellyfin.Plugin.Webhook/Configuration/Web/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@
element.querySelector("[data-name=txtWebhookName]").value = config.WebhookName || "";
element.querySelector("[data-name=txtWebhookUri]").value = config.WebhookUri || "";
element.querySelector("[data-name=chkSendAllProperties]").checked = config.SendAllProperties || false;
element.querySelector("[data-name=chkTrimWhitespace]").checked = config.TrimWhitespace || false;
element.querySelector("[data-name=chkSkipEmptyMessageBody]").checked = config.SkipEmptyMessageBody || false;
element.querySelector("[data-name=txtTemplate]").value = Webhook.atou(config.Template || "");

Expand All @@ -183,6 +184,7 @@
config.WebhookName = element.querySelector("[data-name=txtWebhookName]").value || "";
config.WebhookUri = element.querySelector("[data-name=txtWebhookUri]").value || "";
config.SendAllProperties = element.querySelector("[data-name=chkSendAllProperties]").checked || false;
config.TrimWhitespace = element.querySelector("[data-name=chkTrimWhitespace]").checked || false;
config.SkipEmptyMessageBody = element.querySelector("[data-name=chkSkipEmptyMessageBody]").checked || false;
config.Template = Webhook.utoa(element.querySelector("[data-name=txtTemplate]").value || "");

Expand Down
9 changes: 8 additions & 1 deletion Jellyfin.Plugin.Webhook/Destinations/BaseOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ public abstract class BaseOption
/// </summary>
public bool SendAllProperties { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to trim the message body before sending.
/// </summary>
public bool TrimWhitespace { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to skip sending an empty message body.
/// </summary>
Expand Down Expand Up @@ -98,8 +103,10 @@ public HandlebarsTemplate<object, string> GetCompiledTemplate()
/// <returns>The string message body.</returns>
public string GetMessageBody(Dictionary<string, object> data)
{
return SendAllProperties
var body = SendAllProperties
? JsonSerializer.Serialize(data, JsonDefaults.Options)
: GetCompiledTemplate()(data);

return TrimWhitespace ? body.Trim() : body;
}
}

0 comments on commit a9171e8

Please sign in to comment.