From 71783bf3465c459d9b279c05e9bb4c583ea7cd69 Mon Sep 17 00:00:00 2001 From: mmrbnjd Date: Sat, 9 Aug 2025 19:06:36 +0330 Subject: [PATCH] ... --- Presentation/HushianWebApp/Pages/Chat.razor | 33 ++++++++++++++++++- .../Pages/FromUserSide/UserCP.razor | 20 ++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/Presentation/HushianWebApp/Pages/Chat.razor b/Presentation/HushianWebApp/Pages/Chat.razor index fc30509..df315d6 100644 --- a/Presentation/HushianWebApp/Pages/Chat.razor +++ b/Presentation/HushianWebApp/Pages/Chat.razor @@ -219,7 +219,23 @@ }
-
@msg.text
+ +
+ @if (msg.FileContent != null && msg.FileContent.Length > 0 && !string.IsNullOrWhiteSpace(msg.FileType) && msg.FileType.StartsWith("image/")) + { + + image + + @if (!string.IsNullOrWhiteSpace(msg.text)) + { +
@msg.text
+ } + } + else + { + @msg.text + } +
@if (msg.Type != Common.Enums.ConversationType.UE) { if (msg.IsRead) @@ -487,6 +503,21 @@ + } + private static string GetImageDataUrl(string? fileType, byte[]? content) + => (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; + var ext = ""; + if (!string.IsNullOrWhiteSpace(fileType) && fileType.StartsWith("image/")) + { + ext = "." + fileType.Split('/').Last(); + } + return $"image_{DateTimeOffset.Now.ToUnixTimeSeconds()}{ext}"; } } diff --git a/Presentation/HushianWebApp/Pages/FromUserSide/UserCP.razor b/Presentation/HushianWebApp/Pages/FromUserSide/UserCP.razor index f45ebba..18da21e 100644 --- a/Presentation/HushianWebApp/Pages/FromUserSide/UserCP.razor +++ b/Presentation/HushianWebApp/Pages/FromUserSide/UserCP.razor @@ -79,7 +79,9 @@
@if (msg.FileContent != null && msg.FileContent.Length > 0 && !string.IsNullOrWhiteSpace(msg.FileType) && msg.FileType.StartsWith("image/")) { - image + + image + @if (!string.IsNullOrWhiteSpace(msg.text)) {
@msg.text
@@ -507,6 +509,22 @@ SelectedImagePreview = null; return Task.CompletedTask; } + + private static string GetImageDataUrl(string? fileType, byte[]? content) + => (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; + var ext = ""; + if (!string.IsNullOrWhiteSpace(fileType) && fileType.StartsWith("image/")) + { + ext = "." + fileType.Split('/').Last(); + } + return $"image_{DateTimeOffset.Now.ToUnixTimeSeconds()}{ext}"; + } }