From 2e1f19c1cc2293b5a40c6300d55bb857ff920d32 Mon Sep 17 00:00:00 2001 From: CwkDark <177549718+CwkDark@users.noreply.github.com> Date: Sat, 31 Aug 2024 06:07:42 +0800 Subject: [PATCH] [Core] ImageEntity add image md5 (#553) * [Core] ImageEntity add image hash * rename to md5 * Use byte[] instead of string --- Lagrange.Core/Message/Entity/ImageEntity.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Lagrange.Core/Message/Entity/ImageEntity.cs b/Lagrange.Core/Message/Entity/ImageEntity.cs index 350217e34..bf0c7ab4e 100644 --- a/Lagrange.Core/Message/Entity/ImageEntity.cs +++ b/Lagrange.Core/Message/Entity/ImageEntity.cs @@ -22,6 +22,8 @@ public class ImageEntity : IMessageEntity public string FilePath { get; set; } = string.Empty; + public byte[] ImageMd5 { get; set; } = Array.Empty(); + public uint ImageSize { get; set; } public string ImageUrl { get; set; } = string.Empty; @@ -55,7 +57,7 @@ public ImageEntity(byte[] file) FilePath = ""; ImageStream = new Lazy(() => new MemoryStream(file)); } - + public ImageEntity(Stream stream) { FilePath = ""; @@ -97,12 +99,13 @@ IEnumerable IMessageEntity.PackElement() { PictureSize = new Vector2(index.Info.Width, index.Info.Height), FilePath = index.Info.FileName, + ImageMd5 = index.Info.FileHash.UnHex(), ImageSize = index.Info.FileSize, MsgInfo = extra, SubType = (int)extra.ExtBizInfo.Pic.BizType, }; } - + if (elems.NotOnlineImage is { } image) { if (image.OrigUrl.Contains("&fileid=")) // NTQQ's shit @@ -111,18 +114,19 @@ IEnumerable IMessageEntity.PackElement() { PictureSize = new Vector2(image.PicWidth, image.PicHeight), FilePath = image.FilePath, + ImageMd5 = image.PicMd5, ImageSize = image.FileLen, ImageUrl = $"{BaseUrl}{image.OrigUrl}", Summary = image.PbRes.Summary, SubType = image.PbRes.SubType }; - } return new ImageEntity { PictureSize = new Vector2(image.PicWidth, image.PicHeight), FilePath = image.FilePath, + ImageMd5 = image.PicMd5, ImageSize = image.FileLen, ImageUrl = $"{LegacyBaseUrl}{image.OrigUrl}", Summary = image.PbRes.Summary, @@ -159,7 +163,7 @@ IEnumerable IMessageEntity.PackElement() return null; } - + private static int GetImageTypeFromFaceOldData(CustomFace face) { if (face.OldData == null || face.OldData.Length < 5)