2019-07-26 11:59:42 -04:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.IO;
|
2018-08-23 21:56:48 -04:00
|
|
|
|
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")]
|
2018-08-24 20:31:17 -04:00
|
|
|
|
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
|
|
|
|
|
2018-08-24 20:31:17 -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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
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()
|
2018-08-16 12:05:01 -04:00
|
|
|
|
{
|
2020-03-27 14:36:37 -04:00
|
|
|
|
using (var reader = new StreamReader(Request.Body, Encoding.UTF8))
|
2018-08-23 21:56:48 -04:00
|
|
|
|
{
|
|
|
|
|
|
var notificationJson = await reader.ReadToEndAsync();
|
2020-03-27 14:36:37 -04:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(notificationJson))
|
2018-08-23 21:56:48 -04:00
|
|
|
|
{
|
2018-08-25 17:21:42 -04:00
|
|
|
|
await HubHelpers.SendNotificationToHubAsync(notificationJson, _hubContext);
|
2018-08-23 21:56:48 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-08-16 12:05:01 -04:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|