From 7df9aa7b479e61363038f55dd8e53314583daeb4 Mon Sep 17 00:00:00 2001 From: linyuchen Date: Tue, 19 May 2026 19:04:55 +0800 Subject: [PATCH] fix(video): make highway upload work Three issues prevent video upload from working end-to-end: - BuildFileInfo for VideoEntity dereferences info.Type which is never initialized. Replace info.Type.Type = 2 with info.Type = new FileType { Type = 2 }. - Group / C2C highway command IDs are swapped: group video uses 1005/1006 and C2C uses 1001/1002, not the other way around. With the wrong cmd the server acks all blocks but archives to the wrong storage bucket, so the recipient cannot resolve the file URL. - Thumbnail upload was missing the sha1 recomputation that the main video has. GenerateExt fills hash.FileSha1 from main video's index, Preprocess overwrites it with CalculateStreamBytes for main but not for thumb, so the thumb upload sends bytes paired with the wrong sha1 list. Server accepts the bytes but the thumb stays unbound to the message and the recipient sees no cover. --- .../Internal/Packets/Service/NTV2RichMedia.cs | 2 +- Lagrange.Core/Message/Entities/VideoEntity.cs | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Lagrange.Core/Internal/Packets/Service/NTV2RichMedia.cs b/Lagrange.Core/Internal/Packets/Service/NTV2RichMedia.cs index d5fc857b..b8fb5a35 100644 --- a/Lagrange.Core/Internal/Packets/Service/NTV2RichMedia.cs +++ b/Lagrange.Core/Internal/Packets/Service/NTV2RichMedia.cs @@ -158,7 +158,7 @@ private static FileInfo BuildFileInfo(RichMediaEntityBase entity) } case VideoEntity: { - info.Type.Type = 2; // unable to determine video type, skip + info.Type = new FileType { Type = 2 }; info.FileName = $"{md5}.mp4"; // default to mp4 break; } diff --git a/Lagrange.Core/Message/Entities/VideoEntity.cs b/Lagrange.Core/Message/Entities/VideoEntity.cs index c37173f0..4e087295 100644 --- a/Lagrange.Core/Message/Entities/VideoEntity.cs +++ b/Lagrange.Core/Message/Entities/VideoEntity.cs @@ -51,12 +51,13 @@ public override async Task Preprocess(BotContext context, BotMessage message) if (result.Ext != null) { result.Ext.Hash.FileSha1 = CalculateStreamBytes(Stream.Value); - await context.HighwayContext.UploadFile(Stream.Value, 1001, ProtoHelper.Serialize(result.Ext)); + await context.HighwayContext.UploadFile(Stream.Value, 1005, ProtoHelper.Serialize(result.Ext)); } if (result.SubExt != null) { - await context.HighwayContext.UploadFile(ThumbnailStream.Value, 1002, ProtoHelper.Serialize(result.SubExt)); + result.SubExt.Hash.FileSha1 = CalculateStreamBytes(ThumbnailStream.Value); + await context.HighwayContext.UploadFile(ThumbnailStream.Value, 1006, ProtoHelper.Serialize(result.SubExt)); } } else @@ -68,12 +69,13 @@ public override async Task Preprocess(BotContext context, BotMessage message) if (result.Ext != null) { result.Ext.Hash.FileSha1 = CalculateStreamBytes(Stream.Value); - await context.HighwayContext.UploadFile(Stream.Value, 1005, ProtoHelper.Serialize(result.Ext)); + await context.HighwayContext.UploadFile(Stream.Value, 1001, ProtoHelper.Serialize(result.Ext)); } if (result.SubExt != null) { - await context.HighwayContext.UploadFile(ThumbnailStream.Value, 1006, ProtoHelper.Serialize(result.SubExt)); + result.SubExt.Hash.FileSha1 = CalculateStreamBytes(ThumbnailStream.Value); + await context.HighwayContext.UploadFile(ThumbnailStream.Value, 1002, ProtoHelper.Serialize(result.SubExt)); } } }