1
0
mirror of https://github.com/bitwarden/server synced 2025-12-17 08:43:27 +00:00
Files
server/src/Notifications/Controllers/SendController.cs
Matt Gibson 77dcf7f339 Log SignalR pushes (#4392)
We are interested in the rate at which signalR notifications are pushed to clients. This enables tracking only of that rate and the type of notification, nothing more identifiable.

Data will be used to determine feasibility of transferring to web push
2024-06-27 13:07:51 -04:00

37 lines
1.2 KiB
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;
private readonly IHubContext<AnonymousNotificationsHub> _anonymousHubContext;
private readonly ILogger<SendController> _logger;
public SendController(IHubContext<NotificationsHub> hubContext, IHubContext<AnonymousNotificationsHub> anonymousHubContext, ILogger<SendController> logger)
{
_hubContext = hubContext;
_anonymousHubContext = anonymousHubContext;
_logger = logger;
}
[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, _anonymousHubContext, _logger);
}
}
}
}