From 7ac856b5e73a1a7a296438593cda280038c1e2d9 Mon Sep 17 00:00:00 2001 From: Linwenxuan04 Date: Thu, 22 Aug 2024 17:30:09 +0800 Subject: [PATCH] [Core] Fixed Video Uploading Expiration --- Lagrange.Core/Internal/Context/Uploader/Common.cs | 2 +- .../Internal/Context/Uploader/VideoUploader.cs | 4 ++++ .../Service/Message/VideoGroupUploadService.cs | 11 ++++------- .../Internal/Service/Message/VideoUploadService.cs | 11 +++++++---- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/Lagrange.Core/Internal/Context/Uploader/Common.cs b/Lagrange.Core/Internal/Context/Uploader/Common.cs index d096b09d9..8548a2fc4 100644 --- a/Lagrange.Core/Internal/Context/Uploader/Common.cs +++ b/Lagrange.Core/Internal/Context/Uploader/Common.cs @@ -92,7 +92,7 @@ public static List CalculateStreamBytes(Stream inputStream) return byteArrayList; } - public static NTHighwayNetwork Convert(List ipv4s) => new() + private static NTHighwayNetwork Convert(List ipv4s) => new() { IPv4s = ipv4s.Select(x => new NTHighwayIPv4 { diff --git a/Lagrange.Core/Internal/Context/Uploader/VideoUploader.cs b/Lagrange.Core/Internal/Context/Uploader/VideoUploader.cs index 04c4a5604..4ba18985d 100644 --- a/Lagrange.Core/Internal/Context/Uploader/VideoUploader.cs +++ b/Lagrange.Core/Internal/Context/Uploader/VideoUploader.cs @@ -19,6 +19,8 @@ public async Task UploadPrivate(ContextCollection context, MessageChain chain, I if (Common.GenerateExt(metaResult) is { } ext) { + ext.Hash.FileSha1 = Common.CalculateStreamBytes(stream.Value); + var hash = metaResult.MsgInfo.MsgInfoBody[0].Index.Info.FileHash.UnHex(); bool hwSuccess = await context.Highway.UploadSrcByStreamAsync(1001, stream.Value, await Common.GetTicket(context), hash, ext.Serialize().ToArray()); if (!hwSuccess) @@ -57,6 +59,8 @@ public async Task UploadGroup(ContextCollection context, MessageChain chain, IMe if (Common.GenerateExt(metaResult) is { } ext) { + ext.Hash.FileSha1 = Common.CalculateStreamBytes(stream.Value); + var hash = metaResult.MsgInfo.MsgInfoBody[0].Index.Info.FileHash.UnHex(); bool hwSuccess = await context.Highway.UploadSrcByStreamAsync(1005, stream.Value, await Common.GetTicket(context), hash, ext.Serialize().ToArray()); if (!hwSuccess) diff --git a/Lagrange.Core/Internal/Service/Message/VideoGroupUploadService.cs b/Lagrange.Core/Internal/Service/Message/VideoGroupUploadService.cs index e1a6167da..a377e694a 100644 --- a/Lagrange.Core/Internal/Service/Message/VideoGroupUploadService.cs +++ b/Lagrange.Core/Internal/Service/Message/VideoGroupUploadService.cs @@ -15,19 +15,16 @@ namespace Lagrange.Core.Internal.Service.Message; [Service("OidbSvcTrpcTcp.0x11ea_100")] internal class VideoGroupUploadService : BaseService { - private static readonly byte[] DefaultThumbnail = Convert.FromBase64String("/9j/4AAQSkZJRgABAQAAAQABAAD//gAXR2VuZXJhdGVkIGJ5IFNuaXBhc3Rl/9sAhAAKBwcIBwYKCAgICwoKCw4YEA4NDQ4dFRYRGCMfJSQiHyIhJis3LyYpNCkhIjBBMTQ5Oz4+PiUuRElDPEg3PT47AQoLCw4NDhwQEBw7KCIoOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozv/wAARCAF/APADAREAAhEBAxEB/8QBogAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoLEAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+foBAAMBAQEBAQEBAQEAAAAAAAABAgMEBQYHCAkKCxEAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcR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bQAlMAoAKACgAzSAKYhKAENACUxBQIKACgBKACgBaAHCgQ4UALQAUAWqzNAoAKACgApgFACGgQ00xjTQAwigBCKAG4pgJQAlABQAUCCgBKACgBKYgoEFABQISgAoAWgBRQA4UALQAUCLdZmoUAFABQAlMAoASgBDQA00wENACYoATFMBpFADSKAEoEJQAUAFABQAlMQtAgoASgQUAJQAUAKKAHCgBaBBQBbrM1CgAoAKACmAUAJQAlADaYBQAlACYpgIRQA0igBpFAhtABQAUAFMAoEFABQIKAEoASgQUALQAooAWgQUAW81mbC0CCgApgFACUAIaAEpgJQAUAFABQAhFMBpFADSKAGkUCExQAYoAMUAGKADFMQYoAMUCExSATFABQIKYBQAtABQIt5qDYM0ALmgQtIApgIaAENADaACmAlAC0ALQAUwGkUANIoAaRQAmKBBigAxQAYoAMUAGKBBigBMUAJigQmKAExTAKBC0AFAFnNQaig0AKDQAtAgoASgBDQAlMBKACgAFADhQAtMBCKAGkUAIRQAmKADFABigQmKADFACYoAXFABigQmKAExQAmKBCYpgJigAoAnzUGgZoAcDQAuaBC0AJQAhoASmAlABQAtADhQAtMAoATFACEUAJigAxQAYoATFAhMUAFABQAuKADFABigBpWgBCKBCYpgJigB+ag0DNADgaBDgaAFzQITNACUAJTAKACgBRQAopgOoAWgBKAEoAKACgAoASgBpoEJQAooAWgBaBhigBMUCEIoAQigBMUAJSLCgBQaBDgaQC5oEFACUwCgBKACmAtADhQA4UALQAUAJQAUAJQAUAJQAhoENoAWgBRQAooGLQAUAGKAGkUAIRQIZSKEoGKKBDhQAUCCgAoAKBBQAUwFoGKKAHCgBaACgAoASgAoASgBCaAEoEJmgAoAUGgBQaAHZoGFABQAUANoAjpDEoAWgBaAFoEFACUALQAUCCmAUAOFAxRQAtAC0AJQAUAJQAmaBDSaAEzQAmaYBmgBQaAHA0gFzQAuaBhmgAzQAlAEdIYUALQAtAgoAKAEoEFAC0AFMAoAUUDFFAC0ALQAUAJQAhoENNACE0wEoATNABmgBc0ALmgBc0gDNAC5o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KACgBKAEoASgAoASgBaAAUAOoEONIoaTQAZoAUGmIUGgQtAgzQISgAoAQ0DGmgYlAxKACgAxQAtACigBRQAtAxaACgAoATFABigBCKAG0CEoAWgBRTAUUAf//Z"); - protected override bool Build(VideoGroupUploadEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, out Span output, out List>? extraPackets) { - if (input.Entity.VideoStream is null) throw new Exception(); + if (input.Entity.VideoStream is null || input.Entity.ThumbnailStream is null) throw new Exception(); string md5 = input.Entity.VideoStream.Value.Md5(true); string sha1 = input.Entity.VideoStream.Value.Sha1(true); - using var thumb = new MemoryStream(DefaultThumbnail); - string thumbMd5 = thumb.Md5(true); - string thumbSha1 = thumb.Sha1(true); + string thumbMd5 = input.Entity.ThumbnailStream.Value.Md5(true); + string thumbSha1 = input.Entity.ThumbnailStream.Value.Sha1(true); var packet = new OidbSvcTrpcTcpBase(new NTV2RichMediaReq { @@ -77,7 +74,7 @@ protected override bool Build(VideoGroupUploadEvent input, BotKeystore keystore, { FileInfo = new FileInfo // dummy images { - FileSize = (uint)thumb.Length, + FileSize = (uint)input.Entity.ThumbnailStream.Value.Length, FileHash = thumbMd5, FileSha1 = thumbSha1, FileName = "video.jpg", diff --git a/Lagrange.Core/Internal/Service/Message/VideoUploadService.cs b/Lagrange.Core/Internal/Service/Message/VideoUploadService.cs index 0a8d1531c..b827f48d2 100644 --- a/Lagrange.Core/Internal/Service/Message/VideoUploadService.cs +++ b/Lagrange.Core/Internal/Service/Message/VideoUploadService.cs @@ -17,11 +17,14 @@ internal class VideoUploadService : BaseService protected override bool Build(VideoUploadEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, out Span output, out List>? extraPackets) { - if (input.Entity.VideoStream is null) throw new Exception(); + if (input.Entity.VideoStream is null || input.Entity.ThumbnailStream is null) throw new Exception(); string md5 = input.Entity.VideoStream.Value.Md5(true); string sha1 = input.Entity.VideoStream.Value.Sha1(true); + string thumbMd5 = input.Entity.ThumbnailStream.Value.Md5(true); + string thumbSha1 = input.Entity.ThumbnailStream.Value.Sha1(true); + var packet = new OidbSvcTrpcTcpBase(new NTV2RichMediaReq { ReqHead = new MultiMediaReqHead @@ -74,9 +77,9 @@ protected override bool Build(VideoUploadEvent input, BotKeystore keystore, BotA { FileInfo = new FileInfo // dummy images { - FileSize = (uint)input.Entity.VideoStream.Value.Length - 1200, - FileHash = md5, - FileSha1 = sha1, + FileSize = (uint)input.Entity.ThumbnailStream.Value.Length, + FileHash = thumbMd5, + FileSha1 = thumbSha1, FileName = "video.jpg", Type = new FileType {