예제 #1
0
        // Token: 0x06000944 RID: 2372 RVA: 0x0004B9A0 File Offset: 0x00049BA0
        public Uri GetDownloadLink(INode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }
            if (node.Type != NodeType.File && node.Type != NodeType.Directory)
            {
                throw new ArgumentException("Invalid node");
            }
            this.EnsureLoggedIn();
            if (node.Type == NodeType.Directory)
            {
                this.Request(new ShareNodeRequest(node, this.masterKey, this.GetNodes()));
                node = this.GetNodes().First((INode x) => x.Equals(node));
            }
            INodeCrypto nodeCrypto = node as INodeCrypto;

            if (nodeCrypto == null)
            {
                throw new ArgumentException("node must implement INodeCrypto");
            }
            GetDownloadLinkRequest request = new GetDownloadLinkRequest(node);
            string arg = this.Request <string>(request, null);

            return(new Uri(MegaApiClient.BaseUri, string.Format("/{0}/{1}#{2}", (node.Type == NodeType.Directory) ? "folder" : "file", arg, (node.Type == NodeType.Directory) ? nodeCrypto.SharedKey.ToBase64() : nodeCrypto.FullKey.ToBase64())));
        }
예제 #2
0
        /// <summary>
        /// Retrieve an url to download specified node
        /// </summary>
        /// <param name="node">Node to retrieve the download link (only <see cref="NodeType.File" /> or <see cref="NodeType.Directory" /> can be downloaded)</param>
        /// <returns>Download link to retrieve the node with associated key</returns>
        /// <exception cref="NotSupportedException">Not logged in</exception>
        /// <exception cref="ApiException">Mega.co.nz service reports an error</exception>
        /// <exception cref="ArgumentNullException">node is null</exception>
        /// <exception cref="ArgumentException">node is not valid (only <see cref="NodeType.File" /> or <see cref="NodeType.Directory" /> can be downloaded)</exception>
        public Uri GetDownloadLink(INode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (node.Type != NodeType.File && node.Type != NodeType.Directory)
            {
                throw new ArgumentException("Invalid node");
            }

            INodeCrypto nodeCrypto = node as INodeCrypto;

            if (nodeCrypto == null)
            {
                throw new ArgumentException("node must implement INodeCrypto");
            }

            this.EnsureLoggedIn();

            GetDownloadLinkRequest request = new GetDownloadLinkRequest(node);
            string response = this.Request <string>(request);

            return(new Uri(BaseUri, string.Format(
                               "/#{0}!{1}!{2}",
                               node.Type == NodeType.Directory ? "F" : string.Empty,
                               response,
                               nodeCrypto.FullKey.ToBase64())));
        }
예제 #3
0
        /// <summary>
        /// Retrieve an url to download specified node
        /// </summary>
        /// <param name="node">Node to retrieve the download link (only <see cref="NodeType.File" /> or <see cref="NodeType.Directory" /> can be downloaded)</param>
        /// <returns>Download link to retrieve the node with associated key</returns>
        /// <exception cref="NotSupportedException">Not logged in</exception>
        /// <exception cref="ApiException">Mega.co.nz service reports an error</exception>
        /// <exception cref="ArgumentNullException">node is null</exception>
        /// <exception cref="ArgumentException">node is not valid (only <see cref="NodeType.File" /> or <see cref="NodeType.Directory" /> can be downloaded)</exception>
        public Uri GetDownloadLink(INode node)
        {
            if (node == null)
            {
                throw new ArgumentNullException("node");
            }

            if (node.Type != NodeType.File && node.Type != NodeType.Directory)
            {
                throw new ArgumentException("Invalid node");
            }

            this.EnsureLoggedIn();

            if (node.Type == NodeType.Directory)
            {
                // Request an export share on the node or we will receive an AccessDenied
                this.Request(new ShareNodeRequest(node, this.masterKey, this.GetNodes()));

                node = this.GetNodes().First(x => x.Equals(node));
            }

            INodeCrypto nodeCrypto = node as INodeCrypto;

            if (nodeCrypto == null)
            {
                throw new ArgumentException("node must implement INodeCrypto");
            }

            GetDownloadLinkRequest request = new GetDownloadLinkRequest(node);
            string response = this.Request <string>(request);

            return(new Uri(BaseUri, string.Format(
                               "/#{0}!{1}!{2}",
                               node.Type == NodeType.Directory ? "F" : string.Empty,
                               response,
                               node.Type == NodeType.Directory ? nodeCrypto.SharedKey.ToBase64() : nodeCrypto.FullKey.ToBase64())));
        }