This commit is contained in:
mmrbnjd
2025-08-09 19:06:36 +03:30
parent 8d69dbc946
commit 71783bf346
2 changed files with 51 additions and 2 deletions

View File

@@ -219,7 +219,23 @@
}
<div class="d-flex mb-2 @(msg.Type==Common.Enums.ConversationType.UE ? "justify-content-end" : "justify-content-start")">
<div class="chat-bubble @(msg.Type==Common.Enums.ConversationType.UE ? "chat-mine": "chat-other")" data-id="@msg.ID"> @msg.text </div>
<div class="chat-bubble @(msg.Type==Common.Enums.ConversationType.UE ? "chat-mine": "chat-other")" data-id="@msg.ID">
@if (msg.FileContent != null && msg.FileContent.Length > 0 && !string.IsNullOrWhiteSpace(msg.FileType) && msg.FileType.StartsWith("image/"))
{
<a href="@GetImageDataUrl(msg.FileType, msg.FileContent)" download="@GetDownloadFileName(msg.FileName, msg.FileType)" title="دانلود تصویر" style="display:inline-block">
<img src="@GetImageDataUrl(msg.FileType, msg.FileContent)" alt="image" style="max-width: 220px; border-radius: 8px; display: block; cursor: pointer;" />
</a>
@if (!string.IsNullOrWhiteSpace(msg.text))
{
<div style="margin-top:6px">@msg.text</div>
}
}
else
{
@msg.text
}
</div>
@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}";
}
}

View File

@@ -79,7 +79,9 @@
<div class="chat-bubble @(msg.Type!=Common.Enums.ConversationType.UE ? "chat-mine": "chat-other")" data-id="@msg.ID">
@if (msg.FileContent != null && msg.FileContent.Length > 0 && !string.IsNullOrWhiteSpace(msg.FileType) && msg.FileType.StartsWith("image/"))
{
<img src="@($"data:{msg.FileType};base64,{Convert.ToBase64String(msg.FileContent)}")" alt="image" style="max-width: 220px; border-radius: 8px; display: block;" />
<a href="@GetImageDataUrl(msg.FileType, msg.FileContent)" download="@GetDownloadFileName(msg.FileName, msg.FileType)" title="دانلود تصویر" style="display:inline-block">
<img src="@GetImageDataUrl(msg.FileType, msg.FileContent)" alt="image" style="max-width: 220px; border-radius: 8px; display: block; cursor: pointer;" />
</a>
@if (!string.IsNullOrWhiteSpace(msg.text))
{
<div style="margin-top:6px">@msg.text</div>
@@ -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}";
}
}
<style>
.chat-bubble {