Единственная оболочка, которая в настоящее время существует для C#, - это https://github.com/gpailler/MegaApiClient/tree/master/MegaApiClient
Однако в ней отсутствует функция импорта папки в текущую зарегистрированную учетную запись. Как бы вы сделали что-то подобное? Я попытался сделать реализацию самостоятельно на основе python оболочки , но безрезультатно.
Ниже приведен код, который я написал, стараясь изо всех сил написать его на основе C# на языке выше. Но это не работает. Я получаю AccessDenied
ответов
public INode Import(Uri uri, INode destinationParentNode)
{
if (uri == null)
{
throw new ArgumentNullException(nameof(uri));
}
if (destinationParentNode == null)
{
throw new ArgumentNullException(nameof(destinationParentNode));
}
this.EnsureLoggedIn();
string shareId;
byte[] iv, metaMac, key;
this.GetPartsFromUri(uri, out shareId, out iv, out metaMac, out key);
if (destinationParentNode.Type == NodeType.File)
{
throw new ArgumentException("Invalid destination parent node");
}
var node = GetNodeFromLink(uri);
var publicNode = (PublicNode)node;
byte[] cryptedAttributes = Crypto.EncryptAttributes(new Attributes(publicNode.Name), key);
byte[] encryptedKey = Crypto.EncryptKey(key, this.masterKey);
var importData = new ImportData(shareId, NodeType.File, cryptedAttributes, encryptedKey);
this.Request(new ImportNodeRequest(importData, destinationParentNode));
return this.GetNodes().First(n => n.Equals(node));
}
namespace CG.Web.MegaApiClient.Serialization
{
using System.Collections.Generic;
using Newtonsoft.Json;
internal class ImportData
{
private readonly IList<ImportDataItem> items;
public ImportData(string nodeId, NodeType v, byte[] cryptedAttributes, byte[] encryptedKey)
{
NodeId = nodeId;
items = new List<ImportDataItem>();
AddItem(nodeId, v, cryptedAttributes, encryptedKey);
}
public string NodeId { get; }
public IEnumerable<ImportDataItem> Items => items;
public void AddItem(string fileHandle, NodeType type, byte[] name, byte[] key)
{
var item = new ImportDataItem
{
FileHandle = fileHandle,
NodeType = type,
Attributes = name.ToBase64(),
Key = key.ToBase64()
};
items.Add(item);
}
public class ImportDataItem
{
[JsonProperty("ph")] public string FileHandle { get; set; }
[JsonProperty("t")] public NodeType NodeType { get; set; }
[JsonProperty("a")] public string Attributes { get; set; }
[JsonProperty("k")] public string Key { get; set; }
}
}
}
namespace CG.Web.MegaApiClient.Serialization
{
using Newtonsoft.Json;
internal class ImportNodeRequest : RequestBase
{
public ImportNodeRequest(ImportData importData, INode destinationParentNode) : base("p")
{
this.Import = importData;
this.DestinationParentId = destinationParentNode.Id;
}
[JsonProperty("t")] public string DestinationParentId { get; private set; }
[JsonProperty("n")] public ImportData Import { get; private set; }
}
}