fix: Bilder und dumme min TImings!

This commit is contained in:
2026-03-01 18:19:37 +01:00
parent 25fb75ae0b
commit 6c485aa0f7
5 changed files with 55 additions and 25 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
@@ -69,14 +70,11 @@ public class DiscordNotificationService
var title = $"📺 {seriesName}";
var description = $"Neue Episoden hinzugefügt:\n{episodeDescription}";
// Get image from first notification
var imageUrl = first.ImageUrl;
await SendDiscordWebhookAsync(
config,
title,
description,
imageUrl,
first.ImagePath,
BuildExternalLinks(first.ProviderIdsJson),
cancellationToken);
}
@@ -182,7 +180,7 @@ public class DiscordNotificationService
config,
title,
description,
notification.ImageUrl,
notification.ImagePath,
BuildExternalLinks(notification.ProviderIdsJson),
cancellationToken);
}
@@ -236,13 +234,13 @@ public class DiscordNotificationService
}
/// <summary>
/// Sends the actual Discord webhook request.
/// Sends the actual Discord webhook request, with optional image attachment.
/// </summary>
private async Task SendDiscordWebhookAsync(
PluginConfiguration config,
string title,
string description,
string? imageUrl,
string? imagePath,
string externalLinks,
CancellationToken cancellationToken)
{
@@ -253,9 +251,11 @@ public class DiscordNotificationService
["color"] = config.EmbedColor
};
if (!string.IsNullOrEmpty(imageUrl))
// If we have a local image file, reference it as attachment
var hasImage = !string.IsNullOrEmpty(imagePath) && File.Exists(imagePath);
if (hasImage)
{
embed["thumbnail"] = new Dictionary<string, string> { ["url"] = imageUrl };
embed["thumbnail"] = new Dictionary<string, string> { ["url"] = "attachment://poster.jpg" };
}
if (!string.IsNullOrEmpty(externalLinks))
@@ -277,9 +277,27 @@ public class DiscordNotificationService
try
{
using var client = _httpClientFactory.CreateClient();
using var content = new StringContent(json, Encoding.UTF8, "application/json");
HttpResponseMessage response;
var response = await client.PostAsync(config.DiscordWebhookUrl, content, cancellationToken);
if (hasImage)
{
// Send as multipart/form-data with image attachment
using var form = new MultipartFormDataContent();
form.Add(new StringContent(json, Encoding.UTF8, "application/json"), "payload_json");
var imageBytes = await File.ReadAllBytesAsync(imagePath!, cancellationToken);
var imageContent = new ByteArrayContent(imageBytes);
imageContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("image/jpeg");
form.Add(imageContent, "files[0]", "poster.jpg");
response = await client.PostAsync(config.DiscordWebhookUrl, form, cancellationToken);
}
else
{
// Send as plain JSON (no image)
using var content = new StringContent(json, Encoding.UTF8, "application/json");
response = await client.PostAsync(config.DiscordWebhookUrl, content, cancellationToken);
}
if (!response.IsSuccessStatusCode)
{