- @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))
{
-
-
-
+ @if (msg.FileType.StartsWith("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}";
+ }
}