Skip to content
This repository was archived by the owner on Jun 17, 2022. It is now read-only.

Commit 3ef5dfe

Browse files
authored
Merge pull request #14 from jellyfin/10.7
Target 10.7
2 parents 6fae0ee + cf887b3 commit 3ef5dfe

File tree

4 files changed

+33
-37
lines changed

4 files changed

+33
-37
lines changed

Jellyfin.Plugin.Slack/Api/SlackNotificationsController.cs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Net.Http;
5+
using System.Net.Http.Json;
46
using System.Net.Mime;
7+
using System.Text.Json;
58
using System.Threading.Tasks;
9+
using MediaBrowser.Common.Json;
610
using MediaBrowser.Common.Net;
7-
using MediaBrowser.Model.Serialization;
811
using Microsoft.AspNetCore.Http;
912
using Microsoft.AspNetCore.Mvc;
1013
using Microsoft.Extensions.Logging;
@@ -16,15 +19,16 @@ namespace Jellyfin.Plugin.Slack.Api
1619
[Produces(MediaTypeNames.Application.Json)]
1720
public class SlackNotificationsController : ControllerBase
1821
{
19-
private readonly IHttpClient _httpClient;
22+
private readonly IHttpClientFactory _httpClientFactory;
2023
private readonly ILogger<SlackNotificationsController> _logger;
21-
private readonly IJsonSerializer _serializer;
22-
23-
public SlackNotificationsController(ILogger<SlackNotificationsController> logger, IHttpClient httpClient, IJsonSerializer serializer)
24+
private readonly JsonSerializerOptions _jsonSerializerOptions;
25+
26+
public SlackNotificationsController(ILogger<SlackNotificationsController> logger, IHttpClientFactory httpClientFactory)
2427
{
2528
_logger = logger;
26-
_httpClient = httpClient;
27-
_serializer = serializer;
29+
_httpClientFactory = httpClientFactory;
30+
_jsonSerializerOptions = JsonDefaults.GetOptions();
31+
2832
}
2933

3034
/// <summary>
@@ -54,15 +58,9 @@ public async Task<ActionResult> SendSlackTestNotification([FromRoute] string use
5458
parameters.Add("icon_url", options.IconUrl);
5559
}
5660

57-
var httpRequest = new HttpRequestOptions
58-
{
59-
Url = options.WebHookUrl,
60-
RequestContent = _serializer.SerializeToString(parameters),
61-
RequestContentType = "application/json",
62-
};
63-
64-
await _httpClient.Post(httpRequest).ConfigureAwait(false);
65-
61+
using var response = await _httpClientFactory.CreateClient(NamedClient.Default)
62+
.PostAsJsonAsync(options.WebHookUrl, parameters, _jsonSerializerOptions)
63+
.ConfigureAwait(false);
6664
_logger.LogInformation("Slack test notification sent.");
6765

6866
return NoContent();
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.1</TargetFramework>
5-
<AssemblyVersion>6.0.0.0</AssemblyVersion>
6-
<FileVersion>6.0.0.0</FileVersion>
4+
<TargetFramework>net5.0</TargetFramework>
5+
<AssemblyVersion>7.0.0.0</AssemblyVersion>
6+
<FileVersion>7.0.0.0</FileVersion>
77
</PropertyGroup>
88

99
<ItemGroup>
@@ -15,7 +15,7 @@
1515
<PackageReference Include="Jellyfin.Data" Version="10.*-*" />
1616
<PackageReference Include="Jellyfin.Controller" Version="10.*-*" />
1717
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
18-
<PackageReference Include="Microsoft.Net.Http.Headers" Version="2.2.8" />
18+
<PackageReference Include="Microsoft.Extensions.Http" Version="5.0.0" />
1919
</ItemGroup>
2020

2121
</Project>

Jellyfin.Plugin.Slack/Notifier.cs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,31 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Net.Http;
5+
using System.Net.Http.Json;
6+
using System.Text.Json;
47
using System.Threading;
58
using System.Threading.Tasks;
69
using Jellyfin.Plugin.Slack.Configuration;
710
using Jellyfin.Data.Entities;
11+
using MediaBrowser.Common.Json;
812
using MediaBrowser.Common.Net;
9-
using MediaBrowser.Controller.Entities;
1013
using MediaBrowser.Controller.Notifications;
11-
using MediaBrowser.Model.Serialization;
1214
using Microsoft.Extensions.Logging;
13-
using Microsoft.Net.Http.Headers;
1415

1516
namespace Jellyfin.Plugin.Slack
1617
{
1718
public class Notifier : INotificationService
1819
{
1920
private readonly ILogger<Notifier> _logger;
20-
private readonly IHttpClient _httpClient;
21-
private readonly IJsonSerializer _serializer;
21+
private readonly IHttpClientFactory _httpClientFactory;
22+
private readonly JsonSerializerOptions _jsonSerializerOptions;
2223

23-
public Notifier(ILogger<Notifier> logger, IHttpClient httpClient, IJsonSerializer serializer)
24+
public Notifier(ILogger<Notifier> logger, IHttpClientFactory httpClientFactory)
2425
{
2526
_logger = logger;
26-
_httpClient = httpClient;
27-
_serializer = serializer;
27+
_httpClientFactory = httpClientFactory;
28+
_jsonSerializerOptions = JsonDefaults.GetOptions();
2829
}
2930

3031
public bool IsEnabledForUser(User user)
@@ -59,14 +60,10 @@ public async Task SendNotification(UserNotification request, CancellationToken c
5960
}
6061

6162
_logger.LogDebug("Notification to Slack : {0} - {1}", options.WebHookUrl, request.Description);
62-
var httpRequest = new HttpRequestOptions
63-
{
64-
Url = options.WebHookUrl,
65-
RequestContent = _serializer.SerializeToString(parameters),
66-
RequestContentType = "application/json",
67-
};
6863

69-
await _httpClient.Post(httpRequest).ConfigureAwait(false);
64+
using var response = await _httpClientFactory.CreateClient(NamedClient.Default)
65+
.PostAsJsonAsync(options.WebHookUrl, parameters, _jsonSerializerOptions, cancellationToken)
66+
.ConfigureAwait(false);
7067
}
7168

7269
private bool IsValid(SlackConfiguration options)

build.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
---
22
name: "Slack Notifications"
33
guid: "94fb77c3-55ad-4c50-bf4e-4e5497467b79"
4-
version: "6.0.0.0"
5-
targetAbi: "10.6.0.0"
4+
version: "7.0.0.0"
5+
targetAbi: "10.7.0.0"
6+
framework: "net5.0"
67
overview: "Get notifications via Slack"
78
description: >
89
Get notifications via Slack.

0 commit comments

Comments
 (0)