Skip to content

Commit

Permalink
Update current progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Linwenxuan authored and Linwenxuan committed Oct 8, 2023
1 parent e39c6b4 commit f3777f7
Show file tree
Hide file tree
Showing 14 changed files with 343 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Lagrange.Core/Common/Interface/Api/GroupExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,10 @@ public static Task<uint> FetchGroupFSCount(this BotContext bot, uint groupUin)

public static Task<List<IBotFSEntry>> FetchGroupFSList(this BotContext bot, uint groupUin, string targetDirectory = "/", uint startIndex = 0)
=> bot.ContextCollection.Business.OperationLogic.FetchGroupFSList(groupUin, targetDirectory, startIndex);

public static Task<string> FetchGroupFSDownload(this BotContext bot, uint groupUin, string fileId)
=> bot.ContextCollection.Business.OperationLogic.FetchGroupFSDownload(groupUin, fileId);

public static Task<bool> GroupFSMove(this BotContext bot, uint groupUin, string fileId, string parentDirectory, string targetDirectory)
=> bot.ContextCollection.Business.OperationLogic.GroupFSMove(groupUin, fileId, parentDirectory, targetDirectory);
}
24 changes: 24 additions & 0 deletions Lagrange.Core/Internal/Event/Protocol/Action/GroupFSDeleteEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace Lagrange.Core.Internal.Event.Protocol.Action;

#pragma warning disable CS8618

internal class GroupFSDeleteEvent : GroupFSOperationEvent
{
public string FileId { get; set; }

public string ParentDirectory { get; set; }

public GroupFSDeleteEvent(uint groupUin, string fileId, string parentDirectory) : base(groupUin)
{
FileId = fileId;
ParentDirectory = parentDirectory;
}

public GroupFSDeleteEvent(int resultCode) : base(resultCode) { }

public static GroupFSDeleteEvent Create(uint groupUin, string fileId, string parentDirectory)
=> new(groupUin, fileId, parentDirectory);

public static GroupFSDeleteEvent Result(int resultCode)
=> new(resultCode);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
namespace Lagrange.Core.Internal.Event.Protocol.Action;

internal class GroupFSDownloadEvent : GroupFSOperationEvent
{
public string FileUrl { get; set; }

public string FileId { get; set; }

private GroupFSDownloadEvent(uint groupUin, string fileId) : base(groupUin)
{
FileId = fileId;
FileUrl = "";
}

private GroupFSDownloadEvent(int resultCode, string fileUrl) : base(resultCode)
{
FileUrl = fileUrl;
FileId = "";
}

public static GroupFSDownloadEvent Create(uint groupUin, string fileId) => new(groupUin, fileId);

public static GroupFSDownloadEvent Result(int resultCode, string fileId) => new(resultCode, fileId);
}
27 changes: 27 additions & 0 deletions Lagrange.Core/Internal/Event/Protocol/Action/GroupFSMoveEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace Lagrange.Core.Internal.Event.Protocol.Action;

#pragma warning disable CS8618

internal class GroupFSMoveEvent : GroupFSOperationEvent
{
public string FileId { get; set; }

public string ParentDirectory { get; set; }

public string TargetDirectory { get; set; }

private GroupFSMoveEvent(uint groupUin, string fileId, string parentDirectory, string targetDirectory) : base(groupUin)
{
FileId = fileId;
ParentDirectory = parentDirectory;
TargetDirectory = targetDirectory;
}

private GroupFSMoveEvent(int resultCode) : base(resultCode) { }

public static GroupFSMoveEvent Create(uint groupUin, string fileId, string parentDirectory, string targetDirectory)
=> new(groupUin, fileId, parentDirectory, targetDirectory);

public static GroupFSMoveEvent Result(int resultCode)
=> new(resultCode);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Lagrange.Core.Internal.Event.Protocol.Action;

internal abstract class GroupFSOperationEvent : ProtocolEvent
{
public uint GroupUin { get; set; }

protected GroupFSOperationEvent(uint groupUin) : base(true)
{
GroupUin = groupUin;
}

protected GroupFSOperationEvent(int resultCode) : base(resultCode) { }
}
27 changes: 27 additions & 0 deletions Lagrange.Core/Internal/Event/Protocol/Action/GroupFSRenameEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
namespace Lagrange.Core.Internal.Event.Protocol.Action;

#pragma warning disable CS8618

internal class GroupFSRenameEvent : GroupFSOperationEvent
{
public string FileId { get; set; }

public string ParentDirectory { get; set; }

public string TargetDirectory { get; set; }

private GroupFSRenameEvent(uint groupUin, string fileId, string parentDirectory, string targetDirectory) : base(groupUin)
{
FileId = fileId;
ParentDirectory = parentDirectory;
TargetDirectory = targetDirectory;
}

private GroupFSRenameEvent(int resultCode) : base(resultCode) { }

public static GroupFSRenameEvent Create(uint groupUin, string fileId, string parentDirectory, string targetDirectory)
=> new(groupUin, fileId, parentDirectory, targetDirectory);

public static GroupFSRenameEvent Result(int resultCode)
=> new(resultCode);
}
12 changes: 12 additions & 0 deletions Lagrange.Core/Internal/Event/Protocol/Action/GroupFSUploadEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Lagrange.Core.Internal.Event.Protocol.Action;

internal class GroupFSUploadEvent : GroupFSOperationEvent
{
public GroupFSUploadEvent(uint groupUin) : base(groupUin)
{
}

public GroupFSUploadEvent(int resultCode) : base(resultCode)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Lagrange.Core.Internal.Packets.Service.Oidb.Request;
// ReSharper disable InconsistentNaming

/// <summary>
/// Group File Operation
/// Group File Upload
/// </summary>
[ProtoContract]
[OidbSvcTrpcTcp(0x6d6, 0)]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using ProtoBuf;

namespace Lagrange.Core.Internal.Packets.Service.Oidb.Request;

#pragma warning disable CS8618
// ReSharper disable InconsistentNaming

/// <summary>
/// Group File Download
/// </summary>
[ProtoContract]
[OidbSvcTrpcTcp(0x6d6, 2)]
internal class OidbSvcTrpcTcp0x6D6_2
{
[ProtoMember(3)] public OidbSvcTrpcTcp0x6D6_2Download? Download { get; set; }
}

[ProtoContract]
internal class OidbSvcTrpcTcp0x6D6_2Download
{
[ProtoMember(1)] public uint GroupUin { get; set; }

[ProtoMember(2)] public uint AppId { get; set; } // 7

[ProtoMember(3)] public uint BusId { get; set; } // 102

[ProtoMember(4)] public string FileId { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using ProtoBuf;

namespace Lagrange.Core.Internal.Packets.Service.Oidb.Request;

#pragma warning disable CS8618
// ReSharper disable InconsistentNaming

[ProtoContract]
[OidbSvcTrpcTcp(0x6d6, 5)]
internal class OidbSvcTrpcTcp0x6D6_5
{
[ProtoMember(6)] public OidbSvcTrpcTcp0x6D6_5Move? Move { get; set; }
}

[ProtoContract]
internal class OidbSvcTrpcTcp0x6D6_5Move
{
[ProtoMember(1)] public uint GroupUin { get; set; }

[ProtoMember(2)] public uint AppId { get; set; } // 7

[ProtoMember(3)] public uint BusId { get; set; } // 102

[ProtoMember(4)] public string fileId { get; set; }

[ProtoMember(5)] public string ParentDirectory { get; set; }

[ProtoMember(6)] public string TargetDirectory { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using ProtoBuf;

namespace Lagrange.Core.Internal.Packets.Service.Oidb.Response;

#pragma warning disable CS8618
// ReSharper disable InconsistentNaming

[ProtoContract]
internal class OidbSvcTrpcTco0x6D6Response
{
[ProtoMember(3)] public OidbSvcTrpcTcp0x6D6_2Response Download { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using ProtoBuf;

namespace Lagrange.Core.Internal.Packets.Service.Oidb.Response;

#pragma warning disable CS8618
// ReSharper disable InconsistentNaming

[ProtoContract]
internal class OidbSvcTrpcTcp0x6D6_2Response
{
[ProtoMember(1)] public int RetCode { get; set; }

[ProtoMember(2)] public string RetMsg { get; set; }

[ProtoMember(3)] public string ClientWording { get; set; }

[ProtoMember(4)] public string DownloadIp { get; set; }

[ProtoMember(5)] public string DownloadDns { get; set; }

[ProtoMember(6)] public byte[] DownloadUrl { get; set; }

[ProtoMember(7)] public byte[] FileSha1 { get; set; }

[ProtoMember(8)] public byte[] FileSha3 { get; set; } // ?

[ProtoMember(9)] public byte[] FileMd5 { get; set; }

[ProtoMember(10)] public byte[] CookieVal { get; set; }

[ProtoMember(11)] public string SaveFileName { get; set; }

[ProtoMember(12)] public uint PreviewPort { get; set; }
}
54 changes: 54 additions & 0 deletions Lagrange.Core/Internal/Service/Action/GroupFSDownloadService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Lagrange.Core.Common;
using Lagrange.Core.Internal.Event.Protocol;
using Lagrange.Core.Internal.Event.Protocol.Action;
using Lagrange.Core.Internal.Packets;
using Lagrange.Core.Internal.Packets.Service.Oidb;
using Lagrange.Core.Internal.Packets.Service.Oidb.Request;
using Lagrange.Core.Internal.Packets.Service.Oidb.Response;
using Lagrange.Core.Internal.Service.Abstraction;
using Lagrange.Core.Utility.Extension;
using Lagrange.Core.Utility.Binary;
using ProtoBuf;

namespace Lagrange.Core.Internal.Service.Action;

[EventSubscribe(typeof(GroupFSDownloadEvent))]
[Service("OidbSvcTrpcTcp.0x6d6_2")]
internal class GroupFSDownloadService : BaseService<GroupFSDownloadEvent>
{
protected override bool Build(GroupFSDownloadEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out BinaryPacket output, out List<BinaryPacket>? extraPackets)
{
var packet = new OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0x6D6_2>(new OidbSvcTrpcTcp0x6D6_2
{
Download = new OidbSvcTrpcTcp0x6D6_2Download
{
GroupUin = input.GroupUin,
AppId = 7,
BusId = 102,
FileId = input.FileId
}
}, false, true);

var stream = new MemoryStream();
Serializer.Serialize(stream, packet);
output = new BinaryPacket(stream);

extraPackets = null;
return true;
}

protected override bool Parse(SsoPacket input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out GroupFSDownloadEvent output, out List<ProtocolEvent>? extraEvents)
{
var payload = input.Payload.ReadBytes(BinaryPacket.Prefix.Uint32 | BinaryPacket.Prefix.WithPrefix);
var packet = Serializer.Deserialize<OidbSvcTrpcTcpResponse<OidbSvcTrpcTco0x6D6Response>>(payload.AsSpan());
var download = packet.Body.Download;

string url = $"https://{download.DownloadIp}:443/ftn_handler/{download.DownloadUrl.Hex(true)}/?fname=";

output = GroupFSDownloadEvent.Result((int)packet.ErrorCode, url);
extraEvents = null;
return true;
}
}
52 changes: 52 additions & 0 deletions Lagrange.Core/Internal/Service/Action/GroupFSMoveService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Lagrange.Core.Common;
using Lagrange.Core.Internal.Event.Protocol;
using Lagrange.Core.Internal.Event.Protocol.Action;
using Lagrange.Core.Internal.Packets;
using Lagrange.Core.Internal.Packets.Service.Oidb;
using Lagrange.Core.Internal.Packets.Service.Oidb.Request;
using Lagrange.Core.Internal.Service.Abstraction;
using Lagrange.Core.Utility.Extension;
using Lagrange.Core.Utility.Binary;
using ProtoBuf;

namespace Lagrange.Core.Internal.Service.Action;

[EventSubscribe(typeof(GroupFSMoveEvent))]
[Service("OidbSvcTrpcTcp.0x6d6_5")]
internal class GroupFSMoveService : BaseService<GroupFSMoveEvent>
{
protected override bool Build(GroupFSMoveEvent input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device,
out BinaryPacket output, out List<BinaryPacket>? extraPackets)
{
var packet = new OidbSvcTrpcTcpBase<OidbSvcTrpcTcp0x6D6_5>(new OidbSvcTrpcTcp0x6D6_5
{
Move = new OidbSvcTrpcTcp0x6D6_5Move
{
GroupUin = input.GroupUin,
AppId = 7,
BusId = 102,
fileId = input.FileId,
ParentDirectory = input.ParentDirectory,
TargetDirectory = input.TargetDirectory
}
}, false, true);

var stream = new MemoryStream();
Serializer.Serialize(stream, packet);
output = new BinaryPacket(stream);

extraPackets = null;
return true;
}

protected override bool Parse(SsoPacket input, BotKeystore keystore, BotAppInfo appInfo, BotDeviceInfo device, out GroupFSMoveEvent output,
out List<ProtocolEvent>? extraEvents)
{
var payload = input.Payload.ReadBytes(BinaryPacket.Prefix.Uint32 | BinaryPacket.Prefix.WithPrefix);
var packet = Serializer.Deserialize<OidbSvcTrpcTcpResponse<byte[]>>(payload.AsSpan());

output = GroupFSMoveEvent.Result((int)packet.ErrorCode);
extraEvents = null;
return true;
}
}

0 comments on commit f3777f7

Please sign in to comment.