This repository has been archived by the owner on Jun 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from Ullmie02/api-migration
Migrate to Asp.Net Core Web Api
- Loading branch information
Showing
3 changed files
with
54 additions
and
43 deletions.
There are no files selected for viewing
43 changes: 0 additions & 43 deletions
43
MediaBrowser.Plugins.SmtpNotifications/Api/ServerApiEntryPoints.cs
This file was deleted.
Oops, something went wrong.
53 changes: 53 additions & 0 deletions
53
MediaBrowser.Plugins.SmtpNotifications/Api/SmtpNotificationsController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
using System; | ||
using System.Net.Mime; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using MediaBrowser.Controller.Notifications; | ||
using MediaBrowser.Controller.Library; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace MediaBrowser.Plugins.SmtpNotifications.Api | ||
{ | ||
[ApiController] | ||
[Route("Notification/SMTP")] | ||
[Produces(MediaTypeNames.Application.Json)] | ||
public class SmtpNotificationsController : ControllerBase | ||
{ | ||
private readonly IUserManager _userManager; | ||
private readonly ILogger<SmtpNotificationsController> _logger; | ||
private readonly ILogger<Notifier> _notifierLogger; | ||
|
||
public SmtpNotificationsController(IUserManager userManager, ILogger<SmtpNotificationsController> logger, ILogger<Notifier> notifierLogger) | ||
{ | ||
_userManager = userManager; | ||
_logger = logger; | ||
_notifierLogger = notifierLogger; | ||
} | ||
|
||
/// <summary> | ||
/// Send test SMTP notification. | ||
/// </summary> | ||
/// <param name="userId">The user id of the Jellyfin user.</param> | ||
/// <response code="204">Test SMTP notification send successfully.</response> | ||
/// <returns>A <see cref="NoContentResult"/> indicating success.</returns> | ||
[HttpPost("Test/{userId}")] | ||
[ProducesResponseType(StatusCodes.Status204NoContent)] | ||
public async Task<ActionResult> SendSmtpTestNotification([FromRoute] string userId) | ||
{ | ||
await new Notifier(_notifierLogger).SendNotification(new UserNotification | ||
{ | ||
Date = DateTime.UtcNow, | ||
Description = "This is a test notification from Jellyfin Server", | ||
Level = Model.Notifications.NotificationLevel.Normal, | ||
Name = "Test Notification", | ||
User = _userManager.GetUserById(Guid.Parse(userId)) | ||
}, CancellationToken.None); | ||
|
||
_logger.LogInformation("Test SMTP notification sent successfully."); | ||
|
||
return NoContent(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters