From 59de1615ea67672ee4d8f77c7d706279271cb266 Mon Sep 17 00:00:00 2001 From: ishkong <19740260+ishkong@users.noreply.github.com> Date: Fri, 6 Dec 2024 23:51:55 +0800 Subject: [PATCH 1/2] [OneBot] impl FileSegment Signed-off-by: ishkong <19740260+ishkong@users.noreply.github.com> --- Lagrange.OneBot/Message/Entity/FileSegment.cs | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 Lagrange.OneBot/Message/Entity/FileSegment.cs diff --git a/Lagrange.OneBot/Message/Entity/FileSegment.cs b/Lagrange.OneBot/Message/Entity/FileSegment.cs new file mode 100644 index 000000000..b56ad87a1 --- /dev/null +++ b/Lagrange.OneBot/Message/Entity/FileSegment.cs @@ -0,0 +1,45 @@ +using System.Text.Json.Serialization; +using Lagrange.Core.Message; +using Lagrange.Core.Message.Entity; + +namespace Lagrange.OneBot.Message.Entity; + +[Serializable] +public partial class FileSegment(string fileName, string fileHash, string fileId, string url) +{ + public FileSegment() : this("", "", "", "") { } + + [JsonPropertyName("filename")] public string Filename { get; set; } = fileName; + + [JsonPropertyName("filehash")] public string Filehash { get; set; } = fileHash; + + [JsonPropertyName("id")] public string Fileid { get; set; } = fileId; + + [JsonPropertyName("url")] public string Url { get; set; } = url; + +} + +[SegmentSubscriber(typeof(FileEntity), "file")] +public partial class FileSegment : SegmentBase +{ + public override void Build(MessageBuilder builder, SegmentBase segment) + { + if (segment is FileSegment fileSegment and not { Fileid: "" }) + { + builder.Add(new FileEntity + { + FileName = fileSegment.Filename, + FileUrl = fileSegment.Url, + FileId = fileSegment.Fileid, + FileHash = fileSegment.Filehash + }); + } + } + + public override SegmentBase FromEntity(MessageChain chain, IMessageEntity entity) + { + if (entity is not FileEntity fileEntity) throw new ArgumentException("Invalid entity type."); + + return new FileSegment(fileEntity.FileName, fileEntity.FileHash ?? "", fileEntity.FileId ?? fileEntity.FileUuid ?? "", fileEntity.FileUrl ?? ""); + } +} \ No newline at end of file From 1dcd3b75504654e06268e0e98c1bfe0ae1f9a85b Mon Sep 17 00:00:00 2001 From: ishkong <19740260+ishkong@users.noreply.github.com> Date: Sat, 7 Dec 2024 00:21:15 +0800 Subject: [PATCH 2/2] [Core] Save key information needed to refresh private chat file links Signed-off-by: ishkong <19740260+ishkong@users.noreply.github.com> --- Lagrange.Core/Message/Entity/FileEntity.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lagrange.Core/Message/Entity/FileEntity.cs b/Lagrange.Core/Message/Entity/FileEntity.cs index acad46b2c..c7b8b662c 100644 --- a/Lagrange.Core/Message/Entity/FileEntity.cs +++ b/Lagrange.Core/Message/Entity/FileEntity.cs @@ -24,9 +24,9 @@ public class FileEntity : IMessageEntity /// public string? FileId { get; set; } - internal string? FileUuid { get; set; } + public string? FileUuid { get; set; } - internal string? FileHash { get; set; } + public string? FileHash { get; set; } internal Stream? FileStream { get; set; }