2016-06-12 06:54:14 +12:00
|
|
|
|
#region License Information (GPL v3)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
ShareX - A program that allows you to take screenshots and share any file type
|
|
|
|
|
Copyright (c) 2007-2016 ShareX Team
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
|
|
|
|
|
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#endregion License Information (GPL v3)
|
|
|
|
|
|
2016-06-28 05:20:55 +12:00
|
|
|
|
using ShareX.UploadersLib.Properties;
|
2016-06-12 06:54:14 +12:00
|
|
|
|
using System.Collections.Generic;
|
2016-06-28 05:20:55 +12:00
|
|
|
|
using System.Drawing;
|
2016-06-12 06:54:14 +12:00
|
|
|
|
using System.IO;
|
2016-06-12 08:34:45 +12:00
|
|
|
|
using System.Windows.Forms;
|
2016-06-12 06:54:14 +12:00
|
|
|
|
|
|
|
|
|
namespace ShareX.UploadersLib.FileUploaders
|
|
|
|
|
{
|
|
|
|
|
public class PuushFileUploaderService : FileUploaderService
|
|
|
|
|
{
|
|
|
|
|
public override FileDestination EnumValue { get; } = FileDestination.Puush;
|
|
|
|
|
|
2016-06-28 05:20:55 +12:00
|
|
|
|
public override Icon ServiceIcon => Resources.puush;
|
|
|
|
|
|
2016-06-12 06:54:14 +12:00
|
|
|
|
public override bool CheckConfig(UploadersConfig config)
|
|
|
|
|
{
|
|
|
|
|
return !string.IsNullOrEmpty(config.PuushAPIKey);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override GenericUploader CreateUploader(UploadersConfig config, TaskReferenceHelper taskInfo)
|
|
|
|
|
{
|
2016-06-29 04:36:24 +12:00
|
|
|
|
return new Puush(config.PuushAPIKey);
|
2016-06-12 06:54:14 +12:00
|
|
|
|
}
|
2016-06-12 08:34:45 +12:00
|
|
|
|
|
|
|
|
|
public override TabPage GetUploadersConfigTabPage(UploadersConfigForm form) => form.tpPuush;
|
2016-06-12 06:54:14 +12:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class Puush : FileUploader
|
|
|
|
|
{
|
|
|
|
|
public const string PuushURL = "https://puush.me";
|
|
|
|
|
public const string PuushRegisterURL = PuushURL + "/register";
|
|
|
|
|
public const string PuushResetPasswordURL = PuushURL + "/reset_password";
|
|
|
|
|
|
2016-06-29 04:36:24 +12:00
|
|
|
|
private const string PuushAPIURL = PuushURL + "/api";
|
|
|
|
|
private const string PuushAPILoginURL = PuushAPIURL + "/auth";
|
|
|
|
|
private const string PuushAPIUploadURL = PuushAPIURL + "/up";
|
|
|
|
|
|
2016-06-12 06:54:14 +12:00
|
|
|
|
public string APIKey { get; set; }
|
|
|
|
|
|
2016-06-29 04:36:24 +12:00
|
|
|
|
public Puush()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Puush(string apiKey)
|
|
|
|
|
{
|
|
|
|
|
APIKey = apiKey;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-12 06:54:14 +12:00
|
|
|
|
public string Login(string email, string password)
|
|
|
|
|
{
|
|
|
|
|
Dictionary<string, string> arguments = new Dictionary<string, string>();
|
|
|
|
|
arguments.Add("e", email);
|
|
|
|
|
arguments.Add("p", password);
|
|
|
|
|
arguments.Add("z", "ShareX");
|
|
|
|
|
|
|
|
|
|
string response = SendRequest(HttpMethod.POST, PuushAPILoginURL, arguments);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(response))
|
|
|
|
|
{
|
|
|
|
|
string[] values = response.Split(',');
|
|
|
|
|
|
|
|
|
|
if (values != null && values.Length > 1)
|
|
|
|
|
{
|
|
|
|
|
int status;
|
|
|
|
|
|
|
|
|
|
if (int.TryParse(values[0], out status) && status >= 0)
|
|
|
|
|
{
|
|
|
|
|
return values[1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override UploadResult Upload(Stream stream, string fileName)
|
|
|
|
|
{
|
|
|
|
|
Dictionary<string, string> arguments = new Dictionary<string, string>();
|
|
|
|
|
arguments.Add("k", APIKey);
|
|
|
|
|
arguments.Add("z", "ShareX");
|
|
|
|
|
|
|
|
|
|
UploadResult result = UploadData(stream, PuushAPIUploadURL, fileName, "f", arguments);
|
|
|
|
|
|
|
|
|
|
if (result.IsSuccess)
|
|
|
|
|
{
|
|
|
|
|
string[] values = result.Response.Split(',');
|
|
|
|
|
|
|
|
|
|
if (values != null && values.Length > 1)
|
|
|
|
|
{
|
|
|
|
|
int status;
|
|
|
|
|
|
|
|
|
|
if (!int.TryParse(values[0], out status))
|
|
|
|
|
{
|
|
|
|
|
status = -2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
|
{
|
|
|
|
|
switch (status)
|
|
|
|
|
{
|
|
|
|
|
case -1:
|
|
|
|
|
Errors.Add("Authentication failure.");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
case -2:
|
|
|
|
|
Errors.Add("Connection error.");
|
|
|
|
|
break;
|
|
|
|
|
case -3:
|
|
|
|
|
Errors.Add("Checksum error.");
|
|
|
|
|
break;
|
|
|
|
|
case -4:
|
|
|
|
|
Errors.Add("Insufficient account storage remaining.");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
result.URL = values[1];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|