1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-03 00:52:49 -05:00
Files
bitwarden/src/Notifications/Controllers/SendController.cs
2022-08-29 16:06:55 -04:00

33 lines
891 B
C#

using System.Text;
using Bit.Core.Utilities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
namespace Bit.Notifications;
[Authorize("Internal")]
public class SendController : Controller
{
private readonly IHubContext<NotificationsHub> _hubContext;
public SendController(IHubContext<NotificationsHub> hubContext)
{
_hubContext = hubContext;
}
[HttpPost("~/send")]
[SelfHosted(SelfHostedOnly = true)]
public async Task PostSend()
{
using (var reader = new StreamReader(Request.Body, Encoding.UTF8))
{
var notificationJson = await reader.ReadToEndAsync();
if (!string.IsNullOrWhiteSpace(notificationJson))
{
await HubHelpers.SendNotificationToHubAsync(notificationJson, _hubContext);
}
}
}
}