add chat file download
This commit is contained in:
parent
0657b16e91
commit
51bca39dd6
|
|
@ -3,7 +3,7 @@ namespace BotSharp.Abstraction.Files.Models;
|
|||
public class FileInformation
|
||||
{
|
||||
/// <summary>
|
||||
/// External file url
|
||||
/// External file url for display
|
||||
/// </summary>
|
||||
[JsonPropertyName("file_url")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
|
|
@ -35,4 +35,11 @@ public class FileInformation
|
|||
[JsonPropertyName("file_extension")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public string? FileExtension { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// External file url for download
|
||||
/// </summary>
|
||||
[JsonPropertyName("file_download_url")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public string? FileDownloadUrl { get; set; } = string.Empty;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ public partial class AgentService
|
|||
{
|
||||
UserId = user.Id,
|
||||
AgentId = agentRecord.Id,
|
||||
Actions = new List<string> { UserAction.Edit },
|
||||
Actions = new List<string> { UserAction.Edit, UserAction.Chat },
|
||||
CreatedTime = DateTime.UtcNow,
|
||||
UpdatedTime = DateTime.UtcNow
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,6 +69,7 @@ public partial class LocalFileStorageService
|
|||
{
|
||||
MessageId = messageId,
|
||||
FileUrl = $"/conversation/{conversationId}/message/{messageId}/{source}/file/{index}/{fileName}",
|
||||
FileDownloadUrl = $"/conversation/{conversationId}/message/{messageId}/{source}/file/{index}/{fileName}/download",
|
||||
FileStorageUrl = file,
|
||||
FileName = fileName,
|
||||
FileExtension = fileExtension,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
using Azure;
|
||||
using BotSharp.Abstraction.Files.Constants;
|
||||
using BotSharp.Abstraction.Files.Enums;
|
||||
using BotSharp.Abstraction.Files.Utilities;
|
||||
using BotSharp.Abstraction.Options;
|
||||
using BotSharp.Abstraction.Routing;
|
||||
using BotSharp.Abstraction.Users.Enums;
|
||||
|
|
@ -488,6 +489,26 @@ public class ConversationController : ControllerBase
|
|||
}
|
||||
return BuildFileResult(file);
|
||||
}
|
||||
|
||||
[HttpGet("/conversation/{conversationId}/message/{messageId}/{source}/file/{index}/{fileName}/download")]
|
||||
public IActionResult DownloadMessageFile([FromRoute] string conversationId, [FromRoute] string messageId, [FromRoute] string source, [FromRoute] string index, [FromRoute] string fileName)
|
||||
{
|
||||
var fileStorage = _services.GetRequiredService<IFileStorageService>();
|
||||
var file = fileStorage.GetMessageFile(conversationId, messageId, source, index, fileName);
|
||||
if (string.IsNullOrEmpty(file))
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
var fName = file.Split(Path.DirectorySeparatorChar).Last();
|
||||
var contentType = FileUtility.GetFileContentType(fName);
|
||||
var stream = System.IO.File.Open(file, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
var bytes = new byte[stream.Length];
|
||||
stream.Read(bytes, 0, (int)stream.Length);
|
||||
stream.Position = 0;
|
||||
|
||||
return new FileStreamResult(stream, contentType) { FileDownloadName = fName };
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Private methods
|
||||
|
|
|
|||
|
|
@ -19,6 +19,10 @@ public class MessageFileViewModel
|
|||
[JsonPropertyName("file_source")]
|
||||
public string FileSource { get; set; }
|
||||
|
||||
[JsonPropertyName("file_download_url")]
|
||||
[JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)]
|
||||
public string? FileDownloadUrl { get; set; }
|
||||
|
||||
public MessageFileViewModel()
|
||||
{
|
||||
|
||||
|
|
@ -32,7 +36,8 @@ public class MessageFileViewModel
|
|||
FileName = model.FileName,
|
||||
FileExtension = model.FileExtension,
|
||||
ContentType = model.ContentType,
|
||||
FileSource = model.FileSource
|
||||
FileSource = model.FileSource,
|
||||
FileDownloadUrl = model.FileDownloadUrl
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ public class WebSocketsMiddleware
|
|||
var regexes = new List<Regex>
|
||||
{
|
||||
new Regex(@"/conversation/(.*?)/message/(.*?)/(.*?)/file/(.*?)/(.*?)", RegexOptions.IgnoreCase),
|
||||
new Regex(@"/conversation/(.*?)/message/(.*?)/(.*?)/file/(.*?)/(.*?)/download", RegexOptions.IgnoreCase),
|
||||
new Regex(@"/user/avatar", RegexOptions.IgnoreCase),
|
||||
new Regex(@"/knowledge/document/(.*?)/file/(.*?)", RegexOptions.IgnoreCase)
|
||||
};
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ public partial class TencentCosService
|
|||
{
|
||||
MessageId = messageId,
|
||||
FileUrl = BuilFileUrl(file),
|
||||
FileDownloadUrl = BuilFileUrl(file),
|
||||
FileStorageUrl = file,
|
||||
FileName = fileName,
|
||||
FileExtension = fileExtension,
|
||||
|
|
|
|||
Loading…
Reference in a new issue