2022-06-29 19:46:41 -04:00
|
|
|
|
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;
|
2023-05-31 11:12:43 -04:00
|
|
|
|
private readonly IHubContext<AnonymousNotificationsHub> _anonymousHubContext;
|
2024-06-27 13:07:51 -04:00
|
|
|
|
private readonly ILogger<SendController> _logger;
|
2018-08-16 12:05:01 -04:00
|
|
|
|
|
2024-06-27 13:07:51 -04:00
|
|
|
|
public SendController(IHubContext<NotificationsHub> hubContext, IHubContext<AnonymousNotificationsHub> anonymousHubContext, ILogger<SendController> logger)
|
2022-08-29 15:53:48 -04:00
|
|
|
|
{
|
2018-08-16 13:45:31 -04:00
|
|
|
|
_hubContext = hubContext;
|
2023-05-31 11:12:43 -04:00
|
|
|
|
_anonymousHubContext = anonymousHubContext;
|
2024-06-27 13:07:51 -04:00
|
|
|
|
_logger = logger;
|
2022-08-29 15:53:48 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-08-24 20:31:17 -04:00
|
|
|
|
[HttpPost("~/send")]
|
2019-09-08 22:14:15 -04:00
|
|
|
|
[SelfHosted(SelfHostedOnly = true)]
|
2018-08-24 20:31:17 -04:00
|
|
|
|
public async Task PostSend()
|
2022-08-29 16:06:55 -04:00
|
|
|
|
{
|
2020-03-27 14:36:37 -04:00
|
|
|
|
using (var reader = new StreamReader(Request.Body, Encoding.UTF8))
|
2018-08-16 12:05:01 -04:00
|
|
|
|
{
|
2020-03-27 14:36:37 -04:00
|
|
|
|
var notificationJson = await reader.ReadToEndAsync();
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(notificationJson))
|
2018-08-23 21:56:48 -04:00
|
|
|
|
{
|
2024-06-27 13:07:51 -04:00
|
|
|
|
await HubHelpers.SendNotificationToHubAsync(notificationJson, _hubContext, _anonymousHubContext, _logger);
|
2018-08-23 21:56:48 -04:00
|
|
|
|
}
|
2018-08-16 12:05:01 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|