Files
server/src/Notifications/Controllers/SendController.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

37 lines
1.2 KiB
C#
Raw Normal View History

using System.Text;
2018-08-16 12:05:01 -04:00
using Bit.Core.Utilities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
2018-08-16 13:45:31 -04:00
namespace Bit.Notifications;
2022-08-29 16:06:55 -04:00
2018-08-16 13:45:31 -04:00
[Authorize("Internal")]
public class SendController : Controller
2018-08-16 12:05:01 -04:00
{
2018-08-16 13:45:31 -04:00
private readonly IHubContext<NotificationsHub> _hubContext;
private readonly IHubContext<AnonymousNotificationsHub> _anonymousHubContext;
private readonly ILogger<SendController> _logger;
2018-08-16 12:05:01 -04:00
public SendController(IHubContext<NotificationsHub> hubContext, IHubContext<AnonymousNotificationsHub> anonymousHubContext, ILogger<SendController> logger)
{
2018-08-16 13:45:31 -04:00
_hubContext = hubContext;
_anonymousHubContext = anonymousHubContext;
_logger = logger;
}
[HttpPost("~/send")]
2019-09-08 22:14:15 -04:00
[SelfHosted(SelfHostedOnly = true)]
public async Task PostSend()
2022-08-29 16:06:55 -04:00
{
using (var reader = new StreamReader(Request.Body, Encoding.UTF8))
2018-08-16 12:05:01 -04:00
{
var notificationJson = await reader.ReadToEndAsync();
if (!string.IsNullOrWhiteSpace(notificationJson))
{
await HubHelpers.SendNotificationToHubAsync(notificationJson, _hubContext, _anonymousHubContext, _logger);
}
2018-08-16 12:05:01 -04:00
}
}
}