2019-12-20 21:30:51 +01:00
|
|
|
#pragma warning disable CS1591
|
|
|
|
#pragma warning disable SA1402
|
|
|
|
#pragma warning disable SA1600
|
|
|
|
#pragma warning disable SA1649
|
|
|
|
|
2019-01-13 20:54:44 +01:00
|
|
|
using System;
|
2014-04-25 22:15:50 +02:00
|
|
|
using System.Collections.Generic;
|
2014-04-27 05:42:05 +02:00
|
|
|
using System.Linq;
|
2013-07-06 23:23:32 +02:00
|
|
|
using System.Threading;
|
|
|
|
using System.Threading.Tasks;
|
2019-01-13 20:18:07 +01:00
|
|
|
using MediaBrowser.Controller.Library;
|
|
|
|
using MediaBrowser.Controller.Net;
|
|
|
|
using MediaBrowser.Controller.Notifications;
|
2018-09-12 19:26:21 +02:00
|
|
|
using MediaBrowser.Model.Dto;
|
2019-01-13 20:18:07 +01:00
|
|
|
using MediaBrowser.Model.Notifications;
|
|
|
|
using MediaBrowser.Model.Services;
|
2013-07-06 23:23:32 +02:00
|
|
|
|
2018-09-12 19:26:21 +02:00
|
|
|
namespace Emby.Notifications.Api
|
2013-07-06 23:23:32 +02:00
|
|
|
{
|
2014-04-27 05:42:05 +02:00
|
|
|
[Route("/Notifications/Types", "GET", Summary = "Gets notification types")]
|
|
|
|
public class GetNotificationTypes : IReturn<List<NotificationTypeInfo>>
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
[Route("/Notifications/Services", "GET", Summary = "Gets notification types")]
|
2018-09-12 19:26:21 +02:00
|
|
|
public class GetNotificationServices : IReturn<List<NameIdPair>>
|
2014-04-27 05:42:05 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-27 06:35:04 +02:00
|
|
|
[Route("/Notifications/Admin", "POST", Summary = "Sends a notification to all admin users")]
|
2014-04-27 05:42:05 +02:00
|
|
|
public class AddAdminNotification : IReturnVoid
|
2013-07-06 23:23:32 +02:00
|
|
|
{
|
2014-04-27 05:42:05 +02:00
|
|
|
[ApiMember(Name = "Name", Description = "The notification's name", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
|
2019-12-20 21:30:51 +01:00
|
|
|
public string Name { get; set; } = string.Empty;
|
2014-04-27 05:42:05 +02:00
|
|
|
|
|
|
|
[ApiMember(Name = "Description", Description = "The notification's description", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
|
2019-12-20 21:30:51 +01:00
|
|
|
public string Description { get; set; } = string.Empty;
|
2013-07-06 23:23:32 +02:00
|
|
|
|
2014-04-27 05:42:05 +02:00
|
|
|
[ApiMember(Name = "ImageUrl", Description = "The notification's image url", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
|
2019-12-20 21:30:51 +01:00
|
|
|
public string? ImageUrl { get; set; }
|
2014-04-27 05:42:05 +02:00
|
|
|
|
|
|
|
[ApiMember(Name = "Url", Description = "The notification's info url", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
|
2019-12-20 21:30:51 +01:00
|
|
|
public string? Url { get; set; }
|
2014-04-27 05:42:05 +02:00
|
|
|
|
|
|
|
[ApiMember(Name = "Level", Description = "The notification level", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
|
|
|
|
public NotificationLevel Level { get; set; }
|
|
|
|
}
|
2014-03-23 21:07:02 +01:00
|
|
|
|
2014-07-04 04:22:57 +02:00
|
|
|
[Authenticated]
|
2018-09-12 19:26:21 +02:00
|
|
|
public class NotificationsService : IService
|
2013-07-06 23:23:32 +02:00
|
|
|
{
|
2014-04-25 22:15:50 +02:00
|
|
|
private readonly INotificationManager _notificationManager;
|
2014-04-27 05:42:05 +02:00
|
|
|
private readonly IUserManager _userManager;
|
2013-07-06 23:23:32 +02:00
|
|
|
|
2018-09-12 19:26:21 +02:00
|
|
|
public NotificationsService(INotificationManager notificationManager, IUserManager userManager)
|
2013-07-06 23:23:32 +02:00
|
|
|
{
|
2014-04-25 22:15:50 +02:00
|
|
|
_notificationManager = notificationManager;
|
2014-04-27 05:42:05 +02:00
|
|
|
_userManager = userManager;
|
2013-07-06 23:23:32 +02:00
|
|
|
}
|
|
|
|
|
2014-04-27 05:42:05 +02:00
|
|
|
public object Get(GetNotificationTypes request)
|
|
|
|
{
|
2019-12-20 21:30:51 +01:00
|
|
|
_ = request; // Silence unused variable warning
|
2018-09-12 19:26:21 +02:00
|
|
|
return _notificationManager.GetNotificationTypes();
|
2014-04-27 05:42:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public object Get(GetNotificationServices request)
|
|
|
|
{
|
2019-12-20 21:30:51 +01:00
|
|
|
_ = request; // Silence unused variable warning
|
2018-09-12 19:26:21 +02:00
|
|
|
return _notificationManager.GetNotificationServices().ToList();
|
2014-04-27 05:42:05 +02:00
|
|
|
}
|
|
|
|
|
2018-09-12 19:26:21 +02:00
|
|
|
public Task Post(AddAdminNotification request)
|
2014-04-27 05:42:05 +02:00
|
|
|
{
|
|
|
|
// This endpoint really just exists as post of a real with sickbeard
|
|
|
|
var notification = new NotificationRequest
|
|
|
|
{
|
|
|
|
Date = DateTime.UtcNow,
|
|
|
|
Description = request.Description,
|
|
|
|
Level = request.Level,
|
|
|
|
Name = request.Name,
|
|
|
|
Url = request.Url,
|
2018-09-12 19:26:21 +02:00
|
|
|
UserIds = _userManager.Users.Where(i => i.Policy.IsAdministrator).Select(i => i.Id).ToArray()
|
2014-04-27 05:42:05 +02:00
|
|
|
};
|
|
|
|
|
2018-09-12 19:26:21 +02:00
|
|
|
return _notificationManager.SendNotification(notification, CancellationToken.None);
|
2013-07-06 23:23:32 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|