Skip to content

Commit

Permalink
[Core] Fixed Video Uploading Expiration
Browse files Browse the repository at this point in the history
  • Loading branch information
Linwenxuan04 committed Aug 22, 2024
1 parent 71c93df commit 7ac856b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Lagrange.Core/Internal/Context/Uploader/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public static List<byte[]> CalculateStreamBytes(Stream inputStream)
return byteArrayList;
}

public static NTHighwayNetwork Convert(List<IPv4> ipv4s) => new()
private static NTHighwayNetwork Convert(List<IPv4> ipv4s) => new()
{
IPv4s = ipv4s.Select(x => new NTHighwayIPv4
{
Expand Down
4 changes: 4 additions & 0 deletions Lagrange.Core/Internal/Context/Uploader/VideoUploader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,16 @@ namespace Lagrange.Core.Internal.Service.Message;
[Service("OidbSvcTrpcTcp.0x11ea_100")]
internal class VideoGroupUploadService : BaseService<VideoGroupUpload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QAUAJQAlABQISgAoAKACgBaACgBKAEoAnqTQSgBRQIcKBC0xCUAJQISgBKAENADDQAmaYwzQAuaADNAC0AFABQAUAFAhKACgBKACgAoAWgAoELQAlAxKAJqk0EoAWgQooELTEFADaBCUABoENNMY00ANNAwzQAZoAXNAC0AFAC0CFoASgAoASgBKACgAoAWgQtABQAUANNAyWpNAoAKBCimIWgQUCEoASmIQ0ANNADTQMaaAEoGLmgAzQAtADhQIWgBaACgQhoASgYlACUALQIWgBaACgBKAENAyWpNBKYBQIcKBC0CEoEJTAKBCUANNADDQMQ0ANoGFAC5oAUGgBwNAhRQIWgBaAENACGgBtAwoAKAFzQIXNABmgAoAQ0DJKRoJQAtAhRQSLQIKYCUCCgBDQA00AMNAxpoGNoAM0AGaAFBoAcDQIcKBDqACgBDQAhoAQ0DEoAKADNAC5oEGaBhmgAoAkpGgUCCgQooELQIKYhKACgBKAGmgBpoGMNAxDQAlAwzQIUUAOFAhwoAcKBC0AJQAhoGNNACUAFABQAZoAXNABQAUAS0ixKACgQoNAhaYgoEFACUABoAaaAGmgYw0DENAxtABQAooEOFADhQIcKAFoASgBDQAhoGJQAUAFACUALQIKBi0CJDSLEoATNAhc0CHZpiCgQUAJQIKBjTQAhoGNNAxpoATFABigBQKAHCgBwoAWgAoAKACgBKAEoASgAoASgBaAAUAOoEONIoaTQAZoAUGmIUGgQtAgzQISgAoAQ0DGmgYlAxKACgAxQAtACigBRQAtAxaACgAoATFABigBCKAG0CEoAWgBRTAUUAf//Z");

protected override bool Build(VideoGroupUploadEvent input, BotKeystore keystore, BotAppInfo appInfo,
BotDeviceInfo device, out Span<byte> output, out List<Memory<byte>>? 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<NTV2RichMediaReq>(new NTV2RichMediaReq
{
Expand Down Expand Up @@ -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",
Expand Down
11 changes: 7 additions & 4 deletions Lagrange.Core/Internal/Service/Message/VideoUploadService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ internal class VideoUploadService : BaseService<VideoUploadEvent>
protected override bool Build(VideoUploadEvent input, BotKeystore keystore, BotAppInfo appInfo,
BotDeviceInfo device, out Span<byte> output, out List<Memory<byte>>? 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<NTV2RichMediaReq>(new NTV2RichMediaReq
{
ReqHead = new MultiMediaReqHead
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit 7ac856b

Please sign in to comment.