From 8ebf9aed1ca7c1226a3fd0be7ab7ae8e2bb0ecbc Mon Sep 17 00:00:00 2001 From: Jaex Date: Sat, 21 Jan 2017 10:52:33 +0300 Subject: [PATCH] Added DeleteFile method to Puush class --- ShareX.UploadersLib/FileUploaders/Puush.cs | 46 +++++++++++++++++++--- 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/ShareX.UploadersLib/FileUploaders/Puush.cs b/ShareX.UploadersLib/FileUploaders/Puush.cs index 9a7cf32ce..a8e50ddff 100644 --- a/ShareX.UploadersLib/FileUploaders/Puush.cs +++ b/ShareX.UploadersLib/FileUploaders/Puush.cs @@ -28,6 +28,7 @@ using System.Drawing; using System.IO; using System.Windows.Forms; +using ShareX.HelpersLib; namespace ShareX.UploadersLib.FileUploaders { @@ -57,8 +58,11 @@ public class Puush : FileUploader public const string PuushResetPasswordURL = PuushURL + "/reset_password"; private const string PuushAPIURL = PuushURL + "/api"; - private const string PuushAPILoginURL = PuushAPIURL + "/auth"; + private const string PuushAPIAuthenticationURL = PuushAPIURL + "/auth"; private const string PuushAPIUploadURL = PuushAPIURL + "/up"; + private const string PuushAPIDeletionURL = PuushAPIURL + "/del"; + private const string PuushAPIHistoryURL = PuushAPIURL + "/hist"; + private const string PuushAPIThumbnailURL = PuushAPIURL + "/thumb"; public string APIKey { get; set; } @@ -76,9 +80,11 @@ public string Login(string email, string password) Dictionary arguments = new Dictionary(); arguments.Add("e", email); arguments.Add("p", password); - arguments.Add("z", "ShareX"); + arguments.Add("z", UserAgent); - string response = SendRequestMultiPart(PuushAPILoginURL, arguments); + // Successful: status,apikey,expire,usage + // Failed: status + string response = SendRequestMultiPart(PuushAPIAuthenticationURL, arguments); if (!string.IsNullOrEmpty(response)) { @@ -98,19 +104,47 @@ public string Login(string email, string password) return null; } + public bool DeleteFile(string id) + { + Dictionary arguments = new Dictionary(); + arguments.Add("k", APIKey); + arguments.Add("i", id); + arguments.Add("z", UserAgent); + + // Successful: status\nlist of history items + // Failed: status + string response = SendRequestMultiPart(PuushAPIDeletionURL, arguments); + + if (!string.IsNullOrEmpty(response)) + { + string[] lines = response.Lines(); + + if (lines != null && lines.Length > 0) + { + int status; + + return int.TryParse(lines[0], out status) && status >= 0; + } + } + + return false; + } + public override UploadResult Upload(Stream stream, string fileName) { Dictionary arguments = new Dictionary(); arguments.Add("k", APIKey); - arguments.Add("z", "ShareX"); + arguments.Add("z", UserAgent); + // Successful: status,url,id,usage + // Failed: status UploadResult result = SendRequestFile(PuushAPIUploadURL, stream, fileName, "f", arguments); if (result.IsSuccess) { string[] values = result.Response.Split(','); - if (values != null && values.Length > 1) + if (values != null && values.Length > 0) { int status; @@ -138,7 +172,7 @@ public override UploadResult Upload(Stream stream, string fileName) break; } } - else + else if (values.Length > 1) { result.URL = values[1]; }