Skip to content

Commit

Permalink
[Core] ImageEntity add image md5 (#553)
Browse files Browse the repository at this point in the history
* [Core] ImageEntity add image hash

* rename to md5

* Use byte[] instead of string
  • Loading branch information
DarkRRb authored Aug 30, 2024
1 parent 33c1cc3 commit 2e1f19c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Lagrange.Core/Message/Entity/ImageEntity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class ImageEntity : IMessageEntity

public string FilePath { get; set; } = string.Empty;

public byte[] ImageMd5 { get; set; } = Array.Empty<byte>();

public uint ImageSize { get; set; }

public string ImageUrl { get; set; } = string.Empty;
Expand Down Expand Up @@ -55,7 +57,7 @@ public ImageEntity(byte[] file)
FilePath = "";
ImageStream = new Lazy<Stream>(() => new MemoryStream(file));
}

public ImageEntity(Stream stream)
{
FilePath = "";
Expand Down Expand Up @@ -97,12 +99,13 @@ IEnumerable<Elem> 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
Expand All @@ -111,18 +114,19 @@ IEnumerable<Elem> 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,
Expand Down Expand Up @@ -159,7 +163,7 @@ IEnumerable<Elem> IMessageEntity.PackElement()

return null;
}

private static int GetImageTypeFromFaceOldData(CustomFace face)
{
if (face.OldData == null || face.OldData.Length < 5)
Expand Down

0 comments on commit 2e1f19c

Please sign in to comment.