Ejemplo n.º 1
0
        public async Task <string> CompressAsync(long SaveIntoFolderID, string Filename = null)
        {
            var parameters = new AuthDictionary();

            parameters.Add("fileid", FileID.ToString());
            parameters.Add("tofolderid", SaveIntoFolderID.ToString());
            parameters.Add("toname", Filename);
            var GeneJobID = RandomString(8);

            parameters.Add("progresshash", GeneJobID);

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/savezip"));
                HtpReqMessage.Content = new FormUrlEncodedContent(parameters);
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0))
                    {
                        return(GeneJobID);
                    }
                    else
                    {
                        ShowError(result);
                        return(null);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// get auth token from email and passeord
        /// </summary>
        public static async Task <string> GetAuthToken(string Email, string Password)
        {
            var parameters = new AuthDictionary();

            parameters.Add("username", WebUtility.UrlEncode(Email));
            parameters.Add("password", WebUtility.UrlEncode(Password));
            parameters.Add("getauth", "1");
            parameters.Add("logout", "1");

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/userinfo"));
                HtpReqMessage.Content = new FormUrlEncodedContent(parameters);
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0))
                    {
                        return(JObject.Parse(result).SelectToken("auth").ToString());
                    }
                    else
                    {
                        ShowError(result);
                        return(null);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public async Task <Dictionary <long, string> > ThumbnailUrl(string WIDTH_x_HEIGHT, ExtEnum Ext, bool Crop)
        {
            var parameters = new AuthDictionary()
            {
                { "fileids", string.Join(",", FileIDs) }, { "size", WIDTH_x_HEIGHT }, { "type", Ext.ToString() }
            };

            if (Crop)
            {
                parameters.Add("crop", "1");
            }

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/getthumbslinks"));
                HtpReqMessage.Content = new FormUrlEncodedContent(parameters);
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0))
                    {
                        Dictionary <long, string> addationStatus = new Dictionary <long, string>();
                        JObject.Parse(result).SelectToken("thumbs").ToList().ForEach(x => addationStatus.Add(x.Value <long>("fileid"), x.Value <int>("result").Equals(0) ? string.Format("https://{0}{1}", x.SelectToken("hosts").ToList().First(), x.Value <string>("path")) : x.Value <string>("error")));
                        return(addationStatus);
                    }
                    else
                    {
                        ShowError(result);
                        return(null);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public async Task <JSON_FileMetadata> CopyZip(Uri publiclink, long DestinationFolderID, string RenameTo = null)
        {
            var parameters = new AuthDictionary {
                { "code", publiclink.GetParameterInUrl("code") }, { "tofolderid", DestinationFolderID.ToString() }
            };

            if (!string.IsNullOrEmpty(RenameTo))
            {
                parameters.Add("toname", RenameTo.ToLower().EndsWith(".zip") ? RenameTo : $"{RenameTo}.zip");
            }

            using (HtpClient localHttpClient = new HtpClient(new HCHandler()))
            {
                HttpRequestMessage HtpReqMessage = new HttpRequestMessage(HttpMethod.Post, new pUri("/savepubzip"));
                HtpReqMessage.Content = new FormUrlEncodedContent(parameters.RemoveEmptyValues());
                using (HttpResponseMessage response = await localHttpClient.SendAsync(HtpReqMessage, HttpCompletionOption.ResponseContentRead).ConfigureAwait(false))
                {
                    string result = await response.Content.ReadAsStringAsync();

                    if (response.StatusCode == HttpStatusCode.OK && JObject.Parse(result).Value <int>("result").Equals(0))
                    {
                        return(JsonConvert.DeserializeObject <JSON_FileMetadata>(JObject.Parse(result).SelectToken("metadata").ToString(), JSONhandler));
                    }
                    else
                    {
                        ShowError(result);
                        return(null);
                    }
                }
            }
        }