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

45 lines
1.2 KiB
C#
Raw Normal View History

2019-07-26 11:59:42 -04:00
using System;
using System.IO;
using System.Text;
using System.Threading.Tasks;
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
2018-08-16 12:05:01 -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;
2018-08-16 12:05:01 -04:00
public SendController(IHubContext<NotificationsHub> hubContext)
2018-08-16 12:05:01 -04:00
{
2018-08-16 13:45:31 -04:00
_hubContext = hubContext;
2018-08-16 12:05:01 -04:00
}
2019-07-26 11:59:42 -04:00
[HttpGet("~/alive")]
[HttpGet("~/now")]
[AllowAnonymous]
public DateTime GetAlive()
{
return DateTime.UtcNow;
}
[HttpPost("~/send")]
2019-09-08 22:14:15 -04:00
[SelfHosted(SelfHostedOnly = true)]
public async Task PostSend()
2018-08-16 12:05:01 -04:00
{
using (var reader = new StreamReader(Request.Body, Encoding.UTF8))
{
var notificationJson = await reader.ReadToEndAsync();
if (!string.IsNullOrWhiteSpace(notificationJson))
{
2018-08-25 17:21:42 -04:00
await HubHelpers.SendNotificationToHubAsync(notificationJson, _hubContext);
}
}
2018-08-16 12:05:01 -04:00
}
}
}