Changed SessionController.SendMessageCommand

implementation receive data in the POST body, as that is how the
jellyfin-web client currently posts the data to the server.

Resolves: #5628
This commit is contained in:
Brian Arnold 2021-03-26 10:02:23 -04:00 committed by Brian C. Arnold
parent a890a85092
commit 81e3e5ca48

View File

@ -313,9 +313,7 @@ namespace Jellyfin.Api.Controllers
/// Issues a command to a client to display a message to the user. /// Issues a command to a client to display a message to the user.
/// </summary> /// </summary>
/// <param name="sessionId">The session id.</param> /// <param name="sessionId">The session id.</param>
/// <param name="text">The message test.</param> /// <param name="command">The <see cref="MessageCommand" /> object containing Header, Message Text, and TimeoutMs.</param>
/// <param name="header">The message header.</param>
/// <param name="timeoutMs">The message timeout. If omitted the user will have to confirm viewing the message.</param>
/// <response code="204">Message sent.</response> /// <response code="204">Message sent.</response>
/// <returns>A <see cref="NoContentResult"/>.</returns> /// <returns>A <see cref="NoContentResult"/>.</returns>
[HttpPost("Sessions/{sessionId}/Message")] [HttpPost("Sessions/{sessionId}/Message")]
@ -323,18 +321,25 @@ namespace Jellyfin.Api.Controllers
[ProducesResponseType(StatusCodes.Status204NoContent)] [ProducesResponseType(StatusCodes.Status204NoContent)]
public ActionResult SendMessageCommand( public ActionResult SendMessageCommand(
[FromRoute, Required] string sessionId, [FromRoute, Required] string sessionId,
[FromQuery, Required] string text, [FromBody] MessageCommand command)
[FromQuery] string? header,
[FromQuery] long? timeoutMs)
{ {
var command = new MessageCommand if (command == null)
{ {
Header = string.IsNullOrEmpty(header) ? "Message from Server" : header, throw new ArgumentException("Request body may not be null");
TimeoutMs = timeoutMs, }
Text = text //Need to check if message.Text is null, since [Required] can't be applied to properties of a deserialized object.
if (string.IsNullOrWhiteSpace(command.Text))
{
throw new ArgumentNullException("Message Text may not be empty.");
}
var nullCorrectedCommand = new MessageCommand
{
Header = string.IsNullOrWhiteSpace(command.Header) ? "Message from Server" : command.Header,
TimeoutMs = command.TimeoutMs,
Text = command.Text
}; };
_sessionManager.SendMessageCommand(RequestHelpers.GetSession(_sessionManager, _authContext, Request).Id, sessionId, command, CancellationToken.None); _sessionManager.SendMessageCommand(RequestHelpers.GetSession(_sessionManager, _authContext, Request).Id, sessionId, nullCorrectedCommand, CancellationToken.None);
return NoContent(); return NoContent();
} }