From 85043ecb9e40495fe3d7a683feca013c7d57eb5f Mon Sep 17 00:00:00 2001 From: mmrbnjd Date: Sun, 10 Aug 2025 21:17:11 +0330 Subject: [PATCH] ... --- Presentation/HushianWebApp/Pages/Chat.razor | 41 ++++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/Presentation/HushianWebApp/Pages/Chat.razor b/Presentation/HushianWebApp/Pages/Chat.razor index df315d6..f08b9b0 100644 --- a/Presentation/HushianWebApp/Pages/Chat.razor +++ b/Presentation/HushianWebApp/Pages/Chat.razor @@ -221,11 +221,26 @@
- @if (msg.FileContent != null && msg.FileContent.Length > 0 && !string.IsNullOrWhiteSpace(msg.FileType) && msg.FileType.StartsWith("image/")) + @if (msg.FileContent != null && msg.FileContent.Length > 0 && !string.IsNullOrWhiteSpace(msg.FileType)) { - - image - + @if (msg.FileType.StartsWith("image/")) + { + + image + + } + else if (msg.FileType.StartsWith("audio/")) + { +
+ +
+ @GetAudioDuration(msg.FileContent) +
+
+ } @if (!string.IsNullOrWhiteSpace(msg.text)) {
@msg.text
@@ -374,7 +389,6 @@ await JS.InvokeVoidAsync("scrollToTarget"); } } - async Task OnclickInbox(int ID) { switch (ID) @@ -508,7 +522,6 @@ => (string.IsNullOrWhiteSpace(fileType) || content == null || content.Length == 0) ? string.Empty : $"data:{fileType};base64,{Convert.ToBase64String(content)}"; - private static string GetDownloadFileName(string? fileName, string? fileType) { if (!string.IsNullOrWhiteSpace(fileName)) return fileName; @@ -519,6 +532,22 @@ } return $"image_{DateTimeOffset.Now.ToUnixTimeSeconds()}{ext}"; } + private string GetAudioDataUrl(string? fileType, byte[]? content) + => (string.IsNullOrWhiteSpace(fileType) || content == null || content.Length == 0) + ? string.Empty + : $"data:{fileType};base64,{Convert.ToBase64String(content)}"; + private string GetAudioDuration(byte[]? content) + { + // Simple duration calculation based on file size (approximate) + if (content == null || content.Length == 0) return "00:00"; + + // Assuming 16-bit PCM at 44.1kHz, mono + var bytesPerSecond = 44100 * 2; // 44.1kHz * 2 bytes per sample + var durationSeconds = content.Length / bytesPerSecond; + var minutes = durationSeconds / 60; + var seconds = durationSeconds % 60; + return $"{minutes:D2}:{seconds:D2}"; + } }