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

View File

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