Improved presentation slide streaming

This commit is contained in:
Thorsten Sommer 2025-06-30 20:35:00 +02:00
parent f7c3011678
commit 77d3e80765
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
2 changed files with 14 additions and 9 deletions

View File

@ -8,7 +8,7 @@ public static class ContentStreamSseHandler
private static readonly ConcurrentDictionary<string, List<ContentStreamPptxImageData>> CHUNKED_IMAGES = new();
private static readonly ConcurrentDictionary<string, int> CURRENT_SLIDE_NUMBERS = new();
public static string ProcessEvent(ContentStreamSseEvent? sseEvent, bool extractImages = true)
public static string? ProcessEvent(ContentStreamSseEvent? sseEvent, bool extractImages = true)
{
switch (sseEvent)
{
@ -41,15 +41,18 @@ public static class ContentStreamSseHandler
var image = presentationMetadata.Presentation?.Image ?? null;
var presentationResult = new StringBuilder();
var streamId = sseEvent.StreamId;
CURRENT_SLIDE_NUMBERS.TryGetValue(streamId!, out var currentSlideNumber);
if (slideNumber != currentSlideNumber)
{
presentationResult.AppendLine();
presentationResult.AppendLine($"# Slide {slideNumber}");
}
presentationResult.Append($"{sseEvent.Content}");
if (image is not null)
if(!string.IsNullOrWhiteSpace(sseEvent.Content))
presentationResult.AppendLine(sseEvent.Content);
if (extractImages && image is not null)
{
var imageId = $"{streamId}-{image.Id!}";
var isEnd = ProcessImageSegment(imageId, image);
@ -58,8 +61,8 @@ public static class ContentStreamSseHandler
}
CURRENT_SLIDE_NUMBERS[streamId!] = slideNumber;
return presentationResult.ToString();
return presentationResult.Length is 0 ? null : presentationResult.ToString();
default:
return sseEvent.Content;
}

View File

@ -37,7 +37,9 @@ public sealed partial class RustService
if (sseEvent is not null)
{
var content = ContentStreamSseHandler.ProcessEvent(sseEvent, false);
resultBuilder.Append(content);
if(content is not null)
resultBuilder.AppendLine(content);
chunkCount++;
}
}