Skip to content

Conversation

@Bpendragon
Copy link

@Bpendragon Bpendragon commented Nov 18, 2024

These changes are based on those provided by @stoggi in #221 but with additional changes and movements based on suggestions from @crobibero.

Changes:

  • Adds WebhookMediaContentType.cs an Enum that lists out the most common text encodings for webhooks (Plaintext, Json, and Xml)
  • Sets most clients to use Json by default as that is what they are designed for.
  • Defaults the Generic Client to Plain Text Encoding.
    • Adds logic to Generic Client to change the encoding based on the provided headers.
  • Adds functions to BaseOption.cs to escape Json properly. Xml and Plaintext are left to use the existing escape function as they had been.
    • These can easily be changed to other or better functions in the future.
  • Adds list of previously escaped text fields to BaseOption.cs
  • Removes old escape function and calls from DataObjectHelpers.cs

This PR will:

This PR may:

{
Headers = Array.Empty<GenericFormOptionValue>();
Fields = Array.Empty<GenericFormOptionValue>();
// The MediaType is left as JSON because that is what is assumed to be used in GenericFormClient.cs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Json is not assuimed in GenericFormClient, the content type should be application/x-www-form-urlencoded

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may not be intended to be, but the body is currently treated solely as JSON per current master: https://github.com/jellyfin/jellyfin-plugin-webhook/blob/c507d/Jellyfin.Plugin.Webhook/Destinations/GenericForm/GenericFormClient.cs#L52-L58
Once in the processing itself the Generic Client does use FormURLContent (line 77 of same file, unchanged in PR)

/// <summary>
/// Gets or sets the Media-Content type of the webhook body. Should not be set by User except for Generic Client.
/// </summary>
public WebhookMediaContentType MediaContentType { get; set; } = WebhookMediaContentType.Json;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably possible to set in the webui

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do have it available to set in the Generic Client via a header, though at the moment it only supports json, xml, and generic/plaintext. For the individual pre-built clients though I think it makes sense to keep it hidden, or at least on a per-client basis. Discord webhooks for example only allow for JSON, so it makes no sense to expose an option that invariably breaks functionality if changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Please provide a helper that supports changing to escape as \ n in the template

2 participants